dolmen62 Posted June 5, 2011 Share Posted June 5, 2011 Hi ! I'm actually working for The gamer/modder community. I want to create an automatic train system. My first problem is to put 2 train in the same rail. Link to comment
Moderators Citizen Posted June 5, 2011 Moderators Share Posted June 5, 2011 Check my video => here ; ) Link to comment
ecoxp Posted June 5, 2011 Share Posted June 5, 2011 Check my video => here ; ) Which functions did you use for attaching the train with the trailer? Link to comment
Moderators Citizen Posted June 5, 2011 Moderators Share Posted June 5, 2011 There aren't any function to do that I use invisible peds ( excepted the driver ) and all peds do the same things at the same time. It's not the most safe way ( due to the sync ) I know but it's the easier way that I found Maybe I can use getDistanceBetweenPoints3D and make a setElementVelocity to keep the trailers at the good distance. Link to comment
DiSaMe Posted June 5, 2011 Share Posted June 5, 2011 I once had made a custom tram system by remaking the path myself and using setElementPosition/Velocity to move the tram along the path. It used both San Fierro tram lines and one tram could be attached to another. Unfortunately, I lost the gamemode I had made the tram for and I have no screenshots or videos. Still, it was a simple system, and if I make something like that again, I will make the whole train system with better functionality, but I don't script on MTA much nowadays. Link to comment
dolmen62 Posted June 6, 2011 Author Share Posted June 6, 2011 I've made a little script. It work. But the train can't stop, and it's very laggy function makeTrain(source) local loco = createVehicle(537,1725.9,-1954,16) local locool = createVehicle(538,1840,-1954,16) setTrainDerailable(loco, false) setTrainDerailable(locool, false) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.21) outputChatBox("Train is here", source, 255, 255, 0) function stop (source) setTrainSpeed(locool, 0) outputChatBox("Le Train est en gare", source, 255, 255, 0) end timer = setTimer(stop, 10000, 1, source) function depart (source) setTrainSpeed(loco, 0.5) setTrainSpeed(locool, 0.5) end timer = setTimer(depart, 20000, 0, source) end addCommandHandler("traintest", makeTrain) Link to comment
Moderators Citizen Posted June 6, 2011 Moderators Share Posted June 6, 2011 Hi dolmen62, I'm french too and I wanted to know what sort of gamemode do you making ? An RPG, or something else ? There more Frenches on MTA evry months, and it's very cool 'cause sa:mp sucks and they stealing the MTA scripters --' EDIT: Code fixed works only 1 time ( tips: createMarker or createColShape at every stations then use onMarkerHit or onColShapeHit ) function makeTrain(source) loco = createVehicle(537,1725.9,-1954,16) locool = createVehicle(538,1840,-1954,16) setTrainDerailable(loco, false) setTrainDerailable(locool, false) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.21) -- why 0.21 ? outputChatBox("Train is here", source, 255, 255, 0) setTimer(stop, 10000, 1, source) setTimer(depart, 20000, 1, source) end addCommandHandler("traintest", makeTrain) function stop (source) setTrainSpeed(locool, 0) setTrainSpeed(locool, 0) outputChatBox("Le Train est en gare", source, 255, 255, 0) end function depart (source) setTrainSpeed(loco, 0.5) setTrainSpeed(locool, 0.5) end Link to comment
dolmen62 Posted June 7, 2011 Author Share Posted June 7, 2011 Thank you citizen, I will try to use it. I'm working for The Gamer/Modder Comunity. It's a Roleplay server, and Dragonofdark is the administrator. I have seen a subject in French category. I'm sure you knom him. 0.21 is for a slow assembly of the train. Because I cant place the train on the same rail. Link to comment
Moderators Citizen Posted June 7, 2011 Moderators Share Posted June 7, 2011 Yeah I know him ask your questions in this category, I'll help you in french ( if you need help of course ) Link to comment
AGENT_STEELMEAT Posted June 7, 2011 Share Posted June 7, 2011 When the train isn't streamed in on any clients - it stops moving. Therefore, you should use setElementStreamable so that it is always moving. Link to comment
dolmen62 Posted June 7, 2011 Author Share Posted June 7, 2011 Now, I can't use "addEventHandler" Link to comment
Moderators Citizen Posted June 7, 2011 Moderators Share Posted June 7, 2011 When the train isn't streamed in on any clients - it stops moving. Therefore, you should use setElementStreamable so that it is always moving. You right, I forgot that but I disabled the steam on my code ^^ Now, I can't use "addEventHandler" You created a marker or a colShape to stop the train right ? Try this: function makeTrain(source) loco = createVehicle(537,1725.9,-1954,16) locool = createVehicle(538,1840,-1954,16) setTrainDerailable(loco, false) setTrainDerailable(locool, false) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.21) -- why 0.21 ? outputChatBox("Train is here", source, 255, 255, 0) setTimer(stop, 10000, 1) setTimer(depart, 20000, 1) end addCommandHandler("traintest", makeTrain) local markerGare1 = createMarker( ... ) -- put the correct position function stop () setTrainSpeed(locool, 0) setTrainSpeed(locool, 0) if ( source ) then if ( source == markerGare1 )then -- if the marker hited is the markerGare1 outputChatBox("Le Train est en gare 1", getRootElement(), 255, 255, 0) end end setTimer(depart, 20000, 1) end addEventHandler( "onMarkerHit", getRootElement(), stop ) -- This is how to use addEventHandler function depart () setTrainSpeed(loco, 0.5) setTrainSpeed(locool, 0.5) end Link to comment
dolmen62 Posted June 7, 2011 Author Share Posted June 7, 2011 It work, but only for the second train And when I change, it don't work I've found the problem Link to comment
dolmen62 Posted June 10, 2011 Author Share Posted June 10, 2011 I nedd help ! The train don't stop on the marker, when no body is near it. Link to comment
AGENT_STEELMEAT Posted June 10, 2011 Share Posted June 10, 2011 You need to use setElementStreamable on the trains. Try it with the markers, if necessary. Link to comment
dolmen62 Posted June 10, 2011 Author Share Posted June 10, 2011 I have already do it, and it work. But When no real player is in the train, it don't stop. Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 (edited) Well, citizen help me, and he had do this for me : function makeTrain(source) loco = createVehicle(537,1725.9,-1954,16) locool = createVehicle(538,1840,-1954,16) setTrainDerailable(loco, false) setTrainDerailable(locool, false) removeStreamable( loco ) removeStreamable( locool ) local pilot1 = createPed(241,1693.38,-1959,15.6) local pilot2 = createPed(241,1711,-1959,15.6) warpPedIntoVehicle (pilot1, loco) warpPedIntoVehicle (pilot2, locool) removeStreamable( pilot1 ) removeStreamable( pilot2 ) createBlipAttachedTo(loco, 42) setTrainSpeed(loco, 0) setTrainSpeed(locool,0.203) outputChatBox("Train is here", source, 255, 255, 0) removeStreamable(markerGare2) setTimer(depart, 20000, 1) nextStation = 1 setTimer( check, 2000, 0 ) end addCommandHandler("traintest", makeTrain) local markerGare2 = createMarker(787, -1341.8, -1.8, "cylinder", 3, 255, 255, 255, 5) function stop (hitElement) outputChatBox("HIT") if not( getElementType( hitElement ) == "vehicle" ) then return end outputChatBox("c'est un vehicule") if not( getElementModel( hitElement ) == 537 ) then return end outputChatBox("et c'est la loco => Freine") setTrainSpeed(loco, 0) setTrainSpeed(locool, 0) if ( source ) then if ( source == markerGare2 )then outputChatBox("Le Train est dans Market Station.", getRootElement(), 255, 255, 0) end end setTimer(depart, 20000, 1) end addEventHandler( "onMarkerHit", getRootElement(), stop ) function depart () nextStation = nextStation+1 setTrainSpeed(loco, 1) setTrainSpeed(locool, 1) end function removeStreamable( theElement ) triggerClientEvent( "removeStreamable", getRootElement(), theElement ) end function check() local x, y, z = getElementPosition( loco ) if nextgare == 2 then if y >= -1341.8 then stop( loco ) end else if nextgare == 3 then if >= then stop( loco ) end end end end It don't work for the moment. The new system don't use marker, but the coordinates. Edited June 11, 2011 by Guest Link to comment
AGENT_STEELMEAT Posted June 11, 2011 Share Posted June 11, 2011 it's setElementStreamable, not removeStreamable - use [lua][/lua] tags! Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 No ! It's for the client only ! Link to comment
AGENT_STEELMEAT Posted June 11, 2011 Share Posted June 11, 2011 You haven't even created a clientside function for the removeStreamable event you are triggering - it will never work. Also - why are you attach onMarkerHit to the root element? Just attach it to the markers, then you don't need to check the source. Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 I've create a client side. And it work perfectly. It's because 5 stations exist. Link to comment
AGENT_STEELMEAT Posted June 11, 2011 Share Posted June 11, 2011 No - just attach and event handler to each marker, NOT the root element. Then, in your event handler, check if the hit element is the train, then if it is just set the train's speed to 0, play your message, and then set a timer for the depart function. function markerHit(hitElement, matchingDimension) if matchingDimension and hitElement == yourTrain then setTrainSpeed(hitElement, 0) outputChatBox("Your message here") setTimer(depart, 20000, 1) end end Link to comment
dolmen62 Posted June 11, 2011 Author Share Posted June 11, 2011 thank you, I will try it now ! 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