Hello,
I've been using the folowing code to get a player's id when a weapon deploy is registered
PHP Code:
...
RegisterHam(Ham_Item_Deploy, szWeaponName, "Ham_Item_Deploy_hook", 0)
...
public Ham_Item_Deploy_hook(ent)
{
new userid = pev(ent, pev_owner)
// working with the user id
//if (...
}
When testing with bots i noticed they were causing "index out of bounds" errors on the if statement and after some testing i figured out why:
Apparently it takes some time for pev_owner to update.
If a player using _cl_autowepswitch 1 is picking up a weapon from the ground pev_owner will still be set to the entity id when the function is called. I guess a weapon on the ground is it's own owner and therefore pev_owner = entity id.
So my function will give me invalid user ids.
I've been trying to use set_task(1.0,...) to force a little pause and give it time to update but you can still get index out of bounds if you spam dropping weapons while facing a wall.
Is there any better way to get the player id?