Jump to content

[Race] triggering stuff via checkpoints?


trustno1

Recommended Posts

So what I'm trying to do is trigger events via reaching checkpoints. The problem I have is: how do I get the checkpoint IDs out of the .map data and how do I trigger a event on a certain checkpoint (i.e. on CP 1).

I've tried some stuff but it looks kinda messy and wrong. I checked a few tutorials and used the search function to find something similar but there wasn't.

So this is what I've got so far:

local checkpoint = getElementsByType ( "checkpoint",getRootElement()) 
function CP1 () 
if checkpoint == checkpoint (1) then 
CP1FBI = createVehicle (490 , -2222.6044921875, -718.970703125 , 65.950073242188 , 355.869140625 , 3.9715576171875, 275.77331542969 )  
CP1PED = createPed ( 285, 0, 0, 0 )  
warpPedIntoVehicle ( CP1PED, CP1FBI) 
setElementData (CP1FBI, 'race.collideothers', 1 )    
setVehicleEngineState (CP1FBI,true)  
setElementVelocity (CP1FBI,0,1,0) 
setElementHealth (CP1FBI, 1) 
setTimer(destroyElement,10000,1,CP1FBI) 
end 
end  
addEvent('onPlayerReachCheckpoint') 
addEventHandler('onPlayerReachCheckpoint', getResourceRootElement(getThisResource()), CP1) 
  

Edited by Guest
Link to comment

LoL

Remove The 3rd Line

and Remove the 14th Line too, This may Make the Script Loading Fail,

and ...

Try This :

local checkpoint = getElementsByType ( "checkpoint",getRootElement()) 
function CP1 () 
CP1FBI = createVehicle (490 , -2222.6044921875, -718.970703125 , 65.950073242188 , 355.869140625 , 3.9715576171875, 275.77331542969 )  
CP1PED = createPed ( 285, 0, 0, 0 )  
warpPedIntoVehicle ( CP1PED, CP1FBI) 
setElementData (CP1FBI, 'race.collideothers', 1 )    
setVehicleEngineState (CP1FBI,true)  
setElementVelocity (CP1FBI,0,1,0) 
setElementHealth (CP1FBI, 1) 
end 
setTimer(destroyElement,10000,1,CP1FBI) 
end  
addEventHandler('onPlayerReachCheckpoint', getResourceRootElement(getThisResource()), CP1) 

I Think It would Work ?

Link to comment

+1 Aiboforcen.

secondly,

@trustno, afaik I know, the event you are using is exported from race gamemode, have a look at this https://wiki.multitheftauto.com/wiki/RU/ ... _in_detail, you probably have to use an integer, for example if you want to trigger your stuff when player reaches checkpoint #1, then you will have to use,

function CP1 (cp) 
if cp == 1 then 
... 

P/S: no need for getElementsByType.

Link to comment

That is the same code. Whats the difference ? Actually using different functions instead of defining the function with event handlers or command handlers is more easy.

root = getRootElement() 
function CP1 (pennis) 
     if pennis == 1 then 
     CP1FBI = createVehicle (490 , -2222.6044921875, -718.970703125 , 65.950073242188 , 355.869140625 , 3.9715576171875, 275.77331542969 ) 
     CP1PED = createPed ( 285, 0, 0, 0 ) 
     warpPedIntoVehicle ( CP1PED, CP1FBI) 
     setElementData (CP1FBI, 'race.collideothers', 1 )   
     setVehicleEngineState (CP1FBI,true) 
     setElementVelocity (CP1FBI,0,1,0) 
     setElementHealth (CP1FBI, 1) 
     setTimer(destroyElement,10000,1,CP1FBI) 
     end 
end 
addEvent('onPlayerReachCheckpoint') 
addEventHandler('onPlayerReachCheckpoint', root, CP1) 

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...