AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding Entity (https://forums.alliedmods.net/showthread.php?t=187948)

Waleed 06-20-2012 07:09

Finding Entity
 
How to find which weapon user is holding on Ham_Spawn?
If he is holding "m4a1" or any other weapon,then implement this:

PHP Code:

if(cs_get_user_bp_ammo(id) < 20)
{

client_print(id,print_chat,"[Trooper] You have low m4a1/weapon ammo,Becareful")



Can I use this?

PHP Code:

if(cs_get_weapon_id(id) == 22//22 for m4a1 
{
if(
cs_get_user_bp_ammo(id) < 20)
{

client_print(id,print_chat,"[Trooper] You have low m4a1/weapon ammo,Becareful")

}




Napoleon_be 06-20-2012 07:16

Re: Finding Entity
 
RegisterHam(Ham_Spawn, "player, "Function", 1)

Be careful with your check. It will print your message 20 times since you check if your ammo is lower than 20. I'd rather use == 20 or == 19 in your case.

Waleed 06-20-2012 07:23

Re: Finding Entity
 
Quote:

Originally Posted by Napoleon_be (Post 1732308)
RegisterHam(Ham_Spawn, "player, "Function", 1)

Be careful with your check. It will print your message 20 times since you check if your ammo is lower than 20. I'd rather use == 20 or == 19 in your case.

I think its not going to check it 20 times,Instead it will check if weapon index is 22 //m4a1
then check ammo if lower than 20,Executes Client_Print

Backstabnoob 06-20-2012 07:30

Re: Finding Entity
 
No, it will not print 20 times.

Napoleon_be 06-20-2012 07:31

Re: Finding Entity
 
I see, my bad.
Anyways, Ham_Spawn would do or logevent round start.

Waleed 06-20-2012 11:12

Re: Finding Entity
 
Then,Answer my thread.
How would I do that?

<VeCo> 06-20-2012 11:14

Re: Finding Entity
 
Your code is wrong. The check should be:
PHP Code:

if(get_user_weapon(id) == CSW_M4A1 && cs_get_user_bpammo(id,CSW_M4A1) < 20


Waleed 06-20-2012 11:47

Re: Finding Entity
 
I thought in index I should use weapon index not there name O_O :D
Lets see if it works

<VeCo> 06-20-2012 11:49

Re: Finding Entity
 
cs_get_weapon_id gets the CSW_* index of the provided weapon entity id, not the player id. Use get_user_weapon if you want to check the weapon that the player is currently holding.

ConnorMcLeod 06-20-2012 12:41

Re: Finding Entity
 
No shouldn't check agains get_user_weapon, because player can hold his knife when he respawn.

If you want to check few specific weapons, you can check user_has_weapon().
If you want to check more than few, then use get_user_weapons and loop through retrieved list.

You can also use the method i used in there : http://forums.alliedmods.net/showthread.php?p=553846
But make sure you fully understand the code (and for any method you gonna use).


All times are GMT -4. The time now is 06:18.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.