Jump to content

Checkpoints script


steve123

Recommended Posts

Hi

It is possible to make a script which will be change vehicle for random if player touch it ?

Because I want give 5 cars id's and on my server when checkpoint will be have a color ( 225,0,0 ) - only this color of checkpoint it will be give random car of these id's ( 429, 541, 480 , 411 , 565 )

And if it is possible can you tell me which function should I use ?

Link to comment
  
vehiclesid = {429, 541, 480 , 411 , 565} 
  
changermarker = createMarker(x, y, z, "typeofmarker", size,255, 0, 0, alpha) 
  
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
if  getMarkerColor(source) == 255,0,0 then -- We check the color of the marker  
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
end 
end 
end 
addEventHandler( "onMarkerHit", getRootElement() , MarkerHit) 
  

I don't try this but it should work :P

Link to comment
  
vehiclesid = {429, 541, 480 , 411 , 565} 
  
changermarker = createMarker(x, y, z, "typeofmarker", size,255, 0, 0, alpha) 
  
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
if  getMarkerColor(source) == 255,0,0 then -- We check the color of the marker  
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
end 
end 
end 
addEventHandler( "onMarkerHit", getRootElement() , MarkerHit) 
  

I don't try this but it should work :P

In no way is this helping the OP. The OP directly asked for a list of functions and never asked for the full code because he is not learning from it. Anyone can copy and paste.

To answer the topic, you can use createMarker, onMarkerHit, createVehicle and setElementModel. Bold means it's an event rather than function.

It would also be a good idea to put the list of models you wish to use in a table using curly brackets. By doing this you can easily loop through each of the vehicles and even choose one from random. For example if the table was called 'vehicles', you can use vehicles[math.random(1, #vehicles)] which would fetch a random vehicle from the table.

Link to comment
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
local r,g,b = getMarkerColor(source) 
if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
end 
end 
end 
end 
  

This code work. I just edit a little bit.

Link to comment

Try this:

vehiclesid = {429, 541, 480, 411, 565} 
  
marker = createMarker(x, y, z, "typeofmarker", size, 255, 0, 0, 255) 
  
addEventHandler( "onMarkerHit", marker,  
function (element) 
    if getElementType(element) == "player" then  
        local x,y,z = getElementPosition(element) 
        local rx,ry,rz = getElementRotation(element) 
        local r, g, b, a = getMarkerColor(marker) 
        if r == 255 and g == 0 and b == 0 and a == 255 then 
            local vehicle = math.random(1,#vehiclesid) 
                local veh = createVehicle(vehicle, x, y, z, 0, 0, rx, ry, rz) 
                warpPedIntoVehicle(element, veh) 
        end 
    end 
end 
) 

Link to comment
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
local r,g,b = getMarkerColor(source) 
if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
end 
end 
end 
end 

I retry this this moon and, it work perfectly

Link to comment
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
local r,g,b = getMarkerColor(source) 
if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
end 
end 
end 
end 

I retry this this moon and, it work perfectly

How does this even work? There is no event handling the function.

Link to comment

I swear it dont works :( :( I checked few times and my color of checkpoints is the same like on the script and nothing happen

this is code

  
vehiclesid = {429, 541, 480, 411, 565} 
  
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then  
local r,g,b = getMarkerColor(source) 
if r == 255 and g == 0 and b == 0 then  
local x,y,z = getElementPosition(hitElement)  
if not isPedInVehicle(hitElement) then  
local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement))  
warpPedIntoVehicle(hitElement, vehicle)  
end 
end 
end 
end 
  

PS: I tried with every codes on this thread

Link to comment
function MarkerHit( hitElement) 
if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player 
local r,g,b = getMarkerColor(source) 
if r == 255 and g == 0 and b == 0 then -- We check the color of the marker 
local x,y,z = getElementPosition(hitElement) -- Get the position of the player 
if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle 
local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table 
warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle 
end 
end 
end 
end 

I retry this this moon and, it work perfectly

How does this even work? There is no event handling the function.

Oh, f*ck I'm so stupid ...

Write that after the last "end" ...

addEventHandler( "onMarkerHit", getRootElement(), MarkerHit ) 

Link to comment
  • 3 years later...

Hi

 

I was browsing the forum and I' ve found this topic, I know it's very old topic ,but I can use this script in other way for the server,

how can I fix this script ? and make it useful, cause This code does't work ( I' ve specially made account in this forum to solve this problem guys ?) Can you help me with this  ?

Link to comment
2 hours ago, homie99 said:

Hi

 

I was browsing the forum and I' ve found this topic, I know it's very old topic ,but I can use this script in other way for the server,

how can I fix this script ? and make it useful, cause This code does't work ( I' ve specially made account in this forum to solve this problem guys ?) Can you help me with this  ?

if you want try this script with only red marks try this

 

 server only

 

 

 

vehiclesid = {429, 541, 480 , 411 , 565}
   
function giveRandomCar( hitElement)
local r = getMarkerColor(source)
local x,y,z = getElementPosition(hitElement)
if r == 255 and getElementType(getVehicleController(hitElement)) == "Player"  then
local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement))
if veh then
warpPedIntoVehicle(getVehicleController(hitElement),veh)
if getElementType(hitElement) == "Vehicle" then
destroyElement (hitElement)
end
end
end
end
addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) 

 

 

 

and this with all marks colors

vehiclesid = {429, 541, 480 , 411 , 565}
 
function giveRandomCar( hitElement)
local x,y,z = getElementPosition(hitElement)
if getElementType(getVehicleController(hitElement)) == "Player"  then
local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement))
if veh then
warpPedIntoVehicle(getVehicleController(hitElement),veh)
if getElementType(hitElement) == "Vehicle" then
destroyElement (hitElement)
end
end
end
end
addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) 

 

Edited by komal
Link to comment

Hi

Thank you komal for your job, but I don't know why It still doesn't works.

This is a link for this which i used. Can you check it ? (I checked the race checkpoint and there was to color r-225 )

http://www.mediafire.com/file/7c1njkk0hns9j5s/test.rar/file

 

Link to comment
  • Moderators
17 hours ago, homie99 said:

Any ideas ? , any body ? ?

What is this entire topic all about if you haven't even wrote a single line of code? Also not even debug and validate the code in a single way?

If you did not come here to script, please go discus this in a personal message with the one that did donate the code.

This section is not for requesting free code, it is for learning how to code.

 

Link to comment

Okay, Okay

I think the problem is getMarkerColor, in my view it should be something with checkpoints, I made this part of code with tutorial and it still doen'st works ? what Can I change  ? ;)

 

function checkpoint:getCheckpoint(i)
local realcheckpoint = g_Checkpoints[i]
local checkpoint = {}
for k,v in pairs(realcheckpoint) do
checkpoint[k] = v

end

checkpoint.vehicle = self:getRandomVehicle(checkpoint)
return checkpoint


vehiclesid = {429, 541, 480 , 411 , 565}
   
function giveRandomCar( hitElement)
local r = getMarkerColor(source)
local x,y,z = getElementPosition(hitElement)
if r == 255 and getElementType(getVehicleController(hitElement)) == "Player"  then
local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement))
if veh then
warpPedIntoVehicle(getVehicleController(hitElement),veh)
if getElementType(hitElement) == "Vehicle" then
destroyElement (hitElement)
end
end
end
end
addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) 

 

Link to comment
  • Moderators
1 hour ago, homie99 said:

I think the problem is getMarkerColor, in my view it should be something with checkpoints, I made this part of code with tutorial and it still doen'st works ? what Can I change  ? ;)

What you can change is learning the basics of Lua, so that you read code and understand that copying and pasting more advance code is not clever...

 

 

Link to comment
  • IIYAMA locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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