Jump to content

[HELP] Mission


1LoL1

Recommended Posts

Hello i created my own script but i don't know how i can when player use /job so marker and blip will be showed only to who use /job. And next is please how i can fix this when i use /job so marker and blip will be created but how i can when i'am go onMarkerHit then marker and blip will be destroyed? :(

/job --> Will be created Marker and Blip

onMarkerHit --> Marker & Blip will be destroyed

function job (source) 
marker1 = createMarker(-2708.6142578125, 1358.259765625, 7.0769176483154, "cylinder", 1.5, 255, 255, 0, 170) 
blip1 = createBlip(-2708.6142578125, 1358.259765625, 7.0769176483154, 0) 
setElementData(source, "mission", true) 
end 
addCommandHandler("job", job) 
  
function marker (thePlayer) 
local money = math.random(5000,15000) 
givePlayerMoney(thePlayer, money) 
setElementData(thePlayer, "mission", false) 
if getElementData(thePlayer, "mission") == false then 
destroyElement(marker1) 
destroyElement(blip1) 
outputChatBox("#00FF00Mission complete. You get "..convertNumber(money).."$!", thePlayer, 255, 255, 255, true) 
end 
end 
addEventHandler("onMarkerHit", marker1, marker) 

Link to comment
Hello i created my own script but i don't know how i can when player use /job so marker and blip will be showed only to who use /job. And next is please how i can fix this when i use /job so marker and blip will be created but how i can when i'am go onMarkerHit then marker and blip will be destroyed? :(

/job --> Will be created Marker and Blip

onMarkerHit --> Marker & Blip will be destroyed

  
function job (source) 
   marker1 = createMarker(-2708.6142578125, 1358.259765625, 7.0769176483154, "cylinder", 1.5, 255, 255, 0, 170) 
   blip1 = createBlip(-2708.6142578125, 1358.259765625, 7.0769176483154, 0) 
   setElementData(source, "mission", true) 
end 
  
addCommandHandler("job", job) 
  
function markerJob (thePlayer) 
   local money = math.random(5000,15000) 
   givePlayerMoney(thePlayer, money) 
   setElementData(thePlayer, "mission", false) 
    
   if getElementData(thePlayer, "mission") == false then 
      destroyElement(marker1) 
      destroyElement(blip1) 
      outputChatBox("#00FF00Mission complete. You get "..convertNumber(money).."$!", thePlayer, 255, 255, 255, true) 
   end 
end 
  
addEventHandler("onMarkerHit", marker1, marker) 

if your code doesn't works i think is becouse your function have a native function name. Try to replace your function name call marker with markerJob, and tell me what about.

if getElementData(thePlayer, "mission") == false then 

Have no sense imho, you can avoid it and left only destroy functions without If istruction.

Link to comment
Hello i created my own script but i don't know how i can when player use /job so marker and blip will be showed only to who use /job. And next is please how i can fix this when i use /job so marker and blip will be created but how i can when i'am go onMarkerHit then marker and blip will be destroyed? :(

/job --> Will be created Marker and Blip

onMarkerHit --> Marker & Blip will be destroyed

  
function job (source) 
   marker1 = createMarker(-2708.6142578125, 1358.259765625, 7.0769176483154, "cylinder", 1.5, 255, 255, 0, 170) 
   blip1 = createBlip(-2708.6142578125, 1358.259765625, 7.0769176483154, 0) 
   setElementData(source, "mission", true) 
end 
  
addCommandHandler("job", job) 
  
function markerJob (thePlayer) 
   local money = math.random(5000,15000) 
   givePlayerMoney(thePlayer, money) 
   setElementData(thePlayer, "mission", false) 
    
   if getElementData(thePlayer, "mission") == false then 
      destroyElement(marker1) 
      destroyElement(blip1) 
      outputChatBox("#00FF00Mission complete. You get "..convertNumber(money).."$!", thePlayer, 255, 255, 255, true) 
   end 
end 
  
addEventHandler("onMarkerHit", marker1, marker) 

if your code doesn't works i think is becouse your function have a native function name. Try to replace your function name call marker with markerJob, and tell me what about.

if getElementData(thePlayer, "mission") == false then 

Have no sense imho, you can avoid it and left only destroy functions without If istruction.

My code works normally but when i started resource then there is marker and blip and i want only when i use /job then blip and marker will be created. and when i finish mission or onMarkerHit blip and marker will destroyed.

Link to comment

Both createMarker and createBlip have an argument that specifies which elements can see the marker/blip (if you don't knew see the syntax at the wiki).

To destroy the elements later you have to save them at a table (or with element datas), if you don't do it, other markers will overwrite the marker1 variable for example. to do this we'll create a table at the top of the code.

myTable = {} 

Then, when the player type /job, we've to define his table:

myTable[source] = {} -- create a new table for the player 
myTable[source]["marker"] = createMarker ( ......... ) -- define the marker index at the player's table as the marker element. 
myTable[source]["blip"] = createBlip ( ......... ) -- define the blip index at the player's table as the blip element. 

Now we're going to have the elements stored in the player table, so they're 'safe'.

When the player hit any marker we check if the marker is the same that is in the player's table, if it is we give the money to him.

function onHitAnyMarker ( thePlayer ) 
    -- Check if the player have a table (and is doing a job). 
    if myTable[thePlayer] then 
        -- Check if the hited marker is the that is in his table 
        if source == myTable[thePlayer]["marker"] then 
            givePlayerMoney( thePlayer, math.random( 5000, 15000 ) ) 
  
            destroyElement(marker1) 
            destroyElement(blip1) 
            outputChatBox("#00FF00Mission complete. You get "..convertNumber(money).."$!", thePlayer, 255, 255, 255, true) 
        end 
    end 
end 
addEventHandler("onMarkerHit", root, onHitAnyMarker) 

Hope you've understood my explanation :P.

Link to comment

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
  • Recently Browsing   0 members

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