Page 1 of 1

Checking if a player has a gun.

Posted: Sun Oct 11, 2009 2:34 pm
by SA007
I'm busy building a pistol-only area in a map and I've into a problem.

As soon as you enter the area I give a 'useweaponclass pistol'.
This works fine, but if the player dropped its pistol this doesn't do anything.

If the player doesn't have a pistol I want to force the player to holster the weapon.
But how do I find if a player has a weapon?
I can't find any link to the inventory besides 'listinventory' which doesn't seem to do the job I want it to do.

Yes, I know there is a way to detect which gun someone is using using weaponcommand targetname. But this only gives the weapon you are using which is useless if the weapon is holstered.


Btw, I also have a script in RAISE_WEAPON to prevent switching to != pistol.

Posted: Sun Oct 11, 2009 6:00 pm
by HeavenBound
If they don't have a pistol, why not give them one? And if it's a pistol only part of the map, do a take all, then give em a pistol.... Yes?

Posted: Sun Oct 11, 2009 6:53 pm
by SA007
I'm doing that now, but its kind of awkward if you dump the gun that you get a new one. That, plus new ammo.

Takeall is not an option because the rest of the guns are used again if you leave that area (its just 1 'room' in the level)

I think its strange that there are plenty of use/give/etc command (found at least 3 ways to give or switch to a gun) but none apparent one that can check if there is a weapon.

Posted: Sun Oct 11, 2009 8:14 pm
by HeavenBound
Well here's your script:

Code: Select all

main:

	self weaponcommand dual targetname ("weapon" + self.entnum)
	local.weapon = $("weapon" + self.entnum )

	if(local.weapon != NULL)
	{
		self.weapon = $("weapon" + self.entnum ).model
		local.weapon targetname ""
	}
	else
	{
		self.weapon = "models/weapons/unarmed.tik"
	}

end 

Posted: Sun Oct 11, 2009 8:37 pm
by SA007
HeavenBound wrote:Well here's your script:

...
Read the second line from the bottom again.

I already use that script, but it only gives me the active weapon, I'm not interested in that.
What I'm interested in is if the player has a pistol or not.

If you run the game, and type listinventory you get the info I want, but for some reason that info cannot be reached from the script.
I can run listinventory, but getting the info in the console is pointless.

Posted: Mon Oct 12, 2009 1:57 am
by HeavenBound
oh. lol

then use an if statement. As you said, if they are using a different weapon, holster it and give them a pistol

Posted: Wed Oct 14, 2009 7:21 am
by jv_map
Yah unfortunately there is no way to retrieve the items in the player's inventory via script.