Help with script, please!


function GM:StaminaTick(client)
	local velocity = client:GetVelocity():Length2D();
	local health = client:Health();

	if ( (client.nextStamina or 0) < CurTime() ) then
		local stamina = client.DarkRPVars.stamina or 100;

		local value;
		local bonus = 0;
		local bonusTime = 0;

		if (client:Team() == TEAM_POLICE) then
			bonus = 1;
			bonusTime = 0.1;
		end;

		if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 10, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end
	
		
		if ( client:KeyDown(IN_SPEED) and velocity >= (client:GetRunSpeed() - 5) ) then
			value = math.Clamp(stamina - 1, 0, 100);
			client:SetDarkRPVar("stamina", value);

			client.nextStamina = CurTime() + (0.1 + bonusTime);
		else
			if ( client:KeyDown(IN_DUCK) ) then
				value = math.Clamp(stamina + 2 + bonus, 0, 100);
			else
				value = math.Clamp(stamina + 1 + bonus, 0, 100);
			end;

			client:SetDarkRPVar("stamina", value);

			if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 50, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end
	
		Msg(client:GetJumpPower())
			
			if (velocity < 5) then
				client.nextStamina = CurTime() + (0.5 + bonusTime) + ( (100 - health) / 100 );
			else
				client.nextStamina = CurTime() + (1.5 + bonusTime) + ( (100 - health) / 100 );
			end;
		end;

		local walkSpeed = client:GetWalkSpeed();

		if (stamina < 1) then
			client:SetRunSpeed(walkSpeed);
		else
			local walkSpeed = cvars.Number("ps_walkspeed", 125);
			local runSpeed = cvars.Number("ps_runspeed", 250);

			client:SetWalkSpeed( math.Clamp(walkSpeed, 50, walkSpeed) );
			client:SetRunSpeed( math.Clamp(runSpeed, 75, runSpeed) );
		end;
	end;
end;

This part don’t work every time, when i’m press space. But sometimes it works. Why it works only sometimes?


if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 10, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end

Why dumb?

You aren’t saying what is happening, or what you need help with. That’s why ‘dumb’

I need that - when I will press the jump button, 10 points of stamina will take away. But my script doesn’t work every time, when I press the space bar.

That’s the part, that I added:


if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 10, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end

That’s pistachio rp script, with my part in it:


function GM:StaminaTick(client)
	local velocity = client:GetVelocity():Length2D();
	local health = client:Health();

	if ( (client.nextStamina or 0) < CurTime() ) then
		local stamina = client.DarkRPVars.stamina or 100;

		local value;
		local bonus = 0;
		local bonusTime = 0;

		if (client:Team() == TEAM_POLICE) then
			bonus = 1;
			bonusTime = 0.1;
		end;

		if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 10, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end
	
		
		if ( client:KeyDown(IN_SPEED) and velocity >= (client:GetRunSpeed() - 5) ) then
			value = math.Clamp(stamina - 1, 0, 100);
			client:SetDarkRPVar("stamina", value);

			client.nextStamina = CurTime() + (0.1 + bonusTime);
		else
			if ( client:KeyDown(IN_DUCK) ) then
				value = math.Clamp(stamina + 2 + bonus, 0, 100);
			else
				value = math.Clamp(stamina + 1 + bonus, 0, 100);
			end;

			client:SetDarkRPVar("stamina", value);

			if ( client:KeyPressed(IN_JUMP)) then
			value = math.Clamp(stamina - 50, 0, 100);
			client:SetDarkRPVar("stamina", value);
			end
	
		Msg(client:GetJumpPower())
			
			if (velocity < 5) then
				client.nextStamina = CurTime() + (0.5 + bonusTime) + ( (100 - health) / 100 );
			else
				client.nextStamina = CurTime() + (1.5 + bonusTime) + ( (100 - health) / 100 );
			end;
		end;

		local walkSpeed = client:GetWalkSpeed();

		if (stamina < 1) then
			client:SetRunSpeed(walkSpeed);
		else
			local walkSpeed = cvars.Number("ps_walkspeed", 125);
			local runSpeed = cvars.Number("ps_runspeed", 250);

			client:SetWalkSpeed( math.Clamp(walkSpeed, 50, walkSpeed) );
			client:SetRunSpeed( math.Clamp(runSpeed, 75, runSpeed) );
		end;
	end;
end;

Sorry for my english.

Doesn’t Pistachio already have a Stamina system built-in? WITH your requirements?

Yes, but without jumps. Jumping no effect on stamina.