Jump to content

[REL] Ramp Spawning Script


Woovie

Recommended Posts

A script I've had for a while written by me and OffRoader23. Decided to release it. Here you go:

ramps.lua

ramp = {} 
rampid = {} 
  
function spawnRamp (player) 
    if (isPedInVehicle( player ) == true) then 
        local vehicle = getPedOccupiedVehicle ( player ) 
        local speed = getPlayerSpeed ( player, 2 ) 
        speed = speed / 12 
        local px, py, pz = getElementPosition ( vehicle ) 
        local rx, ry, rz = getVehicleRotation ( vehicle ) 
        local pingdis = getPlayerPing ( player ) / 20 
        if rx > 180 then rx = rx - 360 end           
        local x = (speed + 15 + pingdis)*math.cos((rz+90)*math.pi/180) 
        local y = (speed + 15 + pingdis)*math.sin((rz+90)*math.pi/180) 
        local a2 = (speed + 15 + pingdis) 
        local b2 = a2 / math.cos(rx*math.pi/180) 
        local c2 = math.sqrt(b2*b2 - a2*a2) 
        if rx < 0 then c2 = -c2 end 
        local nx = px + x 
        local ny = py + y 
        local carseat = getPedOccupiedVehicleSeat ( player ) 
        if carseat ~= 0 then  --if player is not driving 
            outputConsole ( "No ramp spawning as passenger.", player ) 
        else --if player is driver 
            if rampid[player] == 0 then 
                outputConsole ( "Ramp disabled.  Type /setramp 1-7 to restore.", player ) 
            elseif rampid[player] == nil or rampid[player] == 1 then 
                ramp = createObject ( 1632, nx, ny, pz + c2, rx, ry, rz ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 2 then 
                ramp = createObject ( 1655, nx, ny, pz + c2, 0, 0, rz ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 3 then 
                ramp = createObject ( 13641, nx, ny, pz + c2, 0, 0, rz + 90) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 4 then 
                ramp = createObject ( 1660, nx, ny, pz + c2 - 1.5, 0, 0, rz ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 5 then 
                ramp = createObject ( 1631, nx, ny, pz + c2, 0, 0, rz ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 6 then 
                ramp = createObject ( 4870, nx, ny, pz - 1.5, 0, 0, rz - 90 ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            elseif rampid[player] == 7 then 
                ramp = createObject ( 4870, nx, ny, pz + c2 - 1.5, 0, 15, rz - 90 ) 
                setTimer ( deleteRamp, 10000, 1, ramp ) 
            end 
        end 
    end 
end 
addCommandHandler ( "ram", spawnRamp) 
  
function setRamp (player, commandname, numb) 
    local rampnum = tonumber(numb)  
    if rampnum >= 1 and rampnum <= 7 then 
        outputChatBox ( "Ramp set as " ..numb.. ".", player ) 
        rampid[player] = rampnum 
    else 
        outputChatBox ( "Ramp disabled.  Type /setramp 1-7 to restore.", player ) 
        rampid[player] = 0 
    end 
end 
addCommandHandler ( "setramp", setRamp) 
  
function getPlayerSpeed( source, mode ) 
    if (isPedInVehicle( source ) == true) then 
        vehicle = getPedOccupiedVehicle( source ) 
        if (mode == "MPH" or mode == 1) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.14) 
        end 
        if (mode == "KMH" or mode == 2) then 
            return math.floor(getDistanceBetweenPoints3D(0,0,0,getElementVelocity(vehicle)) * 100 * 1.61 * 1.14) 
        end 
    else 
        return 0 
    end 
end 
  
function deleteRamp ( ramp, player ) 
    destroyElement ( ramp ) 
end 
  
function playerJoin () 
    bindKey ( source, "num_0", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
    bindKey ( source, "lalt", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
    bindKey ( source, "mouse4", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
    rampid[source] = 1 
end 
  
function playerLeave () 
    if rampid[source] ~= nil then rampid[source] = nil end 
end 
  
function thisResourceStart () 
local players = getElementsByType ( "player" ) 
    for k,v in ipairs(players) do 
        bindKey ( v, "num_0", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
        bindKey ( v, "lalt", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
        bindKey ( v, "mouse4", "down", spawnRamp, "Spawn Ramp N Shit Yo" ) 
        rampid[v] = 1 
    end 
end 
  
local thisResourceRoot = getResourceRootElement(getThisResource()) 
addEventHandler ( "onResourceStart", thisResourceRoot, thisResourceStart ) 
addEventHandler ( "onPlayerJoin", getRootElement(), playerJoin ) 
addEventHandler ( "onPlayerQuit", getRootElement(), playerLeave ) 

meta.xml

<meta> 
    <info author="Woovie" version="1" name="Ramp Spawning Script" description="Press left ALT to spawn a ramp" type="script"/> 
    <script src="ramps.lua" /> 
</meta> 

Link to comment
  • 1 year later...
  • 1 month later...

*sigh* To change the format of the document, click tools, then press "Folder Options". After you open it, go to the "view" tab.

Find the "Hide extension for known file types", then untick that box.

After that, you can find the extensions for each file. Now you can easily change txt. to xml. by simply renaming it.

meta.txt --> meta.xml

(Windows XP, may be different in future versions)

Link to comment
  • 3 weeks later...

Thank you, this is awesome, saw it on another server once where I had so much fun with it.

I'm not a scripter myself, but I was wondering if I could request a small modification from somebody.

If left alt spawns a ramp infront of the player depending on which angle he is facing, would it be difficult to modify the script so that another key could be binded to spawn a ramp infront of the player, but have the same Y axis. (so that e.g. if your in the air on a bike angled upwards, the ramp doesn't spawn above you)

Even if my request is ignored thanks for the script again.

Link to comment
  • 3 months later...

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