Jump to content

[Solved] How to destroy a race pickup?


Recommended Posts

Hi. I need to find a solution to destroy "repair" pickup from race gamemode, this to prevent the players takes so long on fighting because they camp the repairs.

I wrote these codes on the race_server.lua

First I tried to destroy the element "racepickup" seeing that the element is called in that way on the .map file:

function destroyPickups() 
    local objects = getElementsByType("racepickup") 
    for i,k in ipairs(objects) do 
        destroyElement(k) 
    end 
end 
addCommandHandler("destroypicks", destroyPickups) 

I also tried to destroy all the colshapes but it didn't work either:

function destruirColisiones (source) 
    accountname = getAccountName (getPlayerAccount(source)) 
    if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "Admin" ) ) then 
        g_Colshapes = {} 
        local colisiones = getElementsByType("colshape") 
        for i,k in pairs ( colisiones ) do 
            destroyElement( k ) 
        end 
        outputChatBox (getPlayerName (source).." #ffffffhas disabled race pickups.",root,255,255,255,true) 
    else 
        outputChatBox("#ABCDEF* You are not a admin.",source,171,205,239,true) 
    end 
end 
addCommandHandler("dp", destruirColisiones)  

Is there another way of destroy the element or disable (the colision for example) of the pickups?

Edited by Guest
Link to comment
function destroyPickups() 
    local objects = getElementsByType("pickup") 
    for i, k in ipairs(objects) do 
        if (getResourceName(getElementID(getElementParent(getElementParent(k)))) == "race") then 
            destroyElement(k) 
        end 
    end 
end 
addCommandHandler("destroypicks", destroyPickups) 

Try this. It checks if the resource a pickup belongs to is the race element. I'm sure you could do this more efficiently by looping through the children of the race resource, like this (untested):

function destroyPickups() 
    local pickups = getElementChildren(getElementChildren(getResourceFromName("race")), "pickup") 
    for i, k in ipairs(pickups) do 
        destroyElement(k) 
    end 
end 
addCommandHandler("destroypicks", destroyPickups) 

Link to comment
function destroyPickups() 
    local objects = getElementsByType("pickup") 
    for i, k in ipairs(objects) do 
        if (getResourceName(getElementID(getElementParent(getElementParent(k)))) == "race") then 
            destroyElement(k) 
        end 
    end 
end 
addCommandHandler("destroypicks", destroyPickups) 

Try this. It checks if the resource a pickup belongs to is the race element. I'm sure you could do this more efficiently by looping through the children of the race resource, like this (untested):

function destroyPickups() 
    local pickups = getElementChildren(getElementChildren(getResourceFromName("race")), "pickup") 
    for i, k in ipairs(pickups) do 
        destroyElement(k) 
    end 
end 
addCommandHandler("destroypicks", destroyPickups) 

Didn't work either :/ . I think the only one option that I can use is disable the pickups as this post says: https://forum.multitheftauto.com/viewtopic.php?f=108&t=50029

Link to comment

Not tested, hope it'll work :)

-- race_client.lua 
function hidePickups(pickupType) 
    -- g_Pickups defined in race_client.lua, so add this code into race_client.lua 
    for colShape, data in pairs(g_Pickups) do 
        if data.type == tostring(pickupType) then 
            setElementPosition(colShape, 0, 0, -9999) -- hide colshape 
            setElementPosition(data.object, 0, 0, -9999) -- hide object 
        end 
    end 
end 
addEvent("hidePickups", true) 
addEventHandler("hidePickups", resourceRoot, hidePickups) 

and for any server.lua

-- SERVER.LUA 
-- USAGE: 
-- /destroypickups  
  
-- PICKUP TYPES: repair|nitro|vehiclechange 
  
-- Example usage: 
-- /destroypickups repair 
-- /destroypickups nitro 
-- /destroypickups vehiclechange 
function triggerIt(thePlayer, cmd, pickupType) 
    if type(tostring(pickupType)) == "string" then 
        triggerClientEvent("hidePickups", root, pickupType) 
    end 
end 
addCommandHandler("destroypickups", triggerIt) 

Link to comment
Not tested, hope it'll work :)
-- race_client.lua 
function hidePickups(pickupType) 
    -- g_Pickups defined in race_client.lua, so add this code into race_client.lua 
    for colShape, data in pairs(g_Pickups) do 
        if data.type == tostring(pickupType) then 
            setElementPosition(colShape, 0, 0, -9999) -- hide colshape 
            setElementPosition(data.object, 0, 0, -9999) -- hide object 
        end 
    end 
end 
addEvent("hidePickups", true) 
addEventHandler("hidePickups", resourceRoot, hidePickups) 

and for any server.lua

-- SERVER.LUA 
-- USAGE: 
-- /destroypickups  
  
-- PICKUP TYPES: repair|nitro|vehiclechange 
  
-- Example usage: 
-- /destroypickups repair 
-- /destroypickups nitro 
-- /destroypickups vehiclechange 
function triggerIt(thePlayer, cmd, pickupType) 
    if type(tostring(pickupType)) == "string" then 
        triggerClientEvent("hidePickups", root, pickupType) 
    end 
end 
addCommandHandler("destroypickups", triggerIt) 

OMG this works exactly as I wanted! Thank you so much! :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...