Jump to content

[HELP] WHat am i doing wrong?


Imposter

Recommended Posts

Posted

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 ) 
  

Eat My Dust - DM/Deathmatch

350x20_00C3FF_FFFFFF_000000_000000.png

Posted

'source' of onPlayerLogin is the player that logged in, not his/her account.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
'source' of onPlayerLogin is the player that logged in, not his/her account.

I referenced the wiki getAccountData and thats what it says, what am i supposed to use, getElementRoot() ?

Eat My Dust - DM/Deathmatch

350x20_00C3FF_FFFFFF_000000_000000.png

Posted

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 ) 

Posted
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 ) 
  

Eat My Dust - DM/Deathmatch

350x20_00C3FF_FFFFFF_000000_000000.png

Posted

So, getPlayerAccount returns false. What does that tell you? Have you tried using one of the function handler arguments instead?

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

Posted

NooP that error means that there is no such a data "hisTeam" in your player account. You can get a data from an account only in case it was set in it once.

Posted
NooP that error means that there is no such a data "hisTeam" in your player account. You can get a data from an account only in case it was set in it once.

No.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

Posted

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:

Posted
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

Eat My Dust - DM/Deathmatch

350x20_00C3FF_FFFFFF_000000_000000.png

Posted
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 
) 

krsofa999.gif
Posted

That won't work.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

krsofa999.gif

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