Jump to content

[QUESTION] Get the next and previous weapon


Dzsozi (h03)

Recommended Posts

Hello, I would like to make a custom weapon switching screen with dx functions and I would like to display the current weapon, the previous weapon and the next weapon after the current. My question is how I can make that possible and how can I draw these 3 weapons with dx?

I would like to make the script work like if you hold a button a panel appears and if you scroll you scroll to the next weapon, but you can see the weapon you had before on the previous slot. It's kinda hard to explain in words, but take a look at the gif I made:

sc1vVJI.gif

Hope you know now what I mean. So how can I do that? Is this possible?

Link to comment

Try this

  • Previous weapon
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"] = 13 
    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 
  • Next Weapon
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 

 

7 minutes ago, Dzsozi said:

Oh and one more thing I forgot: How can I get the ammo of the next and the previous weapons?

getPedTotalAmmogetPedAmmoInClip, getSlotFromWeapon

Edited by Walid
  • Like 1
  • Thanks 1
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...