WolfPire Posted March 15, 2012 Share Posted March 15, 2012 So, i made a big project, which consists in a automatic Train System that goes alla round San andreas, i also asked for help with a friend, but no luck, so we abandon the project. So i wanna re-take it, and see if i can recieve some help on this little problem... So the problem is, that when the train touches the colsphere, it won't stop (the ped wont desaccelerate) Server ---------------------Col---------------------------------------------- LsUnity = createColSphere(1688.4095458984,-1953.9764404297,14.546875,3) LsMarket = createColSphere(783.00677490234,-1337.8107910156,-0.6554099082947,3) SfCanberry = createColSphere(-1945.2680664063,161.08346557617,161.58346557617,6) LvYB = createColSphere(1473.7739257813,2634.1916503906,11.2203125,6) LvLinden = createColSphere(2866.80078125,1245.5402832031,11.2203125,6) ---------------------------------------------------------------------- Train1 = createVehicle(538,1729.6799316406,-1951.4211425781,13.546875) Pass1 = createVehicle(437,1772,-1957,14) createBlipAttachedTo(Train1,42,2) attachElements(Pass1,Train1,0,-14,-1.1) Pilot = createPed(61,1699.9200439453,-1950.8029785156,14.1171875) setVehicleDamageProof (Pass1,true) setTrainDerailable (Train1,false) function TrainSpawn() warpPedIntoVehicle(Pilot, Train1) triggerClientEvent('streamTheTrain',root,Train1,false) triggerClientEvent('streamThePed',root,Pilot,false) setTimer(triggerClientEvent,5000,1,"accel",root, Pilot) end addEvent("onResourceDownloaded",true) addEventHandler("onResourceDownloaded",root,TrainSpawn) function TrainStopLSUnity(hitElement) if hitElement == Train1 then outputChatBox('Attention! The Train has arrived to Unity Station! (LS) You have 1 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) setElementFrozen(Pilot,true) setTimer(TrainLeaveLSUnity,10000,1) end end addEventHandler('onColShapeHit',LsUnity,TrainStopLSUnity) function TrainLeaveLSUnity() outputChatBox('The Train has left Unity Station (LS), next stop: Market Station (LS)',getRootElement(),0,200,0) setElementFrozen(Pilot,false) setTimer(triggerClientEvent,5000,1,"accel", root, Pilot) end function TrainStopLSMarket(hitElement) if hitElement == Train1 then destroyElement(Pilot) setTrainSpeed(Train1,0) Pilot = createPed(61,1699.9200439453,-1950.8029785156,14.1171875) warpPedIntoVehicle(Pilot, Train1) outputChatBox('Attention! The Train has arrived to Market Station! (LS) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) setTimer(TrainLeaveLSMarket,10000,1) end end addEventHandler('onColShapeHit',LsMarket,TrainStopLSMarket) function TrainLeaveLSMarket() outputChatBox('The Train has left Market Station, next stop: Canberry Station (SF)',getRootElement(),0,200,0) setVehicleEngineState(Train1,true) setTimer(triggerClientEvent,5000,1,"accel",root, Pilot) end function TrainStopSfCanberry(hitElement) if hitElement == Train1 then setTrainSpeed(Train,0) outputChatBox('Attention! The Train has arrived to Caberry Station! (SF) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) setVehicleEngineState(Train1,false) setTimer(TrainLeaveSfCanberry,10000,1) end end addEventHandler('onColShapeHit',SfCanberry,TrainStopSfCanberry) function TrainLeaveSfCanberry() outputChatBox('The Train has left Canberry Station, next stop: Yellow Bell Station (LV)',getRootElement(),0,200,0) setVehicleEngineState(Train1,true) setTimer(triggerClientEvent,5000,1,"accel",root, Pilot) end function TrainStopLVYellowBell(hitElement) if hitElement == Train1 then setTrainSpeed(Train,0) outputChatBox('Attention! The Train has arrived to Yellow Bell Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) destroyElement(Pilot) local Pilot = createPed(61,1699.9200439453,-1950.8029785156,14.1171875) setVehicleEngineState(Train1,false) setTimer(TrainLeaveLvYellowBell,10000,1) end end addEventHandler('onColShapeHit',LvYB,TrainStopLVYellowBell) function TrainLeaveLvYellowBell() outputChatBox('The Train has left Yellow Bell Station, next stop: Linden Station (LV)',getRootElement(),0,200,0) setVehicleEngineState(Train1,true) setTimer(triggerClientEvent,5000,1, "accel",root, Pilot) end function TrainStopLVLinden(hitElement) if hitElement == Train1 then setTrainSpeed(Train,0) outputChatBox('Attention! The Train has arrived to Linden Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) destroyElement(Pilot) local Pilot = createPed(61,1699.9200439453,-1950.8029785156,14.1171875) setVehicleEngineState(Train1,false) setTimer(TrainLeaveLvYellowBell,10000,1) end end addEventHandler('onColShapeHit',LvLinden,TrainStopLVLinden) function TrainLeaveLvLinden() outputChatBox('The Train has left Yellow Bell Station, next stop: Unity Station (LS)',getRootElement(),0,200,0) setVehicleEngineState(Train1,true) setTimer(triggerClientEvent,5000,1, "accel",root, Pilot) end Client addEvent('accel', true) addEventHandler('accel', root, function(Pilot) setPedControlState(Pilot,"accelerate",true) end ) addEvent('stop', true) addEventHandler('stop', root, function(Pilot) setPedControlState(Pilot,"brake_reverse",true) end ) addEventHandler("onClientResourceStart",resourceRoot, function() triggerServerEvent("onResourceDownloaded",getLocalPlayer()) end ) addEvent('streamTheTrain', true) addEventHandler('streamTheTrain', root, function(Train1) setElementStreamable ( Train1, false ) end ) addEvent('streamThePed', true) addEventHandler('streamThePed', root, function(Pilot) setElementStreamable ( Pilot, false ) end ) Pardon me if any error you find, this code is old. Link to comment
WolfPire Posted March 15, 2012 Author Share Posted March 15, 2012 Check conditions. which? Link to comment
Moderators IIYAMA Posted March 15, 2012 Moderators Share Posted March 15, 2012 outputChatBox('Attention! The Train has arrived to Linden Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) If your outputchatbox works than you maybe.. Maybe you can try the vehicle handling ? https://wiki.multitheftauto.com/wiki/SetElementVelocity So the train wont be able to give more power and if the train enters the station you can freeze it. Link to comment
WolfPire Posted March 15, 2012 Author Share Posted March 15, 2012 outputChatBox('Attention! The Train has arrived to Linden Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',getRootElement(),200,0,0) If your outputchatbox works than you maybe.. Maybe you can try the vehicle handling ? https://wiki.multitheftauto.com/wiki/SetElementVelocity So the train wont be able to give more power and if the train enters the station you can freeze it. Hi there! IIYAMA-san! I tried to freeze it with setElementVelocity before, it didn't seem to work D: But thank you! =) And no sadly the outputChatBox doesn't trigger neither so i think it's a condition problem. Link to comment
Absence2 Posted March 15, 2012 Share Posted March 15, 2012 I'm not trying to disturb or spam or anything like that but am I the only one who gets a skype phone number from this line? Uhm, Solomon Islands. Just curious LsMarket = createColSphere(783.00677490234,-1337.8107910156,-0.6554099082947,3) Link to comment
Castillo Posted March 15, 2012 Share Posted March 15, 2012 I think the train only stops if a player is on it, because when I got into the train, we stopped at Market Station. Link to comment
WolfPire Posted March 15, 2012 Author Share Posted March 15, 2012 I think the train only stops if a player is on it, because when I got into the train, we stopped at Market Station. Hmmm, isn't there a way for the colshape to detect the Train Vehicle element? Link to comment
Castillo Posted March 15, 2012 Share Posted March 15, 2012 That's not the problem, I think it's a sync problem, the train is not synchronized if a player isn't near. Link to comment
WolfPire Posted March 15, 2012 Author Share Posted March 15, 2012 That's not the problem, I think it's a sync problem, the train is not synchronized if a player isn't near. Weird, cus' im in the train station as for when the train arrives, near the colshapes, but i think i'll have to set colshapes streamables like i did with the train and pilot... don't i? Link to comment
WolfPire Posted April 2, 2012 Author Share Posted April 2, 2012 So ok, i had to RE-DO the whole code. It stops in the marked station thanks to an object which is literally attached to it. The problem now is "Sync", some players found the train "choppy" or "not moving at all". So, i was wondering if you guys could give me a hand. Server function TrainSpawn() if not Train1 then Train1 = createVehicle(538,1729.6799316406,-1951.4211425781,13.546875) Pass1 = createVehicle(437,1772,-1957,14) createBlipAttachedTo(Train1,42,2) attachElements(Pass1,Train1,0,-14,-1.1) Pilot = createPed(61,1699.9200439453,-1950.8029785156,14.1171875) setVehicleDamageProof (Pass1,true) setTrainDerailable (Train1,false) warpPedIntoVehicle(Pilot, Train1) triggerClientEvent("manageStreaming", root, Train1, Pilot, Pass1) player = getElementsByType("player") for i,v in ipairs(player) do setElementSyncer ( Train1, v ) setElementSyncer ( Pass1, v ) setElementSyncer ( Pilot, v ) end end end addEvent("onResourceDownloaded",true) addEventHandler("onResourceDownloaded",root,TrainSpawn) Client ---------------------Col---------------------------------------------- LsUnity = createColSphere(1787,-1953.9764404297,14.546875,3) LsMarket = createColSphere(919,-1467.8107910156,-2.0554099082947,3) SfCanberry = createColSphere(-1944.2680664063,40.08346557617,26.58346557617,3) LvYB = createColSphere(1224.7739257813,2633.1916503906,11.2203125,3) LvLinden = createColSphere(2866.80078125,1481.5402832031,11.2203125,3) ---------------------------------------------------------------------- addEvent("manageStreaming", true) addEventHandler("manageStreaming", root, function(Train1, Pilot, Pass1) setElementStreamable ( Train1, false ) setElementStreamable ( Pass1, false ) setElementStreamable ( Pilot, false ) Train = Train1 Pilot2 = Pilot setTimer(accel, 5000, 1) setTimer(det, 50, 1) end ) Det = createObject(1337, 1772,-1957,14) function TrainStopLSUnity(hitElement) if hitElement == Det then outputChatBox('Attention! The Train has arrived to Unity Station! (LS) You have 1 minutes to buy a ticket before the train leaves!',200,0,0) setTimer(stop, 50, 1) setTimer(TrainLeaveLSUnity,10000,1) end end addEventHandler('onClientColShapeHit',LsUnity,TrainStopLSUnity) function TrainLeaveLSUnity() outputChatBox('The Train has left Unity Station (LS), next stop: Market Station (LS)',0,200,0) setPedControlState(Pilot2,"brake_reverse",false) setTimer(accel, 50, 1) end function TrainStopLSMarket(hitElement) if hitElement == Det then outputChatBox('Attention! The Train has arrived to Market Station! (LS) You have 5 minutes to buy a ticket before the train leaves!',200,0,0) setTimer(stop, 5000, 1) setTimer(setTrainSpeed, 3500, 1, Train, 0) setTimer(TrainLeaveLSMarket,5000,1) end end addEventHandler('onClientColShapeHit',LsMarket,TrainStopLSMarket) function TrainLeaveLSMarket() outputChatBox('The Train has left Market Station, next stop: Canberry Station (SF)',0,200,0) setPedControlState(Pilot2,"brake_reverse",false) setTimer(accel, 5000, 1) end function TrainStopSfCanberry(hitElement) if hitElement == Det then outputChatBox('Attention! The Train has arrived to Caberry Station! (SF) You have 5 minutes to buy a ticket before the train leaves!',200,0,0) setTimer(stop, 5000, 1) setTimer(TrainLeaveSfCanberry,5000,1) end end addEventHandler('onClientColShapeHit',SfCanberry,TrainStopSfCanberry) function TrainLeaveSfCanberry() outputChatBox('The Train has left Canberry Station, next stop: Yellow Bell Station (LV)',0,200,0) setPedControlState(Pilot2,"brake_reverse",false) setTimer(accel, 5000, 1) end function TrainStopLVYellowBell(hitElement) if hitElement == Det then outputChatBox('Attention! The Train has arrived to Yellow Bell Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',200,0,0) setTimer(stop, 5000, 1) setTimer(TrainLeaveLvYellowBell,5000,1) end end addEventHandler('onClientColShapeHit',LvYB,TrainStopLVYellowBell) function TrainLeaveLvYellowBell() outputChatBox('The Train has left Yellow Bell Station, next stop: Linden Station (LV)',0,200,0) setPedControlState(Pilot2,"brake_reverse",false) setTimer(accel, 5000, 1) end function TrainStopLVLinden(hitElement) if hitElement == Det then outputChatBox('Attention! The Train has arrived to Linden Station! (LV) You have 5 minutes to buy a ticket before the train leaves!',200,0,0) setTimer(stop, 5000, 1) setTimer(TrainLeaveLvYellowBell,5000,1) end end addEventHandler('onClientColShapeHit',LvLinden,TrainStopLVLinden) function TrainLeaveLvLinden() outputChatBox('The Train has left Yellow Bell Station, next stop: Unity Station (LS)',0,200,0) setPedControlState(Pilot2,"brake_reverse",false) setTimer(accel, 9000, 1) end function det() if not hand then hand = addEventHandler("onClientRender", root, detz) outputChatBox("Yes") end end function detz() dx, dy, dz = getElementPosition(Train) drx, dry, drz = getElementRotation(Train) setElementPosition( Det, dx, dy, dz ) setElementRotation( Det, drx, dry, drz ) end function accel() setPedControlState(Pilot2,"accelerate",true) end function stop() setPedControlState(Pilot2,"brake_reverse",true) end addEventHandler("onClientResourceStart",resourceRoot, <--- This could be the reason, i'm not sure. function() triggerServerEvent("onResourceDownloaded", root) end ) 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