Jump to content

I'm expanding magnet wheels...but I need a little help.


qaisjp

Recommended Posts

Pastebin Download

local stickyEnabled = false 
local me = getLocalPlayer() 
local testMode 
local oldMad=10010101099023980 
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 
function isNumberBetweenPoints(number, pointa, pointb) 
    return (number>pointa) and (number) 
end 
function isVehicleOnSteepSurface(veh) 
    local x,y,z = getElementPosition(veh) 
    local steepSurface,_,_,_,_,normalx,normaly,normalz=processLineOfSight(x,y,z+1,z,y,z-10,true,false,false,true,false,false,false,false,veh) --i suppose u know what to put in the veh arugments? yes i do =D 
    if steepSurface then 
        steepSurface = getDistanceBetweenPoints2D(normalx,normaly,0,0)>normalz 
    else 
        steepSurface = true 
    end 
    return steepSurface 
end 
function onRender() 
    local veh = getPedOccupiedVehicle(me) 
    if not veh then 
        removeEventHandler("onClientRender",root,onRender) 
        stickyEnabled = false 
        outputChatBox("[VEH] Sticky wheels turned to: "..tostring(stickyEnabled)) 
        return 
    end 
    local vehicleIsSurfaced, gX,gY,gZ = isSurfaced(veh) 
    local steepSurface = isVehicleOnSteepSurface(veh) 
    if testMode ~= vehicleIsSurfaced then 
        testMode = vehicleIsSurfaced 
        outputDebugString("Is vehicle on a surface? : "..tostring(testMode)) 
    end 
    if oldMad ~= steepSurface then 
        oldMad = steepSurface 
        outputDebugString("If on surface, is it steep? : "..tostring(oldMad)) 
    end 
    if vehicleIsSurfaced and steepSurface then 
        setVehicleGravity(veh, gX,gY,gZ) 
    else 
        setVehicleGravity(veh,0,0,-1) 
    end 
end 
  
function getPositionBelowElement(element) 
    local matrix = getElementMatrix (element) 
    local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1] 
    local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2] 
    local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3] 
    return offX,offY,offZ 
end 
  
function isSurfaced(element) 
    local x,y,z = getElementPosition(element) 
    local bX,bY,bZ = getPositionBelowElement(element) 
    local nX,nY,nZ = bX-x,bY-y,bZ-z 
    local isSurface, sX, sY, sZ, surfaceObj = processLineOfSight(x, y, z, bX,bY,bZ, true, false, false, true, false) 
    return isSurface, nX,nY,nZ 
end 
  
function stopSticky() 
    if stickyEnabled then 
        removeEventHandler("onClientRender",root,onRender)     
        veh = getPedOccupiedVehicle(me) 
        if veh then 
            setVehicleGravity(veh,0,0,-1) 
        end 
    else 
        addEventHandler("onClientRender",root,onRender) 
    end 
    stickyEnabled = not stickyEnabled 
    outputChatBox("[VEH] Sticky wheels turned to: "..tostring(stickyEnabled)) 
end 
  
addCommandHandler("sticky",stopSticky) 

It works fine and my edit determines the following thing. It only sets the gravity below it if it is on a surface and not in the air. I noticed that if I am HIGH above the ground, it disables, but when the bottom of it is near the ground, but not on it, it still enables.

It seems that I have done the above thing, it disables when in the air, but now I want to check if the vehicle is on a steep surface...help would be appreciated.

I'm not a pro at vector quantities and element matrixes. For those who want this, can get this very soon, but not yet. All you have to do is credit me and the original author of magnetwheels.

*please note, if you want to complain about this idea being from being from DKR server, read ahead. DKR server inspired me to make their brilliant DKR stickywheels (originally developed by DKR Kayl) and I give credits for their extra idea added to magnetwheels.*

See it in action!

Edited by Guest
Link to comment

use 3x vertical processLineOfSight that are set to not process the vehicle itself at aprox vehicle bounds, if the Z distance differs alot between those 3 outputs, youre on a steep surface.

PS:remember to handle case that nothing is hit within the line of sight aswell.

EDIT:i forgot 1.1 has also surface normal vector output, you may aswell process only 1 line of sight, and check, is x and/or y offset of the surface vector big enought for it to be steep surface.

Link to comment
  
... 
  hit,_,_,_,_,normalx,normaly,normalz=processLineOfSight(vehiclex,vehicley,vehiclez+1,vehiclex,vehicley,vehiclez-10,true,false,false,true,false,false,false,false,vehicle) --i suppose u know what to put in the veh arugments? 
  if hit then 
    issteep=getDistanceBetweenPoints2D(normalx,normaly,0,0)>normalz 
  else 
    issteep=true 
  end 
... 
  

Link to comment

Yes, it isn't illegal to use someone's idea Qaisjp (although in this case it's still pretty low, and you do need to be careful of hiding behind that "inspiration" assumption), but you do need to reference the already-established idea you are using to form the basis of your work. Just like when you're at school and you use someone's research to do your essay, you can use their ideas but you need to give due credit. And I think we both know where this idea came from, so make sure you credit him and the server he kindly transferred ownership of the resource to.

MTA is only going to be a worthwhile community if the vast majority of the people who form the community behave in a fair and honest manner. I hope you're planning on changing camp to the honest team, Qaisjp.

Link to comment

Indeed [DKR]Oz, I will be giving great thanks to Kayl and you for your ideas if and when I use them, since I will be releasing them out. So yes, this idea came from DKR server and I give Kayl great thanks for his work.

karlis, i will try it out now. Slothman tried it himself and he said he doesn't think it is possible using line of sight, he said try using vehicle rotation. Anyway, i will try it.

EDIT: WOOOT IT WORKS! but it is very sensitive, now i need to see how to stop it from being so sensitive D:

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