Jump to content

[Tutorial] Creating a marker for random vehicles [Tutorial]


novo

Recommended Posts

Hi all.

Today i'll learn you how to create a marker for random vehicles.

This idea is taken from a Mr. Green's map.

Let's begin...

1. You must get all IDs that you want to use. You can see all vehicles ID's here: https://wiki.multitheftauto.com/wiki/Vehicle_IDs#2-Door_and_Compact_cars

2. I'll use all vehicles in mta.

3. Now, let's create the marker:

marker = createMarker(1314,-1575,12,"corona",2,0,255,0) 

You must change "1314,-1575,12" for the x,y,z of where you want to locate the marker.

4. Now, we add a handled function that will happen when player (source) hits the marker:

addEventHandler("onClientMarkerHit",marker, 
function() 
    local vh = getPedOccupiedVehicle ( source ) 
    vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } 
    nm = tonumber ( math.random( #vehicles ) ) 
    setElementModel ( vh, nm )   
end)  
  
  
  
  
  
  

5. Finally, we gotta put together these two codes, like this:

marker = createMarker(x, y, z,"corona",2,0,255,0) 
  
addEventHandler("onClientMarkerHit",marker, 
function() 
    local vh = getPedOccupiedVehicle ( source ) 
    vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } 
    nm = tonumber ( math.random( #vehicles ) ) 
    setElementModel ( vh, nm )   
end)  
  
  
  

6. Save that code as "client.lua" into the map folder.

7. Open the file meta.xml located inside the map folder.

8. Add at the beginning below this code:

<script src="client.lua" type="client" /> 

9. Save the meta.xml

10. We finished.

NOTE: THIS CODE WASN'T TESTED YET, IF YOU HAVE PROBLEMS WITH IT TELL IT TO ME WITH A REPLY.

I hope you like it!

Bye

Edited by Guest
Link to comment
Guest Guest4401
marker = createMarker(x, y, z,"corona",2,0,255,0) 
  
addEventHandler("onClientMarkerHit",marker, 
function() 
    local vh = getPedOccupiedVehicle ( source ) 
    vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } 
    nm = tonumber ( math.random( #vehicles ) ) 
    setElementModel ( vh, nm )   
end)  
  
  
  

It has a few errors

  • source in getPedOccupiedVehicle is the marker, not the player.
  •     nm = tonumber ( math.random( #vehicles ) ) 
        setElementModel ( vh, nm )   
    


    This picks a random number from 1 to count of table, not a random vehicle model. It should be something like:

    nm = tonumber(vehicles[math.random(#vehicles)]) 
    

Link to comment
  • 4 weeks later...

Posting untested (and error-riddled) code in a Tutorial section is probably not something you want to do.

I mean, effort appreciated and all, but seriously, this won't help anyone. Testing such a basic script wouldn't take much time, either.

  • Like 1
Link to comment
It appears no one in MTA knows how to speak good English but Karthik.

lol, 1) That was totally offtopic 2) I'm pretty sure I have great English 3) He is indian 4) OThers can speak perfect english too.

God, chris e_e!

Link to comment
  • 1 month later...
  • 9 months later...

what did i wrong ? can you help me ?

marker = createMarker(2121, 1402, 10,"cylinder",2,0,255,0)

addEventHandler("onClientMarkerHit",marker,

function()

local vh = getPedOccupiedVehicle ( source )

vehicles = 4, 3, 1

nm = tonumber ( math.random( #vehicles ) )

setElementModel ( vh, nm )

end)

Link to comment

-- # Client Side 
local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) 
  
addEventHandler("onClientMarkerHit",marker, 
    function ( player ) 
        if getElementType ( player ) == "player" then  
            local vehicle =  getPedOccupiedVehicle ( player ) 
             if not vehicle then return end 
            local vehicles =  { 411,412,413 } 
            local ID = (vehicles[math.random(#vehicles)]) 
            setElementModel ( vehicle, ID )  
    end 
end,false 
) 

Erros :

-- You're entered id was wrong

-- Check the vehicle with a source element ?

-- Get a random model was wrong .

Link to comment

hi #Mr.Pres[T]ege you are really PRO but is this also for the server side

-- # Client Side 
local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) 
  
addEventHandler("onClientMarkerHit",marker, 
    function ( player ) 
        if getElementType ( player ) == "player" then  
            local vehicle =  getPedOccupiedVehicle ( player ) 
             if not vehicle then return end 
            local vehicles =  { 411,412,413 } 
            local ID = (vehicles[math.random(#vehicles)]) 
            setElementModel ( vehicle, ID )  
    end 
end,false 
) 

Erros :

-- You're entered id was wrong

-- Check the vehicle with a source element ?

-- Get a random model was wrong .

Link to comment
hi #Mr.Pres[T]ege you are really PRO but is this also for the server side
-- # Client Side 
local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) 
  
addEventHandler("onClientMarkerHit",marker, 
    function ( player ) 
        if getElementType ( player ) == "player" then  
            local vehicle =  getPedOccupiedVehicle ( player ) 
             if not vehicle then return end 
            local vehicles =  { 411,412,413 } 
            local ID = (vehicles[math.random(#vehicles)]) 
            setElementModel ( vehicle, ID )  
    end 
end,false 
) 

Erros :

-- You're entered id was wrong

-- Check the vehicle with a source element ?

-- Get a random model was wrong .

No it's only client side you can use this server side :

-- # Server Side 
local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) 
  
addEventHandler("onMarkerHit",marker, 
    function ( player ) 
        if getElementType ( player ) == "player" then  
            local vehicle =  getPedOccupiedVehicle ( player ) 
             if not vehicle then return end 
            local vehicles =  { 411,412,413 } 
            local ID = (vehicles[math.random(#vehicles)]) 
            setElementModel ( vehicle, ID )  
    end 
end,false 
) 

Link to comment
  • 3 years later...

Greetings, I have followed your steps but unfortunately, nothing happened, even the ' debug script 3 '  did not inform me if there are errors!

Here is my work: 

Client.lua:

Spoiler

 

marker = createMarker(2226, 1512, 10, "corona",2,0,255,0)

addEventHandler("onClientMarkerHit",marker,
function()
local vh = getPed0ccupiedVehicle ( source )
vehicles = { 4, 1, 0 }
nm = tonumber ( math.random( #vehicles ) )
setElementModel ( vh, nm )
end)

 

 
 

meta.xml file:

Spoiler

<script src="client.lua" type="client" />

 

What is the wrong?!
 

Edited by Petey99
Link to comment
  • 2 weeks later...
  • Recently Browsing   0 members

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