Game Development Community

Energy Recharge button

by DeVry Instructors (#0020) · in General Discussion · 11/06/2008 (5:00 pm) · 2 replies

Hello, my name is Evan and I am trying to create a button that will manually recharge my energy bar. Does anyone have any ideas or code that might work? thanks in advance.

#1
11/07/2008 (4:21 am)
One option is to have the button request the server start/stop the recharge via a command to server. For example, "commandToServer('startRecharge');" when the button is clicked. Then in serverCmdStartRecharge function you can set the recharge rate:-

%client.player.setRechargeRate( %number );

To stop the recharge, you'd make a similar command to server call 'StopRecharge' and simply call setRechargeRate(0.0); from within it.

It's worth noting that the recharge rate is specified in units/tick, that is, for each tick (there's 32 per second) the engine will increase the players energy by %number of units. How long it will take to go from empty to full thus depends upon the %number and the player's maxEnergy entry in it's current datablock.

So for example, with maxEnergy of 32 and a setRechargeRate(2); it would take 16 ticks to go from empty to full, or 1/2 a second.
#2
11/07/2008 (1:31 pm)
Thanks alot man, worked like a charm!