Jump to content

next and previous weapon


MultiNo

Recommended Posts

"onPlayerWeaponSwitch" will not return the next weapon.

You can use these functions:

Client

function getPreviousWeapon() 
    local tempSlot = {} 
    local curSlot = getPedWeaponSlot(localPlayer) 
    if (curSlot == 0) and (getPedWeapon(localPlayer) == 0 or getPedWeapon(localPlayer) == 1) then 
        curSlot = 13 
    end 
     
    tempSlot["ID"] = 12 + 1 
    repeat 
        tempSlot["ID"] = tempSlot["ID"]-1 
    until (tempSlot["ID"] < curSlot) and not (tempSlot["ID"] ~= 0 and getPedWeapon(localPlayer, tempSlot["ID"]) == 0) 
    return getPedWeapon(localPlayer, tempSlot["ID"]) 
end 
  
function getNextWeapon() 
    local tempSlot = {} 
    local curSlot = getPedWeaponSlot(localPlayer) 
    if (curSlot == 12) then 
        curSlot = - 1 
    end 
     
    tempSlot["ID"] = - 1 
    repeat 
        tempSlot["ID"] = tempSlot["ID"] + 1 
        if tempSlot["ID"] == 13 then 
            tempSlot["ID"] = -1 
            curSlot = -1 
        end 
    until (tempSlot["ID"] > curSlot) and not (tempSlot["ID"] ~= 0 and getPedWeapon(localPlayer, tempSlot["ID"]) == 0) 
    return getPedWeapon(localPlayer, tempSlot["ID"]) 
end 

I don't know if it's the best way to do that, but it should work without problems.

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