Xeno Posted November 29, 2011 Share Posted November 29, 2011 I have a problem with setElementData, im makign it so if you have a certain ammount of kills, it will put you in a team, this is the code... function setTeamZombie() if getElementData(source,"Zombie kills") <= 100 then sw = getTeamFromName("Subway Clan") setPlayerTeam(source, sw) elseif getElementData(source,"Zombie kills") >= 101 then sw1 = getTeamFromName("Clan 7") setPlayerTeam(source, sw1) end end addEventHandler("onZombieWasted", root, setTeamZombie) I get the error: Attempt to compare boolen with number. Oh and heres my Collumn. exports.scoreboard:addScoreboardColumn('Zombie kills') I have no idea how to fix this so please help Xeno Link to comment
Castillo Posted November 29, 2011 Share Posted November 29, 2011 (edited) function setTeamZombie(killer) local kills = tonumber(getElementData(killer,"Zombie kills")) if kills <= 100 then sw = getTeamFromName("Subway Clan") setPlayerTeam(killer, sw) elseif kills >= 101 then sw1 = getTeamFromName("Clan 7") setPlayerTeam(killer, sw1) end end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) Edited November 29, 2011 by Guest Link to comment
Xeno Posted November 29, 2011 Author Share Posted November 29, 2011 function setTeamZombie(killer) local kills = tonumber(getElementData(killer,"Zombie kills")) if kills <= 100 then sw = getTeamFromName("Subway Clan") setPlayerTeam(source, sw) elseif kills >= 101 then sw1 = getTeamFromName("Clan 7") setPlayerTeam(source, sw1) end end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) Thanks for the reply, I tried that, and I get the same error as last time: attempt to compare boolean with number Link to comment
Castillo Posted November 29, 2011 Share Posted November 29, 2011 function setTeamZombie(killer) if (killer and getElementType(killer) == "player") then local kills = tonumber(getElementData(killer,"Zombie kills")) if (not kills) then setElementData(killer, "Zombie kills", 0) end if kills <= 100 then local sw = getTeamFromName("Subway Clan") setPlayerTeam(killer, sw) elseif kills >= 101 then local sw1 = getTeamFromName("Clan 7") setPlayerTeam(killer, sw1) end end end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) It should work, in the other post I forgot something. Link to comment
Xeno Posted November 29, 2011 Author Share Posted November 29, 2011 function setTeamZombie(killer) if (killer and getElementType(killer) == "player") then local kills = tonumber(getElementData(killer,"Zombie kills")) if (not kills) then setElementData(killer, "Zombie kills", 0) end if kills <= 100 then local sw = getTeamFromName("Subway Clan") setPlayerTeam(killer, sw) elseif kills >= 101 then local sw1 = getTeamFromName("Clan 7") setPlayerTeam(killer, sw1) end end end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) It should work, in the other post I forgot something. Still getting the same error D: Link to comment
Castillo Posted November 29, 2011 Share Posted November 29, 2011 Is "Zombie kills" a number? Link to comment
50p Posted November 29, 2011 Share Posted November 29, 2011 if (not kills) then setElementData(killer, "Zombie kills", 0); kills = 0; end Link to comment
Xeno Posted November 29, 2011 Author Share Posted November 29, 2011 Is "Zombie kills" a number? Yes, yes it is. And ill give that ago 50p Link to comment
Xeno Posted November 29, 2011 Author Share Posted November 29, 2011 if (not kills) then setElementData(killer, "Zombie kills", 0); kills = 0; end I still get the same error Link to comment
50p Posted November 29, 2011 Share Posted November 29, 2011 if (not kills) then setElementData(killer, "Zombie kills", 0); kills = 0; end I still get the same error Which line is the error at? Link to comment
Xeno Posted November 29, 2011 Author Share Posted November 29, 2011 if (not kills) then setElementData(killer, "Zombie kills", 0); kills = 0; end I still get the same error Which line is the error at? if (not kills) then setElementData(killer, "Zombie kills", 0); kills = 0; end Link to comment
50p Posted November 30, 2011 Share Posted November 30, 2011 I don't know how is this possible to get "Attempt to compare boolen with number." at that line if you're not comparing anything there. Even if, that doesn't make sense since "not" can be used with any sort of variable. Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 I don't know what is your problem, it works perfectly fine here. Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 I don't know what is your problem, it works perfectly fine here. So you tested it ingame? Urgh... I dont even know, ima try again. Thanks for the help by the way Castillo and 50p Someone told me it was something to do with making the collumn, but he didn't fix it, what do you guys think? Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 I don't know what is your problem, it works perfectly fine here. It works now, thanks both of you. ONE last thing, how would I make it so it checks the kills on Player login and sets the team? I tried changing the event Handlers around, but that didn't work. And also, if I were to add another team, would it go like this? function setTeamZombie(killer) if (killer and getElementType(killer) == "player") then local kills = tonumber(getElementData(killer,"Zombie kills")) if (not kills) then setElementData(killer, "Zombie kills", 0) end if kills <= 24 then local beg = getTeamFromName("Beginners") setPlayerTeam(killer,beg) elseif kills >= 25 then local sw1 = getTeamFromName("Subway Clan") setPlayerTeam(killer, sw1) elseif kills >= 35 then local sw2 = getTeamFromName("Clan 3") setPlayerTeam(killer, sw2) end end end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 (edited) function checkKills(player) if (player and getElementType(player) == "player") then local kills = tonumber(getElementData(player,"Zombie kills")) if (not kills) then setElementData(player, "Zombie kills", 0) end if kills <= 24 then local beg = getTeamFromName("Beginners") setPlayerTeam(player,beg) elseif kills >= 25 then local sw1 = getTeamFromName("Subway Clan") setPlayerTeam(player, sw1) elseif kills >= 35 then local sw2 = getTeamFromName("Clan 3") setPlayerTeam(player, sw2) end end end function setTeamZombie(killer) checkKills(killer) end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) addEventHandler("onPlayerLogin",root, function () checkKills(source) end) Edited November 30, 2011 by Guest Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 function checkKills(player) if (player and getElementType(player) == "player") then local kills = tonumber(getElementData(player,"Zombie kills")) if (not kills) then setElementData(player, "Zombie kills", 0) end if kills <= 24 then local beg = getTeamFromName("Beginners") setPlayerTeam(player,beg) elseif kills >= 25 then local sw1 = getTeamFromName("Subway Clan") setPlayerTeam(player, sw1) elseif kills >= 35 then local sw2 = getTeamFromName("Clan 3") setPlayerTeam(player, sw2) end end function setTeamZombie(killer) checkKills(killer) end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) addEventHandler("onPlayerLogin",root, function () checkKills(source) end) Thanks, the login thing is all fine. But when I get past 35 kills, it doesnt switch me to the next team, I stay in Subway Clan Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 Do you have all these teams created? the name's must be the same. Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 Do you have all these teams created? the name's must be the same. Yeah all the teams are created in the script. I just made a new account and it sent me straight to the Subway Team. Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 (edited) Ok, I've found your problem, you are checking if the kills are 25 or HIGHER, and then again checking if 35 or HIGHER, but 25 is first, so it'll always set the team to "Subway clan". function checkKills(player) if (player and getElementType(player) == "player") then local kills = tonumber(getElementData(player,"Zombie kills")) if (not kills) then setElementData(player, "Zombie kills", 0) kills = 0 end if (kills <= 24) then setPlayerTeam(player, getTeamFromName("Beginners")) elseif (kills >= 25 and kills <= 35) then setPlayerTeam(player, getTeamFromName("Subway Clan")) elseif (kills >= 35) then setPlayerTeam(player, getTeamFromName("Clan 3")) end end end function setTeamZombie(killer) checkKills(killer) end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) addEventHandler("onPlayerLogin",root, function () checkKills(source) end) Edited November 30, 2011 by Guest Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 Ok, I've found your problem, you are checking if the kills are 25 or HIGHER, and then again checking if 35 or HIGHER, but 25 is first, so it'll always set the team to "Subway clan". function checkKills(player) if (player and getElementType(player) == "player") then local kills = tonumber(getElementData(player,"Zombie kills")) if (not kills) then setElementData(player, "Zombie kills", 0) kills = 0 end if (kills <= 24) then setPlayerTeam(player, getTeamFromName("Beginners")) elseif (kills == 25) then setPlayerTeam(player, getTeamFromName("Subway Clan")) elseif (kills == 35) then setPlayerTeam(player, getTeamFromName("Clan 3")) end end end function setTeamZombie(killer) checkKills(killer) end addEvent("onZombieWasted",true) addEventHandler("onZombieWasted", root, setTeamZombie) addEventHandler("onPlayerLogin",root, function () checkKills(source) end) Im SERIOUSLY puzzled, because that SHOULD work and I dont know why? It sets the team "Subway Clan" But after that, it doesnt set it to the new clan EDIT: Wait no, its because its just "25", i need it to be 25-39 is that possible to do? So for example, if i logged in, and my kills were 26 , it wouldn't set the team becuase my kills are 26 and not 25. So basically, everything works expect for the team check on login. Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 Copy my last code again, I added to check if it's higher than 25 but lower to 35. Link to comment
Xeno Posted November 30, 2011 Author Share Posted November 30, 2011 Copy my last code again, I added to check if it's higher than 25 but lower to 35. Thats BRILLIANT. Thank you so much for the help! 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