Jump to content

[TUT] Simple marker-job script.


Recommended Posts

Hello there. I though I would learn you guys how to make a real easy job marker. With a gui appearing when the player enters the marker. And sets you in the correct team.

OBS! This requires you to run scoreboard on the server and have a team called "Carjacker"!

This script is most suited on an RPG server.

First, lets create the marker. And add when the client hits the marker, the gui will be shown.

(CLIENT SCRIPT)

jobmarker = createMarker(1314,-1575,12,"cylinder",2,0,255,0) -- creates the marker at the given x,y,z sets the marker size and rgb color also wich type of marker. 
addEventHandler("onClientMarkerHit",jobmarker,function(p) if p == lp and not isPedInVehicle(lp) then guiSetVisible(jobwindow,true) showCursor(true) end end) -- adds an event so if I'm not in a car the gui will be visible on marker hit 
  

now let's create the gui.

sx,sy = guiGetScreenSize() -- creates a variable 
lp = getLocalPlayer() -- creates a variable 
mr = math.random(1,2) -- creates a variable 
jobwindow = guiCreateWindow(0.3*sx,0.3*sy,0.4*sx,0.4*sy,"Car Jacker",false) -- creates the "window" 
sx,sy = 0.5*sx,0.5*sy 
memo = guiCreateMemo(0*sx,0.05*sy,0.8*sx,0.6*sy,"Description here",false,jobwindow) -- creates the memo text 
takebutton = guiCreateButton(0.25,0.9,0.2,0.18,"Accept",true,jobwindow) -- creates the accept button 
cancbutton = guiCreateButton(0.55,0.9,0.2,0.18,"Cancel",true,jobwindow) -- creates the cancel button 
guiSetVisible (jobwindow,false) -- makes the gui unvisible  
guiMemoSetReadOnly(memo,true) -- makes so the memo text cannot be edited. 
guiWindowSetMovable (jobwindow,false ) -- makes to the window is not moveable 
guiWindowSetSizable (jobwindow,false ) -- makes so you cannot set the size. 

This creates a calculated gui window in the middle of the screen with a memo text and two buttons to either accept or close the gui.

Now, let's add a message saying I'm employed as a Car Jacker if I click on the "Accept" button (takebutton) and if the player clicks on the "Cancel" button (cancbutton) the gui will be closed.

addEventHandler("onClientGUIClick",jobwindow, 
function(b)  
    if b == "left" then 
        if source == takebutton then -- checks if I press on the accept or not 
            if getTeamName(getPlayerTeam(lp)) ~= "Carjacker" then -- checks if I'm in the carjacker team 
            triggerServerEvent("haveCarJob",lp) -- triggers the server event  
            outputChatBox ("You are now now employed as a car jacker",255,255,0, true) -- outputs a message 
            guiSetVisible(jobwindow,false) -- closes the gui 
            showCursor(false) -- removes the cursor 
            end 
        elseif source == cancbutton then -- checks if I press on the cancel button 
        guiSetVisible(jobwindow,false) -- and if I do, the gui will close. 
        showCursor(false) -- removes the cursor 
        end 
    end 
end) 

And now, let's check if the player is in "Carjacker" team, and if he is a message will be shown and he wont see the gui when he hits the marker.

addEventHandler("onClientMarkerHit",jobmarker, 
        function(p) 
             if p == lp and not isPedInVehicle(lp) then -- checks so if I'm in a vehicle the gui will not be shown 
                 guiSetVisible(jobwindow,true) -- sets the gui visible on marker hit 
                showCursor(true) -- sets the cursor visible  
                if getTeamName(getPlayerTeam(lp)) == "Carjacker" then -- checks if I'm in the Carjacker team 
                outputChatBox ("You already have this job..",0,255,0, true) -- if I am, outputs a message 
        guiSetVisible(jobwindow,false) -- sets the gui unvisible 
        showCursor(false) -- removes the cursor 
        end 
    end 
end) 

and, at last

addEvent("haveMonkeyJob",true) -- adds the event which will be triggered server sided 

So, the full client sided script is:

jobmarker = createMarker(1314,-1575,12,"cylinder",2,0,255,0) 
addEventHandler("onClientMarkerHit",jobmarker,function(p) if p == lp and not isPedInVehicle(lp) then guiSetVisible(jobwindow,true) showCursor(true) end end) 
  
sx,sy = guiGetScreenSize() 
lp = getLocalPlayer() 
mr = math.random(1,2) 
jobwindow = guiCreateWindow(0.3*sx,0.3*sy,0.4*sx,0.4*sy,"Car Jacker",false) 
sx,sy = 0.5*sx,0.5*sy 
memo = guiCreateMemo(0*sx,0.05*sy,0.8*sx,0.6*sy,"Description here",false,jobwindow) 
takebutton = guiCreateButton(0.25,0.9,0.2,0.18,"Accept",true,jobwindow) 
cancbutton = guiCreateButton(0.55,0.9,0.2,0.18,"Cancel",true,jobwindow) 
guiSetVisible (jobwindow,false) 
guiMemoSetReadOnly(memo,true) 
guiWindowSetMovable (jobwindow,false ) 
guiWindowSetSizable (jobwindow,false ) 
  
addEventHandler("onClientGUIClick",jobwindow, 
function(b) 
    if b == "left" then 
        if source == takebutton then 
            if getTeamName(getPlayerTeam(lp)) ~= "Carjacker" then 
            triggerServerEvent("haveMonkeyJob",lp) 
            outputChatBox ("You are now now employed as a car jacker",255,255,0, true) 
            guiSetVisible(jobwindow,false) 
            showCursor(false) 
            end 
        elseif source == cancbutton then 
        guiSetVisible(jobwindow,false) 
        showCursor(false) 
        end 
    end 
end) 
  
addEventHandler("onClientMarkerHit",jobmarker, 
        function(p) 
             if p == lp and not isPedInVehicle(lp) then 
                 guiSetVisible(jobwindow,true)  
                showCursor(true)  
                if getTeamName(getPlayerTeam(lp)) == "Carjacker" then 
                outputChatBox ("You already have this job..",0,255,0, true) 
        guiSetVisible(jobwindow,false) 
        showCursor(false) 
        end 
    end 
end)  
  
addEvent("haveMonkeyJob",true) 
  

(SERVER SCRIPT)

So, the whole client sided script is done. Now let's create the server script.

First, we need to add the event and the function..

addEvent("haveMonkeyJob",true) 
function haveMonkeyJob() 

Then we need to trigger the clientevent

triggerClientEvent(source,"haveMonkeyJob",root,TheX,TheY) 

And, now we need to set the player into the correct team.

setPlayerTeam(source,getTeamFromName("Carjacker")) 

So, whole server sided script is:

addEvent("haveMonkeyJob",true) -- adds the event 
function haveMonkeyJob()  
triggerClientEvent(source,"haveMonkeyJob",root,TheX,TheY) -- triggers the client event 
setPlayerTeam(source,getTeamFromName("Carjacker")) -- sets me in "Carjacker" team 
end 
addEventHandler("haveMonkeyJob",root,haveMonkeyJob) 

Download Link to the resource: http://www.mediafire.com/?9r3kmukebokzc12

Link to comment
  • 1 month later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...