Page 1 of 1

LUA help sought

Posted: Sun Apr 18, 2010 7:48 pm
by myers73

Code: Select all

    OnCharacterDeath(
		function(player)	
		if GetCharacterTeam(player) == 2 and IsCharacterHuman(player) then
		TeamChange(player, 1)
		end
		)
I'm not so great at LUA, but I think yall get what this is attempting.

person dies-> check to see if they are human -> if yes then check team -> if team 2 switch their team.

seems a simple enough task. As I said im not very good with LUA, so there may be things horribly wrong with my script. If anyone could will they please fix it for me. thanks

Re: LUA help seeked

Posted: Sun Apr 18, 2010 8:11 pm
by skelltor
So what exactly is your problem dose it cause a ctd or what?(if it dose crash please post an error log.

Re: LUA help seeked

Posted: Sun Apr 18, 2010 8:54 pm
by myers73
well fixed code somewhat, everything works except the function to change the team

Code: Select all

    playerDead = OnCharacterDeath(
		function(player)	
			if GetCharacterTeam(player) == 2 and IsCharacterHuman(player) then
			SetObjectTeam(player, 1)
			end
		end
	)

Re: LUA help seeked

Posted: Sun Apr 18, 2010 10:57 pm
by [RDH]Zerted
What in the end are you trying to do?

Just about all the team switching code deals with changing the unit's team. The person's player/character is still on the same team, just his/her unit is different. When the unit dies, it no longer exists, thus you can't chance its team after its death.

Re: LUA help seeked

Posted: Tue Apr 20, 2010 12:00 am
by myers73
I want to check when a player is killed if they are on team 1, if that is yes then change them to team 2.


would this work?

Code: Select all

			if GetCharacterTeam(player) ==  1 then
			SetProperty(player, "Team", 2)
EDIT:

what about /admin /swap playerid, that changes their team when you use that online.


EDIT2
ok, so scratch the above, dont think it is possible. now for another idea:

Code: Select all

onKillReplinishHealth = OnCharacterDeath(
	function(player, killer)
	if IsCharacterHuman(player) = true and IsCharacterHuman(killer) then
	SetProperty(killer, "AddHealth", 1000) --higher than maxhealth in order to fully replinish
	end
end
)
would this work to replinish the health of the killer if both the killer and player were human?

Re: LUA help seeked

Posted: Tue Apr 20, 2010 9:21 am
by [RDH]Zerted
You might have to do SetProperty on GetCharacterUnit(killer), but almost. Change your "=" to "==".

Re: LUA help seeked

Posted: Tue Apr 20, 2010 9:32 pm
by myers73
so...

Code: Select all

onKillReplinishHealth = OnCharacterDeath(
   function(player, killer)
   if IsCharacterHuman(player) == true and IsCharacterHuman(killer) then --corrected = to ==
   SetProperty(GetCharacterUnit(killer), "AddHealth", 1000) --higher than maxhealth -- changed killer to GetCharacterUnit(killer)
   end
end
)