Jump to content

[Help] onPlayerWasted issue


chris1384

Recommended Posts

Hi there. Recently I have this issue with this part of the code, I'm trying to trigger something with onPlayerWasted, but it looks like the updateTeamTables() is not updated as it should be. To be more explicit, if there's only one zombie in the team, it should trigger the outputChatBox function, but that doesn't happen. Can someone help? Thanks.

function updateTeamTables()
	table_allHumans = {}
	table_allHumansAlive = {}
	table_allZombies = {}
	table_allZombiesAlive = {}
	for k,v in ipairs(getElementsByType("player")) do
		if isPlayerInTeam(v, team_Humans) then
			table.insert(table_allHumans, v)
			if getElementData(v, "State") == "Alive" then
				table.insert(table_allHumansAlive, v)
			end
		elseif isPlayerInTeam(v, team_Zombies) then
			table.insert(table_allZombies, v)
			if getElementData(v, "State") == "Alive" then
				table.insert(table_allZombiesAlive, v)
			end
		end
	end
end

addEventHandler("onPlayerWasted", root, function(ammo, attacker, weapon, bodypart)
	updateTeamTables()
	for k,v in ipairs(getElementsByType("player")) do
		if getElementData(v, "zp_Class") == "Spectator" then
			setspectator(v)
		end
	end
	if getElementData(source, "zp_Class") == "Zombie" then
		if attacker ~= nil and isElement(attacker) then
			setspectator(source)
			local scr = getElementData(attacker, "Score")
			setElementData(attacker, "Score", tonumber(getElementData(attacker, "Score")+2))
		end
	end
	local dths = getElementData(source, "Deaths")
	setElementData(source, "Deaths", tonumber(dths + 1))
	setElementData(source, "State", "Dead")
	setElementData(source, "zp_Class", "None (Dead)")
	local allHumans = getPlayersInTeam(team_Humans)
	local allZombies = getPlayersInTeam(team_Zombies)
	elseif getElementData(source, "zp_Class") == "Zombie" and #table_allZombiesAlive == 1 then
		outputChatBox("true", root)
	end
end)

 

Edited by chris1384
Link to comment

Your elseif statement doesn't have a primary if statement to work from, try this.

function updateTeamTables()
	table_allHumans = {}
	table_allHumansAlive = {}
	table_allZombies = {}
	table_allZombiesAlive = {}
	for k,v in ipairs(getElementsByType("player")) do
		if isPlayerInTeam(v, team_Humans) then
			table.insert(table_allHumans, v)
			if getElementData(v, "State") == "Alive" then
				table.insert(table_allHumansAlive, v)
			end
		elseif isPlayerInTeam(v, team_Zombies) then
			table.insert(table_allZombies, v)
			if getElementData(v, "State") == "Alive" then
				table.insert(table_allZombiesAlive, v)
			end
		end
	end
end

addEventHandler("onPlayerWasted", root, function(ammo, attacker, weapon, bodypart)
	updateTeamTables()
	for k,v in ipairs(getElementsByType("player")) do
		if getElementData(v, "zp_Class") == "Spectator" then
			setspectator(v)
		end
	end
	if getElementData(source, "zp_Class") == "Zombie" then
		if attacker ~= nil and isElement(attacker) then
			setspectator(source)
			local scr = getElementData(attacker, "Score")
			setElementData(attacker, "Score", tonumber(getElementData(attacker, "Score")+2))
		end
	elseif getElementData(source, "zp_Class") == "Zombie" and #table_allZombiesAlive == 1 then
		outputChatBox("true", root)
	end
	local dths = getElementData(source, "Deaths")
	setElementData(source, "Deaths", tonumber(dths + 1))
	setElementData(source, "State", "Dead")
	setElementData(source, "zp_Class", "None (Dead)")
	local allHumans = getPlayersInTeam(team_Humans)
	local allZombies = getPlayersInTeam(team_Zombies)
end)

 

Link to comment

Sorry for the late response, but before making this topic I edited something in the LUA code and I didn't noticed it was wrong edited.

However, this is the part that really kills me and I still didn't figured out how to fix it:

if getElementData(source, "zp_Class") == "Zombie" and #table_allZombiesAlive == 1 then
	outputChatBox("true", root)
end

When the player is infected by a zombie, (using onPlayerDamage) I use again updateTeamTables() to update the tables, but as it mentioned before, it doesn't update correctly so after the zombie is killed nothing happens, but after the round start and the zombie choosed infects another player, triggers the outputChatBox function.s.

Edit: Maybe the updateTeamTables() isn't necessary, but I don't know an alternative to that. Someone?

Edited by chris1384
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...