Jump to content

setElementData problems?


Xeno

Recommended Posts

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
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 by Guest
Link to comment
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
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
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

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
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
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
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 by Guest
Link to comment
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

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 by Guest
Link to comment
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

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...