kieran Posted September 5, 2017 Share Posted September 5, 2017 I'm trying to get the player when he joins and trigger an event tied to a function, it originally has a marker, you hit marker then you start the script, it works with adding a command handler to the function, but I can't just add an onPlayerLogin event as I want it to check team. Here's all you should need to save confusion. Function to trigger client side event (works 100%) IronMarker = createMarker (327.93359375, 865.84765625, 19.0625, "cylinder", 2, 0, 200, 55, 255) local IronMinerTeam = createTeam("Iron_Miner", 20, 100, 150) IronJobBlip = createBlipAttachedTo ( IronMarker, 56 ) function IronMiner ( hitElement, matchingDimension ) if isElement(hitElement) and getElementType(hitElement) == "player" and matchingDimension then if getElementData( hitElement, "Iron.pres" ) == nil then setElementData (hitElement, "Iron.pres", 0) --outputChatBox("You have successfully registered as an iron miner, please enter the marker again to start working!", hitElement, 255, 0, 0) end if ( IronMinerTeam ) then if isPedOnGround ( hitElement ) then setPlayerTeam(hitElement, IronMinerTeam) --triggerClientEvent ( hitElement, "ShowIron", hitElement ) local TheIron = getElementData( hitElement, "Iron.pres" ) if (TheIron) then if ( tonumber (TheIron) >= tonumber (9999999)) then outputChatBox ("You may only mine iron if your iron is below 99999999, please sell some at the T icon on F11 or by typing: /selliron amount", hitElement, 255, 0, 0) elseif ( tonumber (TheIron) <= tonumber (9999999) or nil) then triggerClientEvent ( hitElement, "IronMinerStuff", hitElement ) else outputChatBox("You must be on foot to change team!", hitElement, 255, 0, 0) end end end end end end addEvent("IronLoginEvent", true) addEventHandler("IronLoginEvent", getRootElement(), IronMiner) addEventHandler("onMarkerHit", IronMarker, IronMiner) Function that is not working (Meant to trigger the event above) function LoginHandler () local checkTeam = getTeamFromName("Iron_Miner") if ( checkTeam ) then local playerTeam = getPlayerTeam(player) if ( playerTeam == checkTeam ) then triggerEvent ( "IronLoginEvent", player ) end end end addEventHandler("onPlayerLogin", root, LoginHandler) So it keeps showing up with error on line 5 (on second code snippet) saying that it expected a player at argument one where getPlayerTeam is, I tried localPlayer and source.... How do I get the player? This is meant to trigger client event to make a marker and a blip, that's all. Thanks for help. Link to comment
ForLaXPy Posted September 5, 2017 Share Posted September 5, 2017 Well firstly add player varialbe in the function like this LoginHandler (player) and you can replace Lines 2,3,4,5,6,7 with those 2 lines local team = getPlayerTeam(player) if ( getTeamName(team) == "Iron_Miner" ) then Link to comment
kieran Posted September 5, 2017 Author Share Posted September 5, 2017 36 minutes ago, ForLaXPy said: Well firstly add player varialbe in the function like this LoginHandler (player) and you can replace Lines 2,3,4,5,6,7 with those 2 lines local team = getPlayerTeam(player) if ( getTeamName(team) == "Iron_Miner" ) then It says it gets the account when the player logs in, so clearly not the player..... Here is the script that gets and saves a players team. --Team save function onPlayQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in local myTeam = getPlayerTeam ( source ) if (myTeam) then local currentTeam = getTeamName ( myTeam ) setAccountData ( playeraccount, "TeamLog", currentTeam ) -- save it in his account end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayQuit ) --Team load function onPlayLogin (_, playeraccount ) if ( playeraccount ) then local LoadTeam = getAccountData ( playeraccount, "TeamLog" ) if ( LoadTeam ) then teamLoad = getTeamFromName ( LoadTeam ) setPlayerTeam ( source, teamLoad ) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayLogin ) It says: [2017-09-05 16:33:00] WARNING: IronMiner\Iron_Miner_S.lua:95: Bad argument @ 'getPlayerTeam' [Expected player at argument 1, got account] [2017-09-05 16:33:00] WARNING: IronMiner\Iron_Miner_S.lua:96: Bad argument @ 'getTeamName' [Expected team at argument 1, got boolean] So it is getting account, NOT player, I am wanting to know how to get the player only... remember what I said originally, I tried player, source, etc... But same result, source does notihng and player gets account. Same thing happens when I assign "thePlayer" to the function, as you shown me with player, it does the exact same.... At a wall here haha, all I need is to get the players team and trigger an event if that player is in the specified team when they log in. 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