So i have a nextbot that holds a gun, but the problem is, if he comes into close range of myself or another player, they can take the bot’s weapon from his hands, as if it were a dropped weapon on the ground. Because my bot’s code needs the weapon to reference in order to attack, so it derps up.
I can override this by allowing it to spawn a weapon each time, but it still cannot come close to the player without losing it again, causing it to endlessly chase someone, lose it’s weapon, spawn another, and repeat.
Humble is right. Any gun that is about to be picked up goes through PlayerCanPickupWeapon. Even when a weapon is ply:Give( )'ed.
Depending how the weapon is being held by the bot, you could check to make sure the weapon is valid, and the weapon is not parented to an entity, or doesn’t have some var attached to it.
If you’re coding a gamemode, GM:functionname() functions go in code that runs while the gamemode is initializing (such as the init.lua of the whole gamemode).
Many gamemode functions are also gamemode hook functions. Such as PlayerCanPickupWeapon.
If you want to add code to control gamemode hook function behavior, you can override the gamemode’s default definition by creating a hook to it, at any time.
[lua]hook.Add(“PlayerCanPickupWeapon”,“mycustomhookreferencename”,function()
–your code here
end)[/lua]