Jump to content

Train Speed Limit


CodX

Recommended Posts

Hello ! I have tried to search google how to set the speed limit on a train but I have not found anything.
Can you tell me please if possible?
If possible, can you tell me how could I set the limit to 160 km / h?

P.S: Excuse me if I did not write correctly.

Edited by CodX
Link to comment

I added this to the scripts that create trains:   
 

    [9] = { 
        vehicles = { 
            { 538, "Tren" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
                setTrainDerailable(myTrain, false),
                executeCommandHandler("speed", source),
                setTrainSpeed(myTrain, 1),
        spawnLocation = { 2864.8310546875, 1291.5625, 10.8203125, 356, 9 },

I tested it, not giving errors or warnings, but it does not work (exceeds 160 km / h).
We also added scripts with "getTrainSpeed".

Edited by CodX
Link to comment

Isn't posible to change that varbiable from "setTrainDeraible" in 'spawnLocation' ? I've tried but it didn't work..

How can i change the variable, i can't add a local variable in that script, he give me error if i do that.

Edited by CodX
Link to comment

I see right now but i can't add a local variable because he give me error and i can't create the train separated from that script because then he will not be spawned.

How can i put a local variable if i can't ?

 

P.S: I'm beginner in LUA.

Edited by CodX
Link to comment

what errors

    [9] = { 
        vehicles = { 
            { 538, "Tren" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
                local myTrain = getPedOccupiedVehicle(source)
                setTrainDerailable(myTrain, false),
                executeCommandHandler("speed", source),
                setTrainSpeed(myTrain, 1),
        spawnLocation = { 2864.8310546875, 1291.5625, 10.8203125, 356, 9 },

 

Link to comment

ERROR: Loading script failed: job-system/jobClient.lua:61: unexpected symbol near 'local'
This is the script:

    [9] = { 
        vehicles = { 
            { 538, "Tren" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
                local tren = spawnLocation={ 2864.8310546875, 1291.5625, 10.8203125, 356, 9 },
        setTrainDerailable(tren, false),
        outputChatBox("Test.", source, 255, 255, 0),
               setTrainSpeed(tren, 1),
Link to comment
	[9] = { 
		vehicles = { 
			{ 538, "Tren" },
		},
		vehiclesColor = { 6, 6, 6, 6 },
                local tren = createVehicle(2864.8310546875, 1291.5625, 10.8203125,13),
                setTrainDerailable(tren, false),
                outputChatBox("Test.", source, 255, 255, 0),
                warpPedIntoVehicle(source, tren),
                setTrainSpeed(tren, 1),

Now the error is:

ERROR: Loading script failed: job-system/jobClient.lua:61: unexpected symbol near `

Edited by CodX
Link to comment
  • Moderators

You guys can't do that like that. This is a table WTF

	[9] = { 
		vehicles = { 
			{ 538, "Tren" },
		},
		vehiclesColor = { 6, 6, 6, 6 },
  		tren = (function ()
            local tren = createVehicle(2864.8310546875, 1291.5625, 10.8203125,13)
            setTrainDerailable(tren, false)
            outputChatBox("Test.", source, 255, 255, 0)
           	warpPedIntoVehicle(source, tren)
            setTrainSpeed(tren, 1)
			return tren
    	end)(),

  	

 

 

Link to comment

When i create a train he give me this error:

ERROR: job-system\jobClient.lua:126 : attempt to index local 'thing' (a nil value)

 

At that line the script is:

		local x, y, z, theVehicleRoation, theVehicleJob = thing[1], thing[2], thing[3], thing[4], thing[5]

 

 

P.S: Sorry, but i beginner in LUA.

Link to comment

Isn't a table, i think. This is all script:

vehiclesWindow = guiCreateWindow(395,237,241,413,"Vehicule",false)
vehiclesGrid = guiCreateGridList(9,26,221,307,false,vehiclesWindow)
guiGridListSetSelectionMode(vehiclesGrid,0)
spawnVehicleButton = guiCreateButton(9,337,220,30,"Creează Vehicul",false,vehiclesWindow)
closeWindowButton = guiCreateButton(9,373,220,30,"Ieși din Meniu",false,vehiclesWindow)
guiGridListSetSortingEnabled ( vehiclesGrid, false )
vehicleName = guiGridListAddColumn( vehiclesGrid, " Numele Vehiculelor:", 0.80 )
local screenW,screenH=guiGetScreenSize()
local windowW,windowH=guiGetSize(vehiclesWindow,false)
local x,y = (screenW-windowW)/2,(screenH-windowH)/2
guiSetPosition(vehiclesWindow,x,y,false)
guiWindowSetMovable (vehiclesWindow, true)
guiWindowSetSizable (vehiclesWindow, false)
guiSetVisible (vehiclesWindow, false)

local customPanels = { 
    [-2] = { 
        vehicles = { 
            { 410, "Scoala Auto - Manana" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { -2068.58984375, -83.4248046875, 35.1640625, 182, -1 },
    },
    [-1] = { 
        vehicles = { 
            { 481, "BMX" },
            { 510, "Mountain Bike" },
            { 509, "Bike" }, 
        },
        vehiclesColor = { 1, 1, 0, 0 },
        spawnLocation = { -1988.271484375, 170.7890625, 27.5390625, 2, -1 },
        rentCost = 50
    },
    [2] = { 
        vehicles = { 
            { 420, "Taxi" },
            { 438, "Cabbie" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { 2125.3466796875, 2064.65625, 10.398958206177, 180, 2 },
    },
    [3] = { 
        vehicles = { 
            { 431, "Autobuz" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { 2225.072265625, 1255.357421875, 10.766926765442, 180, 3 },
    },
    [4] = { 
        vehicles = { 
            { 574, "MaÈ™ină de Curățat" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { 2040.244140625, 1513.951171875, 10.671875, 178, 4 },
    },
    [9] = { 
        vehicles = { 
            { 538, "Tren" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
          tren = (function ()
                local tren = createVehicle(2864.8310546875, 1291.5625, 10.8203125,13)
                setTrainDerailable(tren, false)
                outputChatBox("Test.", source, 255, 255, 0)
               warpPedIntoVehicle(source, tren)
                setTrainSpeed(tren, 1)
            return tren
                end)(),
    },
    [20] = { 
        vehicles = { 
            { 453, "Vas Petrolier Mic" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { 2655.3505859375, -2468.4619140625, 4.4452381134033, 180, 9 },
        },
    [21] = { 
        vehicles = { 
            { 511, "Avion de Transport" },
        },
        vehiclesColor = { 6, 6, 6, 6 },
        spawnLocation = { 389.9248046875, 2498.556640625, 16.484375, 90, 9 },
    },
}
local number = 0

function showCustomPanel ( nr )
    nr = tonumber(nr)
    if not nr then return end
    if nr > 0 then
        local job = getElementData(getLocalPlayer(),"job")
        if job ~= nr then
            showJobMenu ( nr )
            return
        end
    end
    number = nr
    local vehiclesList = customPanels[nr]["vehicles"]
    guiGridListClear ( vehiclesGrid )
    for i, v in pairs( vehiclesList ) do 
        local row = guiGridListAddRow ( vehiclesGrid )
        guiGridListSetItemText ( vehiclesGrid, row, vehicleName, tostring(v[2]), false, false )
        guiGridListSetItemData ( vehiclesGrid, row, vehicleName, tonumber(v[1]) )        
    end
    guiSetVisible (vehiclesWindow, true)
    showCursor(true,true)
end
addEvent("showRentPanel", true)
addEventHandler("showRentPanel", root, showCustomPanel)

function onCloseWindow()
    guiSetVisible(vehiclesWindow, false)
    showCursor(false,false)
    guiGridListClear ( vehiclesGrid )
end
addEventHandler("onClientGUIClick", closeWindowButton, onCloseWindow, false)

function spawnTheVehicle ()
    local selectedVehicle = guiGridListGetItemText ( vehiclesGrid, guiGridListGetSelectedItem ( vehiclesGrid ), 1 )
    if selectedVehicle == "" or selectedVehicle == " " then
        outputChatBox("Nu ai selectat nici un vehicul!", 225 ,0 ,0)
    else
        local selectedRow, selectedColumn = guiGridListGetSelectedItem(vehiclesGrid)
        local theVehicleID = guiGridListGetItemData ( vehiclesGrid, selectedRow, selectedColumn )
        local thing = customPanels[number]["spawnLocation"]
        local x, y, z, theVehicleRoation, theVehicleJob = thing[1], thing[2], thing[3], thing[4], thing[5]
        local v = customPanels[number]["vehiclesColor"]
        local c1, c2, c3, c4 = v[1], v[2], v[3], v[4]
        local rentCost = customPanels[number]["rentCost"]
        local cost = 0
        if rentCost then
            cost = rentCost
        end
        triggerServerEvent("spawnVehicle", localPlayer, localPlayer, x, y, z, theVehicleID, c1, c2, c3, c4, theVehicleRoation, theVehicleJob, false, cost)
        guiSetVisible (vehiclesWindow, false)
        showCursor(false,false)
        guiGridListClear ( vehiclesGrid )
    end
end
addEventHandler("onClientGUIClick", spawnVehicleButton, spawnTheVehicle, false)

wEmployment, jobList, bAcceptJob, bCancel = nil
local job, number = 0, 0
function showJobMenu ( jobID )
    job = tonumber(jobID)
    local realJob = getElementData(getLocalPlayer(),"job")
    if realJob == job then
        local jobsTable = customPanels[job]
        if jobsTable then
            showCustomPanel ( job )
            return
        end
    end
    if jobID and jobs[job] then
        local currentJob = getElementData(getLocalPlayer(), "job")    
        local jobName = jobs[job][1]
        local jobDescription = jobs[job][2]
        local width, height = 300, 400
        local scrWidth, scrHeight = guiGetScreenSize()
        local x = scrWidth/2 - (width/2)
        local y = scrHeight/2 - (height/2)    
        wEmployment = guiCreateWindow(x, y, width, height, "Slujba de ".. jobName, false)    
        if (currentJob>0) then
            bAcceptJob = guiCreateButton(0.05, 0.85, 0.45, 0.1, "Demisionează", true, wEmployment)
            addEventHandler("onClientGUIClick", bAcceptJob, quitTheJob)
            jobList = guiCreateMemo(0.05, 0.05, 0.9, 0.7, jobs[0][2], true, wEmployment)
        else
            bAcceptJob = guiCreateButton(0.05, 0.85, 0.45, 0.1, "Acceptă slujba", true, wEmployment)
            jobList = guiCreateMemo(0.05, 0.05, 0.9, 0.8, jobDescription, true, wEmployment)
            addEventHandler("onClientGUIClick", bAcceptJob, acceptJob)
        end        
        guiMemoSetReadOnly( jobList, true )
        bCancel = guiCreateButton(0.5, 0.85, 0.45, 0.1, "IeÈ™i", true, wEmployment)    
        showCursor(true)    
        addEventHandler("onClientGUIClick", bCancel, cancelJob)
    end
end
addEvent("showJob", true)
addEventHandler("showJob", getRootElement(), showJobMenu)

function closeMenu ()
    destroyElement(jobList)
    destroyElement(bAcceptJob)
    destroyElement(bCancel)
    destroyElement(wEmployment)
    wEmployment, jobList, bAcceptJob, bCancel = nil, nil, nil, nil
    showCursor(false)
end

function startClientJob ( job )
    if (job == 1) then
        displayTruckerJob()
    elseif (job == 2) then
        displayTaxiJob()
    elseif  (job == 3) then
        displayBusJob()        
    elseif  (job == 4) then
        displaySweeperJob()            
    elseif (job == 5) then
        --displayMechanicJob()
        displayPizzaJob()
    elseif (job == 6) then
        --displayLocksmithJob()
    elseif (job == 7) then
        displayTruckerJob()
    elseif (job == 8) then
        displayFishJob()
    elseif (job == 9) then
        displaytramJob()
        elseif (job == 20) then
                displayBoatJob()
        elseif (job == 21) then
                displayAirJob()
    end
end

function acceptJob ( )
    if job == 1 or job == 2 or job == 3 then
        local carlicense = getElementData(getLocalPlayer(), "license.car")
        if carlicense then else 
            outputChatBox("Ai nevoie de o licență de condus pentru a te angaja la această slujbă.", 255, 0, 0)
            return
        end
    end
    triggerServerEvent("acceptJob", getLocalPlayer(), job)        
    outputChatBox("Ai fost angajat ca " .. jobs[job][1]..".", 0, 255, 0)
    startClientJob ( job )
    closeMenu()
end

function quitTheJob()
    triggerServerEvent("quitJob", getLocalPlayer(), getLocalPlayer())        
    closeMenu()
end

function cancelJob(button, state)
    if (source==bCancel) and (button=="left") then
        closeMenu()
    end
end

 

Link to comment

So, i've make this:

function getPlayersTrainSpeed ( source, command )
	if ( isPedInVehicle ( source ) ) then
	local veh = getPedOccupiedVehicle ( source )
		if ( getVehicleType ( veh ) == "Train" ) then
			local speed = getTrainSpeed ( veh )
			outputChatBox ( "You are travelling at a speed of " .. speed, source, 255, 0, 0 )
		else
			outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 )
		end
	else
		outputChatBox ( "You must be in a train to use this command.", source, 255, 0, 0 )
	end
end
addEventHandler ( "onClientRender", root, getPlayersTrainSpeed )

But i don't know to solve that problem with train creator.

This is picture when i try to create a train from NPC.

Link to comment
  • Moderators

function getPlayersTrainSpeed ( source, command )

@CodX Where do you see parameters here:

https://wiki.multitheftauto.com/wiki/OnClientRender

?

 

I don't see them, because there are none. So you can't add them there.

 

 

Use localPlayer instead of source, without parameters.

 

outputChatBox 

Doesn't require a player to send to, pls check the syntax.

 

Edited by IIYAMA
Link to comment

I've modify:

function getPlayersTrainSpeed ()
	if ( isPedInVehicle ( localPlayer ) ) then
	local veh = getPedOccupiedVehicle ( localPlayer )
		if ( getVehicleType ( veh ) == "Train" ) then
			local speed = getTrainSpeed ( veh )
			outputChatBox ( "Viteza ta: " .. speed, localPlayer , 255, 0, 0 )
                        setTrainDerailable(tren, false)
                        outputChatBox("Test.", localPlayer , 255, 255, 0)
           	        warpPedIntoVehicle(localPlayer , tren)
                        setTrainSpeed(tren, 1)
		else
		end
	else
		outputChatBox ( "You must be in a train to use this command.", localPlayer , 255, 0, 0 )
	end
end
addEventHandler ( "onClientRender", root, getPlayersTrainSpeed )

 

 

But i can't make a train..

Is this picture you can see the error (i don't know how to solve it, can you help me please):

http://imgur.com/a/7BEJq

Link to comment
function getPlayersTrainSpeed ()
	if ( isPedInVehicle ( localPlayer ) ) then
	local veh = getPedOccupiedVehicle ( localPlayer )
		if ( getVehicleType ( veh ) == "Train" ) then
			local speed = getTrainSpeed ( veh )
			outputChatBox ( "Viteza ta: " .. speed, 255, 0, 0 )
                        setTrainDerailable(tren, false)
                        outputChatBox("Test.",  255, 255, 0)
           	        warpPedIntoVehicle(localPlayer , tren)
                        setTrainSpeed(tren, 1)
		else
		end
	else
		outputChatBox ( "You must be in a train to use this command.", localPlayer , 255, 0, 0 )
	end
end
addEventHandler ( "onClientRender", root, getPlayersTrainSpeed )

 

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