Pikachu Posted August 15, 2012 Share Posted August 15, 2012 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) Link to comment
robhol Posted August 15, 2012 Share Posted August 15, 2012 Use source, and you need to check if the element is a player before acting on it. Link to comment
Tete omar Posted August 15, 2012 Share Posted August 15, 2012 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) Link to comment
Flaker Posted August 15, 2012 Share Posted August 15, 2012 (edited) In function https://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 August 15, 2012 by Guest Link to comment
Tete omar Posted August 15, 2012 Share Posted August 15, 2012 rootElement is not defined anyway .. correct your code 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