View Single Post
Old 09-26-2010   #2
Mex
Registered User
 
Join Date: Nov 2008
Posts: 44
Mex is on a distinguished roadMex is on a distinguished roadMex is on a distinguished road
This method just uses 1 timer, meaning the health check is done for all players at the same time every 10 seconds. (untested)

Code:
function GiveSailorsHP()
	-- fetch highest possible player ID
	local b = getMaxPlayers() - 1
	
	-- create local variables outside the loop to hold data for the players
	local SkinID, Health, NewHealth

	-- loop around all possible player IDs
	for a=0, b do
		
		-- check if player is connected and spawned
		if isPlayerConnected(a) == 1 and isPlayerSpawned(a) == 1 then
			
			-- fetch player skin
			SkinID = getPlayerSkin(a)
			
			-- check player is using sailor skin
			if SkinID == 134 or SkinID == 135 or SkinID == 136 then
				
				-- fetch player health
				Health = getPlayerHealth(a)
				
				-- check player's health is more than 20, and less than 100
				if Health > 20 and Health < 100 then
					-- work out new health
					NewHealth = Health * 1.1
					
					-- if new health is more than 100, change it to 100
					if NewHealth > 100 then NewHealth = 100 end
					
					-- set player's new health
					setPlayerHealth(a, NewHealth)
				end
			end
		end
	end
end

-- create a timer to call GiveSailorsHP() every 10 seconds, infinite amount of repeitions
createTimer("GiveSailorsHP", 10000, 0)
Mex is offline   Reply With Quote