Raised This Month: $ Target: $400
 0% 

Finding Entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-20-2012 , 07:09   Finding Entity
Reply With Quote #1

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")

}


__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]

Last edited by Waleed; 06-20-2012 at 07:13.
Waleed is offline
Send a message via Skype™ to Waleed
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-20-2012 , 07:16   Re: Finding Entity
Reply With Quote #2

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.
__________________

Last edited by Napoleon_be; 06-20-2012 at 07:17.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-20-2012 , 07:23   Re: Finding Entity
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
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
__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]
Waleed is offline
Send a message via Skype™ to Waleed
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-20-2012 , 07:30   Re: Finding Entity
Reply With Quote #4

No, it will not print 20 times.
Backstabnoob is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-20-2012 , 07:31   Re: Finding Entity
Reply With Quote #5

I see, my bad.
Anyways, Ham_Spawn would do or logevent round start.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-20-2012 , 11:12   Re: Finding Entity
Reply With Quote #6

Then,Answer my thread.
How would I do that?
__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]
Waleed is offline
Send a message via Skype™ to Waleed
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-20-2012 , 11:14   Re: Finding Entity
Reply With Quote #7

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
__________________
<VeCo> is offline
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-20-2012 , 11:47   Re: Finding Entity
Reply With Quote #8

I thought in index I should use weapon index not there name O_O
Lets see if it works
__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]

Last edited by Waleed; 06-20-2012 at 11:48.
Waleed is offline
Send a message via Skype™ to Waleed
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-20-2012 , 11:49   Re: Finding Entity
Reply With Quote #9

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.
__________________
<VeCo> is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-20-2012 , 12:41   Re: Finding Entity
Reply With Quote #10

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).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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