Jump to content

Automatic Train System


Recommended Posts

  • Replies 78
  • Created
  • Last Reply

Top Posters In This Topic

  • Moderators

There aren't any function to do that :mrgreen:

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

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

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

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

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

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 by Guest
Link to comment

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

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