chris1384 Posted February 5, 2018 Share Posted February 5, 2018 (edited) 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 February 5, 2018 by chris1384 Link to comment
NeXuS™ Posted February 5, 2018 Share Posted February 5, 2018 (edited) Try to output the #table_allZombiesAlive var. What does it give you back? Edited February 5, 2018 by NeXuS™ Link to comment
chris1384 Posted February 5, 2018 Author Share Posted February 5, 2018 Did it with a tester Before round start (or resource start): 0 humans alive , 0 zombies alive After round start (choosing random zombie): 2 humans alive, 0 zombies alive After zombie killed (onPlayerWasted): 1 human alive, 1 zombie alive Link to comment
NeXuS™ Posted February 5, 2018 Share Posted February 5, 2018 Are you sure that this code works? It looks like you are missing an "if". Link to comment
Skully Posted February 6, 2018 Share Posted February 6, 2018 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
chris1384 Posted February 6, 2018 Author Share Posted February 6, 2018 (edited) 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 February 6, 2018 by chris1384 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now