Recharge Script

From GameStudio Wiki

Jump to: navigation, search

Code Submitted by ManSlayer101.

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;
		}


jump_key == on and my.boost_speed need to be edited to your preferences.

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

Original Forum Post: http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/652335/an/0/page/0/gonew/1#UNREAD

Personal tools