recharging code...many uses...

Posted By: mpdeveloper_B

recharging code...many uses... - 05/08/06 01:28

okay, first of all the code below is meant for recharging energy and slowly boosting the player, and it recharges depending on how much is lost, this can be used for recharging shields, health, energy weapons, other ammo, and more...no credit necessary, although it would be nice...

Code:

var energy = 100;
var use_energy;

function energy_recharge()
{
while (1)
{
if (energy > 100) { energy = 100; }
if (energy < 0) { energy = 0; }
if (use_energy == 0)
{
if (energy < 20) { energy += 0.5 *time; } //if energy has been majorly depleted recharge slowly
if (energy >= 20 && energy < 30) { energy += 1 *time; } //start to speed up charge
if (energy >= 30 && energy < 50) { energy += 2 *time; }
if (energy >= 50 && energy < 74) { energy += 4 *time; }
if (energy >= 74 && energy < 100) { energy += 7 *time; }
}
wait (1);
}
}



now put this in the code where you want it to recharge

Code:

if (jump_key == on) //boost and drain energy
{
if (energy > 0)
{
use_energy = 1;
c_move (my, vector (0,0, my.boost_speed *time), nullvector, glide);
energy -= 5 *time;
}
}

else
{
use_energy = 0;
}



things in red need to be edited to your prefs.
believe me, this is the best way to do the recharge, as putting min/max will allow energy to go above or below what it should be...enjoy
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 06/04/06 04:23

i take it no one needed this....oh well
Posted By: testDummy

Re: recharging code...many uses... - 06/04/06 05:38

Choose your own adventure:
*At least you took a gamble and put it out there.
*In my opinion, this demonstrates, in this instance, you've got the right spirit.
*At the very least, I respect that you took the time and initiative to contribute.
Posted By: Josh_Arldt

Re: recharging code...many uses... - 06/06/06 06:09

Thanks for the contribution man.
I find it helpfull.
Thanks.
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 06/08/06 15:41

thank you guys now i'm happy, lol, now i'm off to play jedi academy...
Posted By: BigDaz

Re: recharging code...many uses... - 06/08/06 21:18

Thanks, I might make use of that
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 06/20/06 00:28

thanks again
Posted By: Marcio Esper

Re: recharging code...many uses... - 06/23/06 06:12

very cool and clean code.

I believe it will be very usefful for many users that are going out from templates.

Congratulations

BR

Marcio
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 06/25/06 01:54

well i myself am kindof a noob to wdl, well...i started with 3dgamestudio back in i'd say.....december, no wait....september, but i did not start scripting till december, i'm still kinda newb but i make use of the code i know ^^. i have been told by a few that alot of the code i make is clean, this code was just an idea i had since i am making a mecha fighting game
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 06/25/06 02:04

has anyone tested? tell me how u like it? or should i set up a demo?
Posted By: FoxZero

Re: recharging code...many uses... - 06/29/06 03:13

I could use this for my movement code. I'll try to incorperate it when I get the chance.

Thanks man! I really did need something like this. I'm a newb to C-Script and I can't figure out how to get Tomb Raider III style sprinting to work.
Posted By: spartan131

Re: recharging code...many uses... - 06/30/06 21:23

can you make a demo for it so i can see how it works on the script editor and also in the game?
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 07/04/06 03:32

i will tomorrow, k
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 07/18/06 16:52

okay the file is now on FilePlanet, here you go:

Energy Recharge Test
Posted By: Joey

Re: recharging code...many uses... - 05/13/07 21:34

old thread? doesn't matter... i saw this in the call for goodies section, so it might be still interesting. why don't you make some kind of function instead of the numberous if-clauses?

energy = min(100, max(0, energy*(1+0.1*(use_energy==0)) ));

should do the job faster.
Posted By: xXxGuitar511

Re: recharging code...many uses... - 05/14/07 01:39

energy = clamp(energy*(1+0.1*(use_energy==0)) , 0, 100);
Posted By: Joey

Re: recharging code...many uses... - 05/14/07 19:31

i love clamp now
Posted By: mpdeveloper_B

Re: recharging code...many uses... - 05/15/07 13:20

this was also one of the first codes i had written, now it could be improved
© 2024 lite-C Forums