dewu Posted February 21, 2015 Share Posted February 21, 2015 Hi guys. Is any way to glue max. 1 vehicle? I'm using glue2: https://community.multitheftauto.com/?p=resources ... ils&id=360 Link to comment
Dealman Posted February 21, 2015 Share Posted February 21, 2015 Sure there is, you could use setElementData for example. Make a data value for the vehicle called "numberOfGluedObjects" or whatnot, increase the value every time something is glued to something. And if the number is greater than whatever you want it to be, do not glue them. I don't know the functions of the resource you're using, or if they're even exported - so you'll have to figure that out yourself. Link to comment
dewu Posted February 21, 2015 Author Share Posted February 21, 2015 Sure, I'm too thinked about it, but in this situation really don't know how to use it, it's really complicated. That's the script: function gluev() local outString outputDebugString("glue vehicle") local thePlayer = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(thePlayer) if myVehicle then local attachMe, attachedTo outputDebugString("my vehicle") local vehicles = getElementsByType("vehicle") local closest, cdist = nil, 100 local mx,my,mz = getElementPosition(myVehicle) for k,v in ipairs(vehicles) do local model = getElementModel(v) if isElementStreamedIn(v) and model == 578 and v ~= myVehicle then local x,y,z = getElementPosition(v) local tmpdist = getDistanceBetweenPoints3D(x,y,z,mx,my,mz) if tmpdist < cdist then cdist = tmpdist closest = v end end end outputDebugString("Auto = " .. getVehicleName(closest) .. ", distancia: " .. tonumber(cdist) .. "") if cdist > 4.1 or cdist == nil then return false end local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then attachMe = closest attachedTo = myVehicle else attachMe = myVehicle attachedTo = closest end local px, py, pz = getElementPosition(attachedTo) local vx, vy, vz = getElementPosition(attachMe) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX, rotpY, rotpZ = getElementRotation(attachedTo) local rotvX, rotvY, rotvZ = getElementRotation(attachMe) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ triggerServerEvent("glueVehicle", attachMe, attachedTo, x*-1, y*-1, z*-1, rotX, rotY, rotZ) unbindKey("k","down",gluev) bindKey("k","down",ungluev) else end end addCommandHandler("gluev",gluev) function ungluev () local player = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(player) local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then local attached = getAttachedElements(myVehicle) for k,v in ipairs(attached) do if getElementType(v) == "vehicle" then myVehicle = v end end end triggerServerEvent("unglueVehicle", myVehicle) unbindKey("jump","down",ungluev) unbindKey("k","down",ungluev) bindKey("k","down",gluev) end addCommandHandler("unglue",ungluev) bindKey("k","down",gluev) Link to comment
dewu Posted February 22, 2015 Author Share Posted February 22, 2015 Guys, i need your help. This should work but don't know why it's not: function gluev() local outString outputDebugString("glue vehicle") local thePlayer = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(thePlayer) if myVehicle then local attachMe, attachedTo outputDebugString("my vehicle") local vehicles = getElementsByType("vehicle") local closest, cdist = nil, 100 local mx,my,mz = getElementPosition(myVehicle) for k,v in ipairs(vehicles) do local model = getElementModel(v) if isElementStreamedIn(v) and model == 578 and v ~= myVehicle then local x,y,z = getElementPosition(v) local tmpdist = getDistanceBetweenPoints3D(x,y,z,mx,my,mz) if tmpdist < cdist then cdist = tmpdist closest = v end end end outputDebugString("Auto = " .. getVehicleName(closest) .. ", distancia: " .. tonumber(cdist) .. "") if cdist > 5 or cdist == nil then return false end local count = getElementData(thePlayer, "CountGlueVeh") if count > 2 then -- CHECK IF COUNT OF GLUE VEHICLES IS HIGHER THAN 2 return false -- IF IT IS RETURN FALSE end local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then attachMe = closest attachedTo = myVehicle else attachMe = myVehicle attachedTo = closest end local px, py, pz = getElementPosition(attachedTo) local vx, vy, vz = getElementPosition(attachMe) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX, rotpY, rotpZ = getElementRotation(attachedTo) local rotvX, rotvY, rotvZ = getElementRotation(attachMe) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ setElementData(thePlayer, "CountGlueVeh", count+1) -- ADD +1 TO ELEMENT DATA WHEN GLUE triggerServerEvent("glueVehicle", attachMe, attachedTo, x*-1, y*-1, z*-1, rotX, rotY, rotZ) unbindKey("k","down",gluev) bindKey("k","down",ungluev) end else end end addCommandHandler("gluev",gluev) function ungluev () local player = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(player) local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then local attached = getAttachedElements(myVehicle) for k,v in ipairs(attached) do if getElementType(v) == "vehicle" then myVehicle = v end end end setElementData(player, "CountGlueVeh", 0) -- SET 0 TO ELEMENT DATA WHEN UNGLUE triggerServerEvent("unglueVehicle", myVehicle) unbindKey("jump","down",ungluev) unbindKey("k","down",ungluev) bindKey("k","down",gluev) end addCommandHandler("unglue",ungluev) bindKey("k","down",gluev) function setnull() -- I'VE MADED COMMAND TO BE SURE THAT COUNT IS NULL local player = getLocalPlayer() setElementData(player, "CountGlueVeh", 0) end addCommandHandler("setnull",setnull) i've pointed that what i've added. 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