Jump to content

destroying element after map ends


kikos500

Recommended Posts

soo i made a command adds to u ramp on car but i won't it to be destroyed when map ends

so there is the code

function ramp ( thePlayer, commandName ) 
      if ( thePlayer ) then 
             local ramp = createObject ( 1634, 0, 0, 0, 0, 0, 0 ) 
  
                 attachElements ( ramp, getPedOccupiedVehicle(thePlayer), 0, 1, 0, 0, 0, 180 ) 
                        setObjectScale ( ramp, 0.7) 
  
              if ( ramp ) then 
                  outputChatBox ( "Ramp Added", thePlayer ) 
              end 
       end 
end 
addCommandHandler ( "ramp", ramp ) 

Link to comment
  • Moderators

try something like this:

local mapRoot = resourceRoot -- temporary adding to resourceRoot 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    local resourceOfMap = export.mapmanager:getRunningGamemodeMap ( )  
    if resourceOfMap then 
        mapRoot = getResourceRootElement(resourceOfMap) 
    end 
end) 
  
addEventHandler( "onGamemodeMapStart", root,  
function (startedMap)  
    mapRoot = getResourceRootElement(startedMap) 
end) 
  
  
function ramp ( thePlayer, commandName ) 
    if ( thePlayer ) then 
        local ramp = createObject ( 1634, 0, 0, 0, 0, 0, 0 ) 
        if ramp then 
            attachElements ( ramp, getPedOccupiedVehicle(thePlayer), 0, 1, 0, 0, 0, 180 ) 
            setObjectScale ( ramp, 0.7) 
            outputChatBox ( "Ramp Added", thePlayer ) 
             
            if isElement(mapRoot) then 
                local setToParent = setElementParent(ramp, mapRoot)  
                if setToParent then -- debug -- 
                    outputDebugString("Set ramp parent successfully!") 
                end 
            end 
        end 
    end 
end 
addCommandHandler ( "ramp", ramp ) 

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