1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Other How can I check if a player has a weapon equipped serverside?

Discussion in 'Development' started by smacks balloon, Feb 7, 2017.

  1. Alright, this snippet detects whether a player has a pistol in their inventory. This code is being run server-side from an ent's init.lua

    Code:
    -- v is defined earlier in the file
    local inventory = v:GetInventory() 
    local contra = Clockwork.inventory:GetItemsByID(inventory,"weapon_pistol") 
    
    if (contra ~= {}) then
        Clockwork.player:NotifyAll("Faggot has pistol") -- debug
        Clockwork.player:NotifyAll(Clockwork.json:Encode(contra)) -- debug
    end
    
    I've been racking my brain trying to figure out how to detect if the pistol is simply sitting in the player's inventory or if it's equipped, and I can't figure it out. Can anyone point me in the right direction?
     
  2. duck

    duck Phant0m Legend

    Code:
    if (contra ~= {}) then
    That will never be false because a table is only equal to itself.
     
  3. Yeah, I realized that a few days ago, but that isn't the issue and it doesn't really have any effect on what I'm trying to do at the moment, so I just left it in. I'm trying to figure out how to check if an item is equipped, do you have anything that is more pertinent to my question?
     

Previous Readers (Total: 0)