Jump to content

[REL] Simple fully working ramp script


Recommended Posts

Ok i saw an old topic where they were talking about spawning ramps, but the problem was ( i tested that scripts )

When 2 players (or more) spawned the ramps at the same time, the first ramp that was spawned didnt disappear.

So that means when your server is a populair you will get a lot of ramps in your server that dont disappear.

I changed that script a bit, and this script allows you to spawn a ramp which disappears 2 seconds later.

Other players can spawn their ramp too at the same time, and all ramps will disappear.

Just get a vehicle and push 'c' and BAM... there is a ramp infront of you

Here you are ;)

  
  
-- Somewhere at the top 
ramp = { } 
rampspawned = { } 
  
--- Put this somewhere in onPlayerJoin event or something, of sterf..    
bindKey ( source, "c", "down", createRamp )  
  
-- Somewhere in your script  
function createRamp ( source )  
    if(isPlayerInVehicle ( source ) ) then 
        if( rampspawned [ source ] ~= true ) then 
            local x, y, z = getElementPosition ( source ) 
            local theVehicle = getPlayerOccupiedVehicle ( source ) 
            local a,b,r = getVehicleRotation ( theVehicle ) 
            x = x - math.sin ( math.rad(r) ) * 20 
            y = y + math.cos ( math.rad(r) ) * 20 
            ramp [ source ] = createObject ( 1655, x, y, z, 0, 0, r ) 
            rampspawned [ source ] = true 
            setTimer ( RemoveRamp, 2000, 1, source ) 
        end  
    end  
end 
  
function RemoveRamp ( source ) 
    destroyramp = destroyElement( ramp [ source ] ) 
    if ( destroyramp ) then 
        rampspawned [ source ] = false 
    end  
end 

Edited by Guest
Link to comment

IMO 1655 is too big of a ramp, I have something like this in my server, it defaults to ramp 1632 which is smaller, but you can /setramp number, and theres no time limit between spawning ramps. It also uses Left Alt, and Numpad 0, and if your flying you can disable it with /setramp 0. 2 Seconds also is WAY too short of a time, mine is 10 sec, but good script for people to build off of. :)

Link to comment

okok, i have think this already :wink:

but what the hell, than why dont work this?

  
-- Somewhere at the top 
ramp = { } 
rampspawned = { } 
  
--- Put this somewhere in onPlayerJoin event or something, of sterf..   
function keyboard ( source ) 
 bindKey ( source, "c", "down", createRamp ) 
end 
  
-- Somewhere in your script  
function createRamp ( source, command )  
    if(isPlayerInVehicle ( source ) ) then 
        if( rampspawned [ source ] ~= true ) then 
            local x, y, z = getElementPosition ( source ) 
            local theVehicle = getPlayerOccupiedVehicle ( source ) 
            local a,b,r = getVehicleRotation ( theVehicle ) 
            x = x - math.sin ( math.rad(r) ) * 20 
            y = y + math.cos ( math.rad(r) ) * 20 
            ramp [ source ] = createObject ( 1655, x, y, z, 0, 0, r ) 
            rampspawned [ source ] = true 
            setTimer ( RemoveRamp, 2000, 1, source ) 
        end  
    end  
end 
  
function RemoveRamp ( source ) 
    destroyramp = destroyElement( ramp [ source ] ) 
    if ( destroyramp ) then 
        rampspawned [ source ] = false 
    end  
end 
  
addEventHandler ( "onPlayerJoin", getRootElement(), keyboard) 
  

(debugscript says nothing)

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