Changing playerdata values on the run
by Josiah Wang · in Torque Game Engine · 02/09/2005 (4:06 pm) · 8 replies
In my game, I have an item that when used (like a healthkit) will increase the speed of the player for 5 seconds. Here's my code so far:
however, i tried running that, and my upgrades (run force and jump force) did not apply. My question here is how I can get these 'upgrades' to apply to my player, and how i can reset them back to what is defined in the PlayerBody datablock
thanks!
function powerup_speed::onUse(%this,%user)
{
%user.decInventory(%this,1);
//%user.applyRepair(%this.repairAmount);
%user.setTranquilized(0.02);
%user.runForce = 180 * 90;
%user.jumpForce = 60.0 * 90;
if (%user.client)
messageClient(%user.client, 'MsgHealthKitUsed', '\c2Speed Power-Up Applied');
schedule(5000,%user,setPowerupSpeedDone,%user);
}
function setPowerupSpeedDone(%user)
{
%user.setTranquilized(0.0);
messageClient(%user.client, '', '\c2Finished Undizzy');
}however, i tried running that, and my upgrades (run force and jump force) did not apply. My question here is how I can get these 'upgrades' to apply to my player, and how i can reset them back to what is defined in the PlayerBody datablock
thanks!
#4
02/12/2005 (7:33 pm)
Hello all, new to the boards and just starting to get my head on straight with scripting. I was wondering if this inability to change fields is the same with objects not instantiated from datablocks. If I were to manually create a player object not associated with any datablock, would I then be able to alter the fields?
#6
In your example code you were also editing the player, which doesn't (unless you added it into the engine) have any functions except for 3: client, datablock, and some other one I forgot :) You can change player level values on the fly (switch the used datablock) which could be used to create a limited speed up system (switch to speeded up DB at start, switch to slowed down later)
I used a fuzzy version of this to do a player stat system, where the player was set to a datablock with their name on it, the datablock was updated based on the player's stats, etc. Err... confuzing arent I?
Not sure if I cleared anything up, but... yeah... :)
Ishbuu
02/12/2005 (7:56 pm)
<-- Is an obsessive TGE scripterIn your example code you were also editing the player, which doesn't (unless you added it into the engine) have any functions except for 3: client, datablock, and some other one I forgot :) You can change player level values on the fly (switch the used datablock) which could be used to create a limited speed up system (switch to speeded up DB at start, switch to slowed down later)
I used a fuzzy version of this to do a player stat system, where the player was set to a datablock with their name on it, the datablock was updated based on the player's stats, etc. Err... confuzing arent I?
Not sure if I cleared anything up, but... yeah... :)
Ishbuu
#7
I thought about that too, but that would mean I can't change more than one value at a time (at least, economically). If I were to change both player speed and something like energy (*shrug, just an example*), I would need a lot DBs: one for normal speed and normal energy, one for normal speed and more energy, one for normal speed and less energy, one for more speed and less energy, etc etc...
Something I *thought* might be possible is making it add something in the playerbody DB itself. Something like this in player.cs (take from PlayerBody:
would that work?
[edit]
DOH. Just read stephane's post. nvm.
[/edit]
03/21/2005 (11:34 am)
Wow, after a month, I finally understand your post (jk) actually i didn't notice your reply, IshbuuI thought about that too, but that would mean I can't change more than one value at a time (at least, economically). If I were to change both player speed and something like energy (*shrug, just an example*), I would need a lot DBs: one for normal speed and normal energy, one for normal speed and more energy, one for normal speed and less energy, one for more speed and less energy, etc etc...
Something I *thought* might be possible is making it add something in the playerbody DB itself. Something like this in player.cs (take from PlayerBody:
mass = 1000 + %massVariable; drag = 0.3; maxdrag = 0.4; density = 10; maxDamage = 100 + %maxDamageVariable; maxEnergy = 60 + %maxEnergyVariable; repairRate = 0.33 + %repairRateVariable; energyPerDamagePoint = 75.0;etc etc....
would that work?
[edit]
DOH. Just read stephane's post. nvm.
[/edit]
#8
If it is the script above, then that will work in all versions.
12/09/2006 (2:16 am)
There are several links up there, which one are you looking for an update for?If it is the script above, then that will work in all versions.
Torque 3D Owner Robert Blanchet Jr.