Checking if a player has a gun.

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
SA007
Lance Corporal
Posts: 24
Joined: Thu Sep 03, 2009 10:17 pm

Checking if a player has a gun.

Post 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.
HeavenBound
Colour Sergeant
Posts: 85
Joined: Thu Sep 11, 2008 12:55 am

Post 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?
HeavenBound

I'm new at this :)
SA007
Lance Corporal
Posts: 24
Joined: Thu Sep 03, 2009 10:17 pm

Post 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.
HeavenBound
Colour Sergeant
Posts: 85
Joined: Thu Sep 11, 2008 12:55 am

Post 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 
HeavenBound

I'm new at this :)
SA007
Lance Corporal
Posts: 24
Joined: Thu Sep 03, 2009 10:17 pm

Post 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.
HeavenBound
Colour Sergeant
Posts: 85
Joined: Thu Sep 11, 2008 12:55 am

Post 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
HeavenBound

I'm new at this :)
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Yah unfortunately there is no way to retrieve the items in the player's inventory via script.
Image
Post Reply