Aron800 Posted July 23, 2010 Share Posted July 23, 2010 Hello, I want to make a train in my server but it doesn't work.. My code in: train_server.lua engineer=createPed(227,1479,2669,3) train=createVehicle(537,1479,2669,3) setTrainDerailable(train, false) warpPedIntoVehicle(engineer,train) triggerClientEvent ( "driveTrain", getRootElement()) My code in: train_client.lua function driveTrain() Engineer=getVehicleOccupant(getPedOccupiedVehicle(getLocalPlayer())) setPedControlState(Engineer,"accelerate",true) end addEvent( "driveTrain", true ) addEventHandler( "driveTrain", getRootElement(), driveTrain ) The Ped will come in the train with this script but the train doesn't go. So does anyone know what's wrong with this script Aron Link to comment
Callum Posted July 23, 2010 Share Posted July 23, 2010 Are you a passenger in the train of which the ped should drive? In your client-side script you are declaring the Engineer as the driver of the vehicle you're in. Link to comment
Aron800 Posted July 23, 2010 Author Share Posted July 23, 2010 Well being a passenger i will add later but how can i declare the engineer on the client-side script and make it work? Link to comment
50p Posted July 23, 2010 Share Posted July 23, 2010 Do you get any error/warning messages? I'm pretty sure you do about event not being added on client's side. I would NOT recommend creating stuff outside a function. Create ped and train inside onResourceStart event and/or triggerClientEvent after player has downloaded the resource. Link to comment
Aron800 Posted July 23, 2010 Author Share Posted July 23, 2010 Im not getting an error and that is a good idea but how can i make it work? Link to comment
DiSaMe Posted July 23, 2010 Share Posted July 23, 2010 Try this: Server: function createTrainAndEngineer() engineer=createPed(227,1479,2669,3) setElementID(engineer,"engineer") train=createVehicle(537,1479,2669,3) setTrainDerailable(train, false) warpPedIntoVehicle(engineer,train) end addEventHandler("onResourceStart",getResourceRootElement(),createTrainAndEngineer) Client: function driveTrain() engineer=getElementByID("engineer") setPedControlState(engineer,"accelerate",true) end addEventHandler("onClientResourceStart",getResourceRootElement(),driveTrain) As you can see, the server creates train and engineer when the resource has started, not when it's starting. Engineer element has ID "engineer" which is used by client to get the element. Link to comment
Aron800 Posted July 23, 2010 Author Share Posted July 23, 2010 It still doesn't work but i found what is wrong setPedControlState(engineer,"accelerate",true) When i try to run the code with runcode it returns: Aron executed command: setPedControlState(engineer,"accelerate",true) Error: [string "return setPedControlState(engineer,"acceler..."]:1: attempt to call global 'setPedControlState' (a nil value) But i dont know how i can make this work. That setPedControlState works if i make a pilot so maybe it does not work on a train? Link to comment
DiSaMe Posted July 23, 2010 Share Posted July 23, 2010 The only thing you found out on runcode is that setPedControlState is a clientside-only function. Yes, setPedControlState doesn't work on trains. It only works on peds. But engineer is a ped, not a train Link to comment
Aron800 Posted July 24, 2010 Author Share Posted July 24, 2010 I know but if i let engineer accelerate then the train needs to be moving. But that doesn't work... Link to comment
Aron800 Posted July 25, 2010 Author Share Posted July 25, 2010 Does anyone know how i can let it work? Link to comment
50p Posted July 25, 2010 Share Posted July 25, 2010 I would suggest you leave this script somewhere in your mind only.. Trains have never worked properly and they have to be synced by at least 1 player. 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