Jump to content

[HELP] WHat am i doing wrong?


Imposter

Recommended Posts

I want to see if the player's account contains the value of civilian and if it does then it sets his team as civilian. thanks!

  
function onConnect () 
    local theTeam = getAccountData ( source, "hisTeam" ) 
    if source then 
        if theTeam=="" then 
            setPlayerTeam ( source, civilianTeam ) 
            if theTeam==("Civilians") then 
                setPlayerTeam ( source, civilianTeam ) 
            end 
        else 
            outputChatBox ( "ERROR!" ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" , getRootElement(),  onConnect ) 
  

Link to comment

You again didn't get the 'source' of this function. The first argument of the function getAccountData should be 'account' object and not a 'source'. In your case 'source' is a connected player.

function onConnect () 
    local account = getPlayerAccount ( source ) 
    local theTeam = getAccountData ( account, "hisTeam" ) 
    if source then 
        if theTeam=="" then 
            setPlayerTeam ( source, civilianTeam ) 
            if theTeam==("Civilians") then 
                setPlayerTeam ( source, civilianTeam ) 
            end 
        else 
            outputChatBox ( "ERROR!" ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" , getRootElement(),  onConnect ) 

Link to comment
You again didn't get the 'source' of this function. The first argument of the function getAccountData should be 'account' object and not a 'source'. In your case 'source' is a connected player.
function onConnect () 
    local account = getPlayerAccount ( source ) 
    local theTeam = getAccountData ( account, "hisTeam" ) 
    if source then 
        if theTeam=="" then 
            setPlayerTeam ( source, civilianTeam ) 
            if theTeam==("Civilians") then 
                setPlayerTeam ( source, civilianTeam ) 
            end 
        else 
            outputChatBox ( "ERROR!" ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" , getRootElement(),  onConnect ) 

on the debugscript, im getting an error, "WARNING:[roleplay]\CivilianTeam\server.lua:3: Bad arguement @ 'getAccountData' [Expected account at arguement 1, got boolean]" this error is coming still even from using your code :/

server side code:

  
function onConnect () 
    local playerAccount = getPlayerAccount(source) 
    local theTeam = getAccountData ( playerAccount, "hisTeam" ) 
    if source then 
        if theTeam=="" then 
            setPlayerTeam ( source, civilianTeam ) 
            if theTeam==("Civilians") then 
                setPlayerTeam ( source, civilianTeam ) 
            end 
        else 
            outputChatBox ( "ERROR!" ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" , getRootElement(),  onConnect ) 
  
function onLeave () 
    local playerAccount = getPlayerAccount(source) 
    local playerTeam = getPlayerTeam ( source ) 
    if playerTeam then 
        setAccountData ( playerAccount, "hisTeam" , playerTeam ) 
    end 
end 
addEventHandler ( "onPlayerQuit" , getRootElement(), onLeave ) 
  
function onResourceStart() 
    civilianTeam = createTeam ( "Civilians", 255, 255, 255 ) 
    outputChatBox ( "Civilian Team Created!" ) 
    onConnect() 
end 
addEventHandler ( "onResourceStart" , getRootElement(), onResourceStart ) 
  

Link to comment

robhol I'm sorry, you were right. "getPlayerAccount" returns false. That was exactly what you wrote above. He could use function handler arguments (thePreviousAccount,theCurrentAccount) but the code I gave to him works fine for me. I always get a player element from this funciton from 'source' :shock:

Link to comment
robhol I'm sorry, you were right. "getPlayerAccount" returns false. That was exactly what you wrote above. He could use function handler arguments (thePreviousAccount,theCurrentAccount) but the code I gave to him works fine for me. I always get a player element from this funciton from 'source' :shock:

I tried both, they both work, but i find the way you told me more comfortable

Link to comment
I want to see if the player's account contains the value of civilian and if it does then it sets his team as civilian. thanks!
  
function onConnect () 
    local theTeam = getAccountData ( source, "hisTeam" ) 
    if source then 
        if theTeam=="" then 
            setPlayerTeam ( source, civilianTeam ) 
            if theTeam==("Civilians") then 
                setPlayerTeam ( source, civilianTeam ) 
            end 
        else 
            outputChatBox ( "ERROR!" ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin" , getRootElement(),  onConnect ) 
  

addEventHandler ( "onPlayerLogin" , getRootElement(), 
function() 
  
local histeam = getAccountData ( source, "hisTeam" ) 
  
     if histeam and histeam == "Civilians" then 
            setPlayerTeam ( source, civilianTeam ) 
                      else 
              outputChatBox ( "ERROR!",source )   
   end 
end 
) 

Link to comment
That won't work.
addEventHandler ( "onPlayerLogin" , getRootElement(), 
function() 
 local acc = getPlayerAccount(source) 
if acc then 
local histeam = getAccountData ( acc, "hisTeam" ) 
  
     if histeam and tostring(histeam) == "Civilians" then 
            setPlayerTeam ( source, civilianTeam ) 
                      else 
              outputChatBox ( "ERROR!",source )   
   end 
end 
end 
) 

Updated

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