Sparrow Posted February 15, 2012 Share Posted February 15, 2012 I'm working on some RPG jobs to get more skills in scripting, so this what I do, no errors. function createPoliceTeam() policeTeam = createTeam ("Police", 25, 50, 255) end addEventHandler ("onResourceStart", getRootElement(), createPoliceTeam) local jobMarker = createMarker (1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255) function setJob(hitElement, thePlayer) local wanted = getPlayerWantedLevel (thePlayer) if (wanted == 0) then if getElementType(hitElement) == "player" then playerName = getPlayerName ( getLocalPlayer() ) if not guiGetVisible(window) then guiSetVisible(window, true) showCursor(true) elseif (wanted > 0) then showCursor(false) guiSetVisible(window, false) end end end end addEventHandler("onClientMarkerHit", jobMarker, setJob) function acceptJob (thePlayer) local getTeam = getTeamFromName ("Police") if theTeam then setPlayerTeam (thePlayer, getTeam) setElementModel (thePlayer, 280) guiSetVisible(window, false) showCursor(false) outputChatBox ("You are now police officer.", thePlayer, 0,255, 0) else outputChatBox ("You are wanted, you can not take this job.", thePlayer, 255, 0, 0) end end addEventHandler("onClientGUIClick", acceptButton , acceptJob, false) it didn't set me in "Police" team, and it says that I'm wanted. how to fix this? and thanks. Link to comment
[STM]Metalhero Posted February 15, 2012 Share Posted February 15, 2012 your problem is "createTeam" ist is server function you must learn to choose server and client side Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 I do this, it didn't work, also no errors server: function createPoliceTeam() policeTeam = createTeam ("Police", 25, 50, 255) end addEventHandler ("onResourceStart", getRootElement(), createPoliceTeam) function acceptJob ( ) local getTeam = getTeamFromName ("Police") if theTeam then setPlayerTeam (source, policeTeam) setElementModel (source, 280) guiSetVisible(window, false) showCursor(false) outputChatBox ("You are now police officer.", source, 0,255, 0) else outputChatBox ("You are wanted, you can not take this job.", source, 255, 0, 0) end end addEvent ("setTeam", true) addEventHandler ("setTeam", getRootElement(), acceptJob) client: local jobMarker = createMarker (1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255) function setJob(hitElement, thePlayer) local wanted = getPlayerWantedLevel (thePlayer) if (wanted == 0) then if getElementType(hitElement) == "player" then playerName = getPlayerName ( getLocalPlayer() ) if not guiGetVisible(window) then guiSetVisible(window, true) showCursor(true) elseif (wanted > 0) then showCursor(false) guiSetVisible(window, false) end end end end addEventHandler("onClientMarkerHit", jobMarker, setJob) Link to comment
Xeno Posted February 15, 2012 Share Posted February 15, 2012 local getTeam = getTeamFromName ("Police") if theTeam then setPlayerTeam (source, policeTeam) What is "theTeam"?? It should be if getTeam then ( I think..) Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 herr herr, what the fail? Link to comment
Kenix Posted February 15, 2012 Share Posted February 15, 2012 Server addEvent( 'onAcceptJob',true ) addEventHandler( 'onAcceptJob',root, function( ) setPlayerTeam ( source,getTeamFromName( 'Police' ) ) setElementModel ( source, 280 ) end ) addEventHandler ( 'onResourceStart', resourceRoot, function( ) createTeam ( "Police", 25, 50, 255 ) end ) Client local jobMarker = createMarker ( 1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255 ) function setJob( player, dim ) if player == localPlayer then local wanted = getPlayerWantedLevel ( ) if wanted == 0 then if not guiGetVisible( window ) then guiSetVisible( window, true ) showCursor( true ) elseif wanted > 0 then showCursor( false ) guiSetVisible( window, false ) end end end end addEventHandler( "onClientMarkerHit", jobMarker, setJob ) function acceptJob ( ) local uTeam = getPlayerTeam( localPlayer ) if uTeam and getTeamName ( uTeam ) ~= 'Police' then triggerServerEvent( 'onAcceptJob',localPlayer ) guiSetVisible( window, false ) showCursor( false ) outputChatBox ( "You are now police officer.", thePlayer, 0,255, 0 ) else outputChatBox ( "You are wanted, you can not take this job.", thePlayer, 255, 0, 0 ) end end addEventHandler( "onClientGUIClick", acceptButton , acceptJob, false ) You need learn https://wiki.multitheftauto.com/wiki/Scr ... troduction You should use in side( client or server ) appropriate function or event. Example if you create gui you need use in client side ( not in server side ) P.S variable window is defined? P.S updated. Link to comment
Xeno Posted February 15, 2012 Share Posted February 15, 2012 Deleted, - Kenix beat me D: NOTE: When setting teams you can't just do this function createTeams() police = createTeam("police",255,0,0) end function setTeam() setPlayerTeam(player, police) end addCommandHandler("setTeam", setTeam) You have to get the team name and use that to set the team, like this: function createTeams() police = createTeam("police",255,0,0) end function setTeam() local getPoliceTeam = getTeamFromName("police") setPlayerTeam(player, getPoliceTeam) end addCommandHandler("setTeam", setTeam) Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 I get job by pressing a button on an GUI, so I don't need command for it. ok, this is good, it's working. hm, I got another problem, when player join or when someone walk to marker, all the players recive the GUI, how to fix that? Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 I'm using yours, but the GUI comes to all players when they join or walk to marker. Link to comment
Kenix Posted February 15, 2012 Share Posted February 15, 2012 Idk how you test , but it working .. Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 here is the gui, I wanna only the GUI showed on screen when player walk to it. window = guiCreateWindow(438,171,370,406,"Job System",false) guiWindowSetSizable(window,false) infoLabel = guiCreateLabel(150,32,66,20,"Police job",false,window) guiLabelSetColor(infoLabel,0,255,0) guiSetFont(infoLabel,"clear-normal") jobMemo = guiCreateMemo(19,61,332,255,"Police job: Description coming soon.!",false,window) guiMemoSetReadOnly(jobMemo,true) acceptButton = guiCreateButton(54,334,113,45,"Accept",false,window) closeButton = guiCreateButton(206,333,113,45,"Close",false,window) Link to comment
Kenix Posted February 15, 2012 Share Posted February 15, 2012 (edited) window = guiCreateWindow( 438,171,370,406,"Job System",false ) guiWindowSetSizable( window,false ) infoLabel = guiCreateLabel( 150,32,66,20,"Police job",false,window ) guiLabelSetColor( infoLabel,0,255,0 ) guiSetFont( infoLabel,"clear-normal" ) jobMemo = guiCreateMemo( 19,61,332,255,"Police job: Description coming soon.!",false,window ) guiMemoSetReadOnly( jobMemo,true ) acceptButton = guiCreateButton( 54,334,113,45,"Accept",false,window ) closeButton = guiCreateButton( 206,333,113,45,"Close",false,window ) guiSetVisible( window,false ) local policePed = createPed (280, 1576.751, -1634.270, 13.556, 90 ) local jobMarker = createMarker ( 1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255 ) function setJob( player, dim ) if player == localPlayer then local wanted = getPlayerWantedLevel ( ) if wanted == 0 then if not guiGetVisible( window ) then guiSetVisible( window, true ) showCursor( true ) elseif wanted > 0 then showCursor( false ) guiSetVisible( window, false ) outputChatBox ( "You are wanted, you can not take this job.", thePlayer, 255, 0, 0 ) end end end end addEventHandler( "onClientMarkerHit", jobMarker, setJob ) function acceptJob ( ) local uTeam = getPlayerTeam( localPlayer ) if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then triggerServerEvent( 'onAcceptJob',localPlayer ) guiSetVisible( window, false ) showCursor( false ) outputChatBox ( "You are now police officer.", 0,255, 0 ) else outputChatBox ( "You are already police officer.", 0,255, 0 ) end end addEventHandler( "onClientGUIClick", acceptButton , acceptJob, false ) function removePoliceWindow( ) guiSetVisible( window, false ) showCursor( false) end addEventHandler( "onClientGUIClick", closeButton , removePoliceWindow, false ) You lol. On resource start it create window FOR ALL CLIENTS ( Why you say if you hit marker it showed for all players ???? ) Code updated. Edited February 15, 2012 by Guest Link to comment
Sparrow Posted February 15, 2012 Author Share Posted February 15, 2012 it showed for all players when I hit marker I test it Link to comment
Kenix Posted February 15, 2012 Share Posted February 15, 2012 No.I test it in sandboxie. Copy code again and past and restart resource. And try again. 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