Page 1 of 1

Players Health

Posted: Sat May 09, 2009 10:14 am
by Micha!
Hi I tried to change players hp but I'm a lua noob. (For the hole map not only if you die or etc)
It would be nice if you can change the hp for each class.
So here is my try:

Code: Select all

Version = 	1.0
Author  =   "^wMicha^0!"
Description = "^7Health"
Homepage = "^7www^1.^7gs2175^1.^wfastdl^1.^7de "

--global vars
samplerate = 200
et.CS_PLAYERS = 689

--


function et_InitGame(levelTime,randomSeed,restart)
	mclients = tonumber( et.trap_Cvar_Get( "sv_maxClients" ) )
	et.G_Print("[Health] Version:1.0 Loaded\n")
   	et.RegisterModname("Health")
	et.trap_SendServerCommand(-1, "b 8 \""..Description.." ^0[^7LUA^0] ^7powered by "..Author.." ^7visit "..Homepage.." \n\"" )
		count = {}
			for i = 0, mclients - 1 do
			count[i] = 0	
	end	
end

--on a player death, check to see if the killer is flagged up for ownage
function et_Obituary( victim, killer, meansOfDeath )
		local vteam = tonumber(et.gentity_get(victim, "sess.sessionTeam")) 
		local vteam1 = tonumber(et.gentity_get(killer, "sess.sessionTeam"))
		local vt1 = string.gsub(et.gentity_get(victim, "pers.netname"), "%^$", "^^ ") 
		local vt2 = string.gsub(et.gentity_get(killer, "pers.netname"), "%^$", "^^ ") 
		if meansofdeath == 6 then
		 if vteam == 2  then
			if vteam1 == 1 then
      			et.gentity_set(victim, "health", 300)
			end
		end
end
	if meansofdeath == 1 then
			et.gentity_set(victim, "health", 200)
     	   end
end

function et_ClientBegin( clientNum ) 
		if et.gentity_get&#40;"health"&#41; <= 0 then
      	et.gentity_set&#40;"health", 200&#41;
		end
end
Can you help me with that pls?

Re: Players Health

Posted: Sat May 09, 2009 11:04 am
by McSteve

Code: Select all

--on a player death, check to see if the killer is flagged up for ownage
I recognise that comment! ;)

Anyway, if I read your post correctly, you say you want to set different hp for each class. I wrote a script once that inflicted punishments in health and ammo for people the more times they selfkilled. Thing is, this only set the hp at spawn time (tip: function et_ClientSpawn(cno, revived) , not et_clientbegin()) and did not affect its maximum value. I'm not sure if this will be of use but here is the link just in case it is.

I've never tried messing with the maximums, so can't help you there. Maybe one of the lua gurus knows if it is possible. If you only want to lower hp, that makes things a lot easier. By the looks of it, you want to increase hp on some occasion, which will take some experimenting.

Posted: Sat May 09, 2009 12:28 pm
by Micha!
Thx Steve, I try to change the players hp for the map, not only if they die or something. :P
Like 300 hp or somethign would be funny.
I know that this is possible with .dll or .so, but you need to change the mdo then and I don't want to do it^^


Btw the middle was taken of a other lua to test if this works.

*EDIT*
Perlung aka crazy helped me and that came out:

Code: Select all

--Do not change--
Modname = "HealthBoost"
Version = "1.0"
Author  = "Perlo_0ung?!"
Description = "^7HealthBoost"
Homepage = "www.gs2175.fastdl.de"
Text = "^1| ^7Maximal&#58; ^3300 ^1| ^7Increase&#58; ^320"
--
 
--global vars
samplerate = 5000
et.CS_PLAYERS = 689
--

function et_InitGame&#40;levelTime,randomSeed,restart&#41;
	maxclients = tonumber&#40; et.trap_Cvar_Get&#40; "sv_maxClients" &#41; &#41;	--gets the maxclients
	et.G_Print&#40;"&#91;HealthBoost&#93; Version&#58;1.0 Loaded\n"&#41;
   	et.RegisterModname&#40;Modname .. " " .. Version&#41;
	et.trap_SendServerCommand&#40;-1, "b 8 \""..Description.." ^0&#91;^7LUA^0&#93; "..Text.." \n\"" &#41;
		count = &#123;&#125;
			for i = 0, mclients - 1 do
			count&#91;i&#93; = 0	
	end	

end	

function et_RunFrame&#40; levelTime &#41;
	if math.mod&#40;levelTime, samplerate&#41; ~= 0 then return end
	for j = 0, &#40;maxclients - 1&#41; do
	hp = tonumber&#40;et.gentity_get&#40;j,"health"&#41;&#41;

   ---------------20&#58; HP increase----------------

	shp = &#40;tonumber&#40;et.gentity_get&#40;j,"health"&#41;&#41; + 20 &#41;

   ----------300&#58; Maximal Healthpoints-----------

	if hp > 300 then return end
	if hp < 300 then 

   ----------------------------------------------

		et.gentity_set&#40;j, "health", shp&#41;
   end
end
end

Posted: Sun May 10, 2009 1:12 am
by crazyfrag
increasing the hp pemanently is atm not possible cause hp gets lowered itself if its higher than the maxhp of the class

Posted: Sun May 10, 2009 2:06 am
by crazyfrag
here's my hp increase beta version:

Code: Select all

--Do not change--
Modname = "HealthBoost"
Version = "1.1"
Author  = "Perlo_0ung?!"
Description = "^7HealthBoost"
Homepage = "www.gs2175.fastdl.de"
Text = "^1| ^7Maximal&#58; ^3300 ^1| ^7Increase&#58; ^320"
-- 
 
--global vars
et.CS_PLAYERS = 689
samplerate = 1000
medic_max_hp = 200
class_max_hp = 150

-- 


function et_InitGame&#40;levelTime,randomSeed,restart&#41;
   maxclients = tonumber&#40; et.trap_Cvar_Get&#40; "sv_maxClients" &#41; &#41;   --gets the maxclients
   et.G_Print&#40;"&#91;HealthBoost&#93; Version&#58;1.0 Loaded\n"&#41;
      et.RegisterModname&#40;Modname .. " " .. Version&#41;
   et.trap_SendServerCommand&#40;-1, "b 8 \""..Description.." ^0&#91;^7LUA^0&#93; "..Text.." \n\"" &#41;
      count = &#123;&#125;
         for cno = 0, maxclients - 1 do
         count&#91;cno&#93; = 1   
   end   

end  
 
function et_ClientSpawn&#40;cno,revived&#41;
	if revived == 0 then
	count&#91;cno&#93; = 1
	end
end
function et_ClientDisconnect&#40;cno&#41; 
	count&#91;cno&#93; = 0
end

function et_RunFrame&#40; levelTime &#41;
   for cno = 0, &#40;maxclients - 1&#41; do
	if count&#91;cno&#93; == 1 then
  local class = et.gentity_get&#40;cno,"sess.playertype"&#41;
	  if class == 1 then 
		local mhp = &#40; medic_max_hp - &#40;et.gentity_get&#40;cno,"health"&#41;&#41;&#41;
		local newmhp = &#40;et.gentity_get&#40;cno,"health"&#41; + mhp&#41;
      		et.gentity_set&#40;cno, "health", newmhp&#41;
		count&#91;cno&#93; = 0
	  elseif class == 0 or class == 2 or class == 3 or class == 4 then 
		local chp = &#40; class_max_hp  - &#40;et.gentity_get&#40;cno,"health"&#41;&#41;&#41;
		local newchp = &#40;et.gentity_get&#40;cno,"health"&#41; + chp&#41;
      		et.gentity_set&#40;cno, "health", newchp&#41;
		count&#91;cno&#93; = 0
 	  end	
	end
   end
 if math.mod&#40;levelTime, samplerate&#41; ~= 0 then return end
   for cno = 0, &#40;maxclients - 1&#41; do
  local class = et.gentity_get&#40;cno,"sess.playertype"&#41;
  local shp = &#40;tonumber&#40;et.gentity_get&#40;cno,"health"&#41;&#41; + 1&#41;
	if class == 1 then
  		 if shp > 189 then return end
   			if shp < 189 then 
			et.gentity_set&#40;cno, "health", shp&#41;
		end
	elseif class == 0 or class == 2 or class == 3 or class == 4 then
  		 if shp > 151 then return end
   			if shp < 151 then 
			et.gentity_set&#40;cno, "health", shp&#41;
		end
	end
	end
end

Posted: Sun May 10, 2009 4:40 am
by Micha!

Code: Select all

--Do not change--
Modname = "HealthBoost"
Version = "1.1"
Author  = "Perlo_0ung?!"
Description = "^7HealthBoost2"
Homepage = "www.gs2175.fastdl.de"
Text = "^1| ^7Medic&#58; ^3200 ^1| ^7Rest&#58; ^3150"
-- 
 
--global vars
et.CS_PLAYERS = 689
samplerate = 1000
medic_max_hp = 200
class_max_hp = 150

-- 


function et_InitGame&#40;levelTime,randomSeed,restart&#41;
   maxclients = tonumber&#40; et.trap_Cvar_Get&#40; "sv_maxClients" &#41; &#41;   --gets the maxclients
   et.G_Print&#40;"&#91;HealthBoost&#93; Version&#58;1.1 Loaded\n"&#41;
      et.RegisterModname&#40;Modname .. " " .. Version&#41;
   et.trap_SendServerCommand&#40;-1, "b 8 \""..Description.." ^0&#91;^7LUA^0&#93; "..Text.." \n\"" &#41;
      count = &#123;&#125;
         for cno = 0, maxclients - 1 do
         count&#91;cno&#93; = 1   
   end   

end 
 
function et_ClientSpawn&#40;cno,revived&#41;
   if revived == 0 then
   count&#91;cno&#93; = 1
   end
end
function et_ClientDisconnect&#40;cno&#41;
   count&#91;cno&#93; = 0
end

function et_RunFrame&#40; levelTime &#41;
   for cno = 0, &#40;maxclients - 1&#41; do
   if count&#91;cno&#93; == 1 then
  local class = et.gentity_get&#40;cno,"sess.playertype"&#41;
     if class == 1 then
      local mhp = &#40; medic_max_hp - &#40;et.gentity_get&#40;cno,"health"&#41;&#41;&#41;
      local newmhp = &#40;et.gentity_get&#40;cno,"health"&#41; + mhp&#41;
            et.gentity_set&#40;cno, "health", newmhp&#41;
      count&#91;cno&#93; = 0
     elseif class == 0 or class == 2 or class == 3 or class == 4 then
      local chp = &#40; class_max_hp  - &#40;et.gentity_get&#40;cno,"health"&#41;&#41;&#41;
      local newchp = &#40;et.gentity_get&#40;cno,"health"&#41; + chp&#41;
            et.gentity_set&#40;cno, "health", newchp&#41;
      count&#91;cno&#93; = 0
      end   
   end
   end
 if math.mod&#40;levelTime, samplerate&#41; ~= 0 then return end
   for cno = 0, &#40;maxclients - 1&#41; do
  local class = et.gentity_get&#40;cno,"sess.playertype"&#41;
  local shp = &#40;tonumber&#40;et.gentity_get&#40;cno,"health"&#41;&#41; + 1&#41;
   if class == 1 then
         if shp > 189 then return end
            if shp < 189 then
         et.gentity_set&#40;cno, "health", shp&#41;
      end
   elseif class == 0 or class == 2 or class == 3 or class == 4 then
         if shp > 151 then return end
            if shp < 151 then
         et.gentity_set&#40;cno, "health", shp&#41;
      end
   end
   end
end 

Posted: Wed Jun 10, 2009 7:45 am
by crazyfrag
increase max hp:

Code: Select all

function et_ClientSpawn&#40;cno,revived&#41;
	et.gentity_set&#40;cno, "ps.stats", 4,130&#41;	-- 130 =maxhp
end