Jump to content

ivan8065

Members
  • Posts

    37
  • Joined

  • Last visited

  • Days Won

    1

ivan8065 last won the day on January 13

ivan8065 had the most liked content!

Recent Profile Visitors

1,399 profile views

ivan8065's Achievements

Rat

Rat (9/54)

3

Reputation

  1. Well it works but only on the nearest vehicle (yeah I know that is logical) but does somebody know how to make it work on more cars nearby? function getNearestVehicle(source,distance) local lastMinDis = distance-0.0001 local nearestVeh = false local px,py,pz = getElementPosition(source) local pint = getElementInterior(source) local pdim = getElementDimension(source) for _,v in pairs(getElementsByType("vehicle")) do local vint,vdim = getElementInterior(v),getElementDimension(v) if vint == pint and vdim == pdim then local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis then lastMinDis = dis nearestVeh = v end end end end return nearestVeh end function getElementSpeed(theElement, unit) -- Check arguments for errors assert(isElement(theElement), "Bad argument 1 @ getElementSpeed (element expected, got " .. type(theElement) .. ")") local elementType = getElementType(theElement) assert(elementType == "player" or elementType == "ped" or elementType == "object" or elementType == "vehicle" or elementType == "projectile", "Invalid element type @ getElementSpeed (player/ped/object/vehicle/projectile expected, got " .. elementType .. ")") assert((unit == nil or type(unit) == "string" or type(unit) == "number") and (unit == nil or (tonumber(unit) and (tonumber(unit) == 0 or tonumber(unit) == 1 or tonumber(unit) == 2)) or unit == "m/s" or unit == "km/h" or unit == "mph"), "Bad argument 2 @ getElementSpeed (invalid speed unit)") -- Default to m/s if no unit specified and 'ignore' argument type if the string contains a number unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit)) -- Setup our multiplier to convert the velocity to the specified unit local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456) -- Return the speed by calculating the length of the velocity vector, after converting the velocity to the specified unit return (Vector3(getElementVelocity(theElement)) * mult).length end addEventHandler( "onClientResourceStart", getRootElement( ), function (thePlayer) epr() end ); function getVehicleRPM(vehicle) local vehicle = getNearestVehicle(localPlayer,2000) local vehicleRPM = 0 if (vehicle) then if (getVehicleEngineState(vehicle) == true) then if getVehicleCurrentGear(vehicle) > 0 then vehicleRPM = math.floor(((getElementSpeed(vehicle, "km/h") / getVehicleCurrentGear(vehicle)) * 160) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9000) then vehicleRPM = math.random(9000, 9900) end else vehicleRPM = math.floor((getElementSpeed(vehicle, "km/h") * 160) + 0.5) if (vehicleRPM < 650) then vehicleRPM = math.random(650, 750) elseif (vehicleRPM >= 9000) then vehicleRPM = math.random(9000, 9900) end end else vehicleRPM = 0 end return tonumber(vehicleRPM) end end function epr() setTimer(function() local theVeh = getNearestVehicle(localPlayer,2000) local enginerpm = getVehicleRPM(theVeh) local rotspeed = enginerpm/32 local rx, ry, rz = getVehicleComponentRotation(theVeh, "vetrak") setVehicleComponentRotation(theVeh, "vetrak", rx-rotspeed, ry, rz) local rx, ry, rz = getVehicleComponentRotation(theVeh, "kluka") setVehicleComponentRotation(theVeh, "kluka", rx-rotspeed, ry, rz) local rx, ry, rz = getVehicleComponentRotation(theVeh, "alternator") setVehicleComponentRotation(theVeh, "alternator", rx-rotspeed, ry, rz) end, 0, 0) end addEvent("epr", true) addEventHandler("epr", root, epr)
  2. Okay I managed to make https://wiki.multitheftauto.com/wiki/GetNearestVehicle to work and it is automated with https://wiki.multitheftauto.com/wiki/OnClientResourceStart
  3. Hello, I am working on script for moving engine parts. I managed to make parts move but at the moment it is only turnable by command and I need help with script doing it somewhat automatically when engine is running. The vehicles are server-sided. I tried using https://wiki.multitheftauto.com/wiki/GetNearestVehicle but only thing I managed to get is error from getElementPosition,Interior and Dimension everytime when I tried localPlayer, player or thePlayer for some reason although I don't know if it would work when used on client-side with server-sided vehicles and probably needs something more to it. Thank you in advance for any reply. (PS: Plz don't kill me for my naming conventions ) CLIENT function epr() local theVeh = getPedOccupiedVehicle(source) if (theVeh) then setTimer(function() local rx, ry, rz = getVehicleComponentRotation(theVeh, "vetrak") setVehicleComponentRotation(theVeh, "vetrak", rx-25, ry, rz) local rx, ry, rz = getVehicleComponentRotation(theVeh, "kluka") setVehicleComponentRotation(theVeh, "kluka", rx-25, ry, rz) local rx, ry, rz = getVehicleComponentRotation(theVeh, "alternator") setVehicleComponentRotation(theVeh, "alternator", rx-25, ry, rz) end, 0, 0) end end addEvent("epr", true) addEventHandler("epr", root, epr) SERVER function epr( thePlayer, commandName ) triggerClientEvent (thePlayer,"epr",thePlayer) end addCommandHandler ("epr", epr)
  4. ivan8065

    Error CD09

    Hello, I am getting error CD09 when connecting on server (v1.6) https://pastebin.mtasa.com/6440577617 Thank you for reply.
  5. Hmm, interesting. I could try that. Thank you for tip.
  6. Hello, I would like to ask if it's possible to create and attach something like water emitter on vehicle (like on firetruck) and ideally if it could extinguish fires. Thank you for reply.
  7. Oh ok sorry, didn't know that. Thank you very much.
  8. Hello, I was trying to make script that would show the name of bus stop in front of bus. I started by trying this example from wiki: local randomPed = createPed(285, 2476.91406, -1665.31799, 13.32435) addEventHandler("onClientRender", getRootElement(), function() dxDrawTextOnElement(randomPed, "SWATTEAM Officer", 1, 20, 0, 0, 255, 255, 1, "pricedown") end) but it throws me this error: client.lua:5 attempt to call global 'dxDrawTextOnElement' (a nil value) Was the function removed from MTA or what can be problem please? Thank you for reply.
  9. @The_GTA I did changes you written and it works, thank you very much for help! ?
  10. Hello, I am trying to do working side doors on van through setComponentPosition and trying to sync it with other players with triggerClientEvent but it's not working, what I have got wrong? Thank you for reply. CLIENT function scp() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", x+0.1, y-1, 0) -- increases by 1 unit end end addEvent("scp", true) addEventHandler("scp", localPlayer, scp) function scp2() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", x-0.1, y+1, 0) -- increases by 1 unit end end addEvent("scp2", true) addEventHandler("scp2", localPlayer, scp2) function scpreset() local theVeh = getPedOccupiedVehicle(localPlayer) local getComponent = getVehicleComponents(theVeh) -- returns table with all the components of the vehicle if (theVeh) then local x, y, z = getVehicleComponentPosition(theVeh, "bocne_dvere") --get the position of the component setVehicleComponentPosition(theVeh, "bocne_dvere", 0, 0, 0) -- increases by 1 unit end end addEvent("scpreset", true) addEventHandler("scpreset", localPlayer, scpreset) SERVER function scp ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scp",thePlayer) end addCommandHandler ("scp", scp) function scp2 ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scp2",thePlayer) end addCommandHandler ("scp2", scp2) function scpreset ( thePlayer, commandName ) local x, y, z = getElementPosition(thePlayer) local nearbyPlayers = getElementsWithinRange(x, y, z, 100, "player") triggerClientEvent (nearbyPlayers,"scpreset",thePlayer) end addCommandHandler ("scpreset", scpreset)
  11. WOW man, it really works! Thank you very much!
  12. Yeah sorry my fault. I changed it from localPlayer to thePlayer, even tried vehicle and now I don't have any errors or warnings but after using command it still wont attach trailer to vehicle and changing distance didn't help. function getNearestTrailer(thePlayer,distance) local lastMinDis = distance-0.0001 local nearestTrailer = false local px,py,pz = getElementPosition(thePlayer) local pint = getElementInterior(thePlayer) local pdim = getElementDimension(thePlayer) for _,v in pairs(getElementsByType("vehicle")) do local vint,vdim = getElementInterior(v),getElementDimension(v) if vint == pint and vdim == pdim then local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis and getVehicleType(v) == "trailer" then lastMinDis = dis nearestTrailer = v end end end end return nearestTrailer end function hookTrailer(thePlayer,commandName) local vehicle = getPedOccupiedVehicle ( thePlayer ) if vehicle then local x,y,z = getElementPosition( vehicle ) local rx,ry,rz = getElementRotation ( vehicle ) local trailer = getNearestTrailer(thePlayer, 2000) if trailer then attachTrailerToVehicle ( vehicle, trailer ) outputChatBox("Connected.", thePlayer, 0, 255, 0) else outputChatBox("No nearby trailer was found!", thePlayer, 255, 0, 0) end else outputChatBox("You need to be in a vehicle!", thePlayer, 255, 0, 0) end end addCommandHandler("hook", hookTrailer)
  13. I am trying to make it server-sided but in debug I have warnings from last 3 lines saying "Expected element at argument 1, got nil" and it is saying same thing if it's there player or thePlayer. function getNearestTrailer(player,distance) local lastMinDis = distance-0.0001 local nearestTrailer = false local px,py,pz = getElementPosition(player) local pint = getElementInterior(player) local pdim = getElementDimension(player)
  14. I hope I got it correctly like this function getNearestTrailer(player,distance) local lastMinDis = distance-0.0001 local nearestTrailer = false local px,py,pz = getElementPosition(player) local pint = getElementInterior(player) local pdim = getElementDimension(player) for _,v in pairs(getElementsByType("vehicle")) do local vint,vdim = getElementInterior(v),getElementDimension(v) if vint == pint and vdim == pdim then local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis and getVehicleType(v) == "trailer" then lastMinDis = dis nearestTrailer = v end end end end return nearestTrailer end function hookTrailer(commandName) vehicle = getPedOccupiedVehicle(localPlayer) local x,y,z = getElementPosition( vehicle ) local rx,ry,rz = getElementRotation ( vehicle ) trailer = getNearestTrailer(localPlayer, 50) attachTrailerToVehicle ( vehicle, trailer ) outputChatBox("Connected.", 255, 0, 0) end addCommandHandler("hook", hookTrailer) because I got warning WARNING: trailer/trailer.lua:29: Bad argument @ 'attachTrailerToVehicle' [Expected vehicle at argument 2, got boolean]
  15. Hello, I am trying to make script that would allow me connect existing trailer to existing vehicle. I am working with example from here https://wiki.multitheftauto.com/wiki/AttachTrailerToVehicle and I managed to make trailer spawn to existing car but I don't know how define trailer so it will connect trailer that is spawned nearby to my car. Thank you for any help. setTimer( function() local vehicle = getPedOccupiedVehicle( localPlayer ) local x,y,z = getElementPosition( vehicle ) local rx,ry,rz = getElementRotation ( vehicle ) local trailer = attachTrailerToVehicle ( vehicle, trailer ) -- attach then outputChatBox("Connected.", 255, 0, 0) end, 50, 1)
×
×
  • Create New...