Jump to content

[Help] Trailor to vehicle


BieHDC

Recommended Posts

You can use attackTrailerToVehicle. The trailer is NOT being created the same time as the vehicle the player is in. So you can do something like this;

function attach( thePlayer ) 
    local v = getPedOccupiedVehicle( thePlayer ); 
    local x, y, z = getElementPosition ( thePlayer ); 
    local theTrailer = createVehicle ( , x, y, z+15 ); 
    AttachTrailerToVehicle ( v, theTrailer ); 
end 

Trigger the event at the position in your race gamemode where the players are getting warped into their vehicle's. Dont forget to give the player as a parameter.

Link to comment

Well, the race gamemode has a start too. I know its hard to believe, mind = blown. But it does have a start. Where everone gets spawned and received a vehicle. At that point, add a trigger to my command with a parameter or the player, because I'm not sure if the player is one of the following;

source 
localPlayer 
getLocalPlayer() 
thePlayer 

Or any costum made one, so just add a trigger to the function like so;

triggerEvent("attach", , ); 

Link to comment

doesnt work

5: argoment 5 got none

6: nil value

i think i dont get z pos

function attach( thePlayer ) 
    local thePlayer = getLocalPlayer() 
    local v = getPedOccupiedVehicle( thePlayer ); 
    local x, y, z = getElementPosition( thePlayer ); 
    local theTrailer = createVehicle( 450, x, y, z+15 ); --+15 
    AttachTrailerToVehicle( v, theTrailer ); 
end 
addCommandHandler("attc", attach) 
  

Link to comment

try: ((Not tested))

function attach( thePlayer ) 
    local v = getPedOccupiedVehicle( localPlayer); 
    local x, y, z = getElementPosition( localPlayer); 
    local theTrailer = createVehicle( 450, x, y, z+15 ); --+15 
    attachTrailerToVehicle( v, theTrailer ); 
end 
addCommandHandler("attc", attach) 
  

Please remember, Lua is very case-sensitive.

Link to comment

This is a server side script? if so, then "localPlayer" should be "thePlayer".

function attach ( thePlayer ) 
    local v = getPedOccupiedVehicle ( thePlayer ); 
    local x, y, z = getElementPosition ( thePlayer ); 
    local theTrailer = createVehicle ( 450, x, y, z+15 ); --+15 
    attachTrailerToVehicle ( v, theTrailer ); 
end 
addCommandHandler ( "attc", attach ) 

Link to comment

It works, but only if the truck dont look to south.

Its so if the truck looks to north, east or west if get connected, but if it looks to south if dont work, because it would be "on" the vehicle.

So the truck has to have the same rotation as the trailer.

You understand?

i will try to include rotation and if it doesnt work i will post it in here

edit: i dont thought to get it work on the first try^i am getting better in scripting yey ^^

here is the code and i will it also release in community^should i add your credits?

--serverside 
function attach ( thePlayer ) 
        local v = getPedOccupiedVehicle ( thePlayer ); 
        local x, y, z = getElementPosition ( thePlayer ); 
        local ra, rb, rc = getElementRotation ( thePlayer ); 
        local theTrailer = createVehicle ( 450, x, y, z+15, ra, rb, rc ); 
        attachTrailerToVehicle ( v, theTrailer ); 
    end 
    addCommandHandler ( "attc", attach ) 
  

edit2: only one thing cant be fixed because there is no check if a trailor is already attached, but only set the createVehicle from +15 to -9999 or somewhere it never would be find^

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