trustno1 Posted November 21, 2010 Share Posted November 21, 2010 (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 November 21, 2010 by Guest Link to comment
dzek (varez) Posted November 21, 2010 Share Posted November 21, 2010 what this means ? if checkpoint == checkpoint (1) then whatever this is - it will never be true Link to comment
trustno1 Posted November 21, 2010 Author Share Posted November 21, 2010 what this means ? 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.) Link to comment
Aibo Posted November 21, 2010 Share Posted November 21, 2010 «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. Link to comment
BabY Posted November 21, 2010 Share Posted November 21, 2010 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
Aibo Posted November 21, 2010 Share Posted November 21, 2010 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. Link to comment
dzek (varez) Posted November 21, 2010 Share Posted November 21, 2010 Yup, no offence MI550, but if you don't know even the basics - don't try to help - you are misleading people.. Link to comment
Static-X Posted November 22, 2010 Share Posted November 22, 2010 +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
AdiBoy Posted November 22, 2010 Share Posted November 22, 2010 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 ) Link to comment
Static-X Posted November 22, 2010 Share Posted November 22, 2010 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
trustno1 Posted November 22, 2010 Author Share Posted November 22, 2010 Thanks guys you really helped me out Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now