Stijger Posted February 11, 2012 Share Posted February 11, 2012 Hey guys, Quick question. Is there any chance you can put an offset to the attachTrailerToVehicle function like in the attachElements function. Would be awesome to like attach a trailer to another without it being attached weird to the bottom of the other trailer. Like it is now. Code used: function attachTrailer ( theVehicle, seat, jacked ) if ( getElementModel ( theVehicle ) == 515 ) then -- if its a roadtrain trailer = createVehicle ( 435, 305, 1855, 18 ) -- create a trailer trailer2 = createVehicle ( 435, 305, 1855, 18 ) -- create another trailer attachTrailerToVehicle (theVehicle, trailer) -- Attach trailer to car attachTrailerToVehicle (trailer, trailer2) -- Attach trailer2 to trailer outputChatBox("Trailers attached, don't lose it or you blow up!") end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), attachTrailer ) Link to comment
Stijger Posted February 13, 2012 Author Share Posted February 13, 2012 Okey, found one solution. I use a different vehicle (a baggagecar in this case) and use the function attachElements (with offsets) to attach this to the trailer. And the other trailer I attach to this baggage so it's nice and straight. Used Code function attachTrailer ( theVehicle, seat, jacked ) if ( getElementModel ( theVehicle ) == 515 ) then -- if its a roadtrain trailer = createVehicle ( 591, 1990, -2390, 18 ) -- create a trailer veh2 = createVehicle (485, 1990, -2392, 18 ) -- create tugtrailer for coupling setVehicleWheelStates ( veh2, 2, 2, 2, 2) trailer2 = createVehicle ( 591, 1990, -2395, 18 ) -- create a trailer veh3 = createVehicle (485, 1990, -2397, 18 ) -- create tugtrailer for coupling setVehicleWheelStates ( veh3, 2, 2, 2, 2) trailer3 = createVehicle ( 435, 1990, -2400, 18 ) -- create a trailer setTimer (attachTrailerToVehicle, 5000, 1, theVehicle, trailer) -- Attach trailer to car after 5 sec setTimer (attachElements, 6000, 1, veh2, trailer, 0, -1.1, 0.1) -- Attach trailer to car after 7.5 sec setTimer (attachTrailerToVehicle, 7000, 1, veh2, trailer2) -- Attach trailer to car after 10 sec setTimer (attachElements, 8500, 1, veh3, trailer2, 0, -1.1, 0.1) -- Attach trailer to car after 12.5 sec setTimer (attachTrailerToVehicle, 10000, 1, veh3, trailer3) -- Attach trailer to car after 15 sec detachTrailerFromVehicle(theVehicle, trailer2) --detach the newly attached trailer detachTrailerFromVehicle(theVehicle, trailer3) --detach the newly attached trailer detachTrailerFromVehicle(theVehicle, veh2) --detach the newly attached trailer detachTrailerFromVehicle(theVehicle, veh3) --detach the newly attached trailer end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), attachTrailer ) function textTrailer () outputChatBox("A couple of trailers will be attached") end addEventHandler ( "onResourceStart", getRootElement(), textTrailer ) So that code works, but i wanted it to start when the countdown started, so I wrote this: --------------Multiple Trailers---------------- -----------------By: Stijger------------------- local trailer = createVehicle ( 591, 1990, -2390, 15 ) -- create a trailer local veh2 = createVehicle (485, 1990, -2391.1, 15.1 ) -- create bagagecar for coupling trailers setElementAlpha ( veh2, 0) --make the baggagecar invisble local trailer2 = createVehicle ( 591, 1990, -2400, 15 ) -- create a trailer local veh3 = createVehicle (485, 1990, -2401.1, 15.1 ) -- create bagagecar for coupling trailers setElementAlpha ( veh3, 0) --make the baggagecar invisble local trailer3 = createVehicle ( 435, 1990, -2410, 15 ) -- create a trailer addEvent('onRaceStateChanging', true) addEventHandler('onRaceStateChanging', getRootElement(), function(newstate, oldstate) if newstate == 'GridCountdown' then --start timer attaching at start countdown outputChatBox("A couple of trailers will be attached", getRootElement(), 255, 0 , 0) for _,veh in pairs(getElementsByType("vehicle")) do if getElementModel(veh) == 515 then -- if its a roadtrain setTimer (attachTrailerToVehicle, 1500, 1, veh, trailer) -- Attach trailer to roadtrain after 1.5 sec setTimer (attachElements, 2000, 1, veh2, trailer, 0, -1.1, 0.1) -- Attach trailer to car after 2 sec setTimer (attachTrailerToVehicle, 2500, 1, veh2, trailer2) -- Attach trailer to car after 2.5 sec setTimer (attachElements, 3000, 1, veh3, trailer2, 0, -1.1, 0.1) -- Attach trailer to car after 3 sec setTimer (attachTrailerToVehicle, 3500, 1, veh3, trailer3) -- Attach trailer to car after 3.5 sec end end end end ) And that kinda works, but only for the player that enters the server first. Any ideas guys to why this code don't work? Link to comment
Stijger Posted February 16, 2012 Author Share Posted February 16, 2012 Nobody has any idea why the second code doesn't work? Link to comment
Stijger Posted February 22, 2012 Author Share Posted February 22, 2012 Another try, Anybody?? if not, it's okay. but just curious. Link to comment
Castillo Posted February 23, 2012 Share Posted February 23, 2012 You have to create many trailers, bagages, you can't just create one and use it for every vehicle. Link to comment
Stijger Posted February 23, 2012 Author Share Posted February 23, 2012 Oke, thanks. I will try that. Link to comment
Stijger Posted March 5, 2012 Author Share Posted March 5, 2012 (edited) Hey guys, back again, so now i adjusted the code (or rather just started from scratch) Now i create as many trailers and bagages as needed. And that all works (not for people entering during a race, but what the hell) --------------Multiple Trailers---------------- -----------------By: Stijger------------------- players = getElementsByType("player") addEvent("onRaceStateChanging", true) addEventHandler("onRaceStateChanging", getRootElement(), function(newStateName, oldStateName) if newStateName == "GridCountdown" then for _,player in pairs(players) do veh = getPedOccupiedVehicle (player) trailer = createVehicle ( 591, 1960, -2430, 15 ) veh2 = createVehicle (485, 1960, -2431.1, 15.1 ) setElementAlpha ( veh2, 0) trailer2 = createVehicle ( 591, 1960, -2439, 15 ) veh3 = createVehicle (485, 1960, -2441.1, 15.1 ) setElementAlpha ( veh3, 0) trailer3 = createVehicle ( 435, 1960, -2449, 15 ) setTimer (attachTrailerToVehicle, 1500, 1, veh, trailer) setTimer (attachElements, 2000, 1, veh2, trailer, 0, -1.1, 0.1) setTimer (attachTrailerToVehicle, 2500, 1, veh2, trailer2) setTimer (attachElements, 3000, 1, veh3, trailer2, 0, -1.1, 0.1) setTimer (attachTrailerToVehicle, 3500, 1, veh3, trailer3) end end end ) But now it's seems like i have a sync problem. At least I think, cause i have no idea. It seems for the player that the trailers of the other player come loose if they drive too fast. Which isn't the case, cause on the other players screen there's nothing wrong. And also the detached trailer appears to be dragged along but at a great distance, so they arent really loose. Youtube video: http://www.youtube.com/watch?v=rQxfTC9veSs Edited March 5, 2012 by Guest Link to comment
Castillo Posted March 5, 2012 Share Posted March 5, 2012 Trailers have a bad sync, if you're far you see the trailer attach and detach from the truck. Some times they are also invisible, the player who's driving the truck can see the trailer, but remote players can't. Link to comment
Stijger Posted March 5, 2012 Author Share Posted March 5, 2012 Trailers have a bad sync, if you're far you see the trailer attach and detach from the truck. Some times they are also invisible, the player who's driving the truck can see the trailer, but remote players can't. Hey Solidsnake, Thanks for the explanation, and I guess there's no way of fixing this right? (btw my solution for the trailers is good right? or do you have another solution?) Link to comment
Castillo Posted March 5, 2012 Share Posted March 5, 2012 Well, that'll be really bad when you try to destroy the trailers, I would suggest using a table to store trailers. Link to comment
Stijger Posted March 5, 2012 Author Share Posted March 5, 2012 A table for each player? Not really familiar with tables yet, but okay thanks for the advice. Will try that. Link to comment
Stijger Posted March 7, 2012 Author Share Posted March 7, 2012 okay, the tables are a step to high, i guess. local players = getElementsByType("player") local trailers = { createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90), createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90), createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90), createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90), createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90), } function attachTrailer () outputChatBox ( "A trailer will be attached, don't lose it or you will blow up!", getRootElement(), 255, 0, 0 ) for _,player in pairs(players) do veh = getPedOccupiedVehicle (player) setTimer (attachTrailerToVehicle, 3000, 1, veh, _,trailer in pairs(trailers)) -- Attach trailer to roadtrain after 1.5 sec end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), attachTrailer ) tried this, but that didn't work ofcourse. Can you guys give me a little help? Link to comment
Castillo Posted March 7, 2012 Share Posted March 7, 2012 I'm afraid you haven't understood me, I meant to store every trailer on a table. E.g: local trailers = {} addEventHandler("onPlayerJoin",root, function () trailers[source] = {} end ) Then you can do something like this: trailers[source][1] = createVehicle(arguments...) Link to comment
Stijger Posted March 12, 2012 Author Share Posted March 12, 2012 okay, I totally lost it. I got as far as this. local trailers = {} addEventHandler("onPlayerJoin",root, function () trailers[source] = {} end ) players = getElementsByType("player") function attachTrailer () for _,player in pairs(players) do local veh = getPedOccupiedVehicle (player) trailers[source][1] = createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90) -- create a trailer outputChatBox ( "A trailer will be attached", getRootElement(), 255, 0, 0 ) setTimer (attachTrailerToVehicle, 5000, 1, veh, trailer) -- Attach trailer to roadtrain after 5 sec end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), attachTrailer ) But that gave me this error: ERROR: editor_test\trialertable.lua:14: attempt to index field '?' (a nil value) And really me head spins, I could like maybe figure out how to get them in the table. But how are you using them? like: "setTimer (attachTrailerToVehicle, 5000, 1, veh, trailer)" what should I put on the part of the "trailer" Link to comment
Castillo Posted March 12, 2012 Share Posted March 12, 2012 local trailers = {} addEventHandler ( "onResourceStart", resourceRoot, function ( ) for index, player in ipairs ( getElementsByType ( "player" ) ) do trailers[ player ] = { } end end ) addEventHandler ( "onPlayerJoin", root, function ( ) trailers[ source ] = { } end ) function attachTrailer () for _,player in pairs ( getElementsByType ( "player" ) ) do local veh = getPedOccupiedVehicle ( player ) if ( not trailers[player] ) then trailers[player] = { } end trailers[player][1] = createVehicle ( 435, 2682, -2127.5, 15, 0, 0, 90) -- create a trailer -- Here you put 'source' instead of 'player'. outputChatBox ( "A trailer will be attached", getRootElement(), 255, 0, 0 ) setTimer (attachTrailerToVehicle, 5000, 1, veh, trailers[player][1]) -- Attach trailer to roadtrain after 5 sec end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), attachTrailer ) 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