kerts93 Posted November 6, 2010 Share Posted November 6, 2010 Hey again, I've got one small question. Is it possible, that server automatically creates trailer 591 and attaches it to vehicle 514 if it's created (by map file, by script or by command (that spawns a vehicle). Basically spawns+attaches the trailer every time a specific id vehicle is created? Link to comment
dzek (varez) Posted November 6, 2010 Share Posted November 6, 2010 hmm, by map - not possible with pure event, but possible with something like: -- server: function getPositionRelatedToVehicle(theVeh, x, y) local xx, yy, zz = getElementPosition(theVeh) local rx, ry, rot = getElementRotation(theVeh) local lx = xx + math.sin (math.rad(-rot)) * x local ly = yy + math.cos (math.rad(-rot)) * y return lx,ly end addEvent("onVehicleSpawn", false) addEventHandler("onVehicleSpawn", getRootElement() function() -- source = spawned vehicle if (getElementModel(source)== 514) then local x,y,z = getElementPosition(source) local rx, ry, rz = getElementRotation(source) local lx, ly = getPositionRelatedToVehicle(source, -3, -3) local trailer = createVehicle(591, lx, ly, z) setElementRotation(trailer, 0, 0, rz) attachTrailerToVehicle(trailer, source) end end) setTimer(function() local vehs = getElementsByType('vehicle') for key,val in ipairs(vehs) do local ed = getElementData(val, "spawnedEventTriggered") if (ed ~= true) then setElementData(val, "spawnedEventTriggered") triggerEvent("onVehicleSpawn", val) end end end, 500, 0) not tested. there is no other way afaik but remember - this can be cpu consuming when there is a lot of cars around the map (but i think it will be fine anyway) Link to comment
kerts93 Posted November 7, 2010 Author Share Posted November 7, 2010 thanks, I'll try it out This section: addEventHandler("onVehicleSpawn", getRootElement() function() -- source = spawned vehicle if (getElementModel(source)== 514) then local x,y,z = getElementPosition(source) local rx, ry, rz = getElementRotation(source) local lx, ly = getPositionRelatedToVehicle(source, -3, -3) local trailer = createVehicle(591, lx, ly, z) setElementRotation(trailer, 0, 0, rz) attachTrailerToVehicle(trailer, source) end end Gives me this error: ')' expected near 'function' line 33 which currently is line 1 here ' expected near 'end' line 43 which is last line here Link to comment
Castillo Posted November 7, 2010 Share Posted November 7, 2010 addEventHandler("onVehicleSpawn", getRootElement(), function() -- source = spawned vehicle if (getElementModel(source)== 514) then local x,y,z = getElementPosition(source) local rx, ry, rz = getElementRotation(source) local lx, ly = getPositionRelatedToVehicle(source, -3, -3) local trailer = createVehicle(591, lx, ly, z) setElementRotation(trailer, 0, 0, rz) attachTrailerToVehicle(trailer, source) end end) Link to comment
kerts93 Posted November 7, 2010 Author Share Posted November 7, 2010 okey, now it keeps spawning trailers and console gives WARNING: lvrp\baas.lua:53: Bad argument @ 'setElementData' Link to comment
dzek (varez) Posted November 7, 2010 Share Posted November 7, 2010 fix that line with: setElementData(val, "spawnedEventTriggered", true) Link to comment
kerts93 Posted November 7, 2010 Author Share Posted November 7, 2010 thanks, work's perfectly, but I had to swap in attachTrailerToVehicle trailer and source places. Also, added that newly created trailer uses same colors as the cab uses Thanks for the help 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