Sign in to follow this  
Pikachu

[HELP] bad argument @ 'getPlayerTeam'

Recommended Posts

i need someone to help me with my script, i run it i see at the console (bad argument @ 'getPlayerTeam')

function:

function onTeamJoin(thePlayer) 
    if not getPlayerTeam(thePlayer) then return end 
    if getTeamName(getPlayerTeam(thePlayer)) == "Mailmen" then 
    local x, y, z = getNewMailLocation(thePlayer, 1) 
    setElementData(thePlayer, "mailData", 1) 
    end 
end 
addEventHandler("onElementDataChange",rootElement,onTeamJoin) 

Share this post


Link to post

Use source, and you need to check if the element is a player before acting on it.

Share this post


Link to post

try this:

rootElement = getRootElement() 
  
function onTeamJoin() 
    if not getPlayerTeam(source) then return end 
    if getTeamName(getPlayerTeam(source)) == "Mailmen" then 
    local x, y, z = getNewMailLocation(source, 1) 
    setElementData(source, "mailData", 1) 
    end 
    end 
addEventHandler("onElementDataChange",rootElement,onTeamJoin) 

Share this post


Link to post

In function http://wiki.multitheftauto.com/wiki/OnElementDataChange, first argument is the name of the element data entry that changed

Player can be source of this event.

The source of this event is the element whose elementdata changed.

Also, u should check that the element is a player before acting on it.

So, this code is more correct:

function onTeamJoin(dataName) 
    if (source and getElementType(source) == "player" and getPlayerTeam(source) ) then 
        if ( getTeamName(getPlayerTeam(source)) == "Mailmen" ) then 
            local x, y, z = getNewMailLocation(source, 1) 
            setElementData(source, "mailData", 1) 
        end 
    end 
end 
addEventHandler("onElementDataChange",root,onTeamJoin) 

Also u can check data name. For example:

  
function func(dataName) 
    if ( dataName == "mailData" ) then --Data Name Check 
    -- CODE HERE 
    end 
end 
addEventHandler("onElementDataChange",root,func) 

Edited by Guest

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.