Jump to content

[Race] triggering stuff via checkpoints?


trustno1

Recommended Posts

Posted (edited)

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
Posted
what this means ? :o
if checkpoint == checkpoint (1) then 

whatever this is - it will never be true

^^

What I tried to do is:

If the checkpoint the player crossing is "checkpoint (1)" then it should do the stuff below (createvehicle etc.)

Posted

«checkpoint (1)» is a function notation, indexed table syntax is «checkpoint[1]».

but it still wont be true cause «checkpoint» is already a table, and you're trying to compare a table with it's value at index 1.

Posted

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 ?

Posted

no it won't. and this WILL "Make the Script Loading Fail".

seriously, you can't even fix your own scripts, can't use indentation. and now you're trying to fix something by deleting stuff without thinking.

Posted

or you could use the simple, faster way:

addEventHandler("onPlayerReachCheckpoint", getRootElement(),  
    function(cp_number) 
        blah blah blah, your code here, cp_number is the cp the player hit 
    end 
) 

Posted

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) 

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