Raised This Month: $51 Target: $400
 12% 

Getting Entity Index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SamuraiBarbi
Senior Member
Join Date: Aug 2006
Location: United States
Old 09-06-2007 , 20:49   Getting Entity Index
Reply With Quote #1

Is there a command I can use to get the entity index of a thrown hand grenade?

I can do this in eventscripts and es_tools using

es_setinfo grenid 0
es_getentityindex grenid hegrenade_projectile

Anywho, I was wondering if there is an equivalent in Sourcemod because it would be really useful to me.

EDIT: After some looking around through includes I found a function ( FindEntityByClassname ) that I think might be what I need but I can't figure out how to use it. When I try using this in a hooked weapon_fire event I end up getting a tag mismatch error.


new String:attackerWeapon[30];
GetEventString(event, "weapon", attackerWeapon, 29);

if(StrEqual(attackerWeapon,"hegrenade"))
{

new grenid = FindEntityByClassname(-1, "hegrenade_projectile");
if (grenid > -1)
{

... do stuff

}
}

Any ideas?

Last edited by SamuraiBarbi; 09-06-2007 at 21:29.
SamuraiBarbi is offline
Send a message via AIM to SamuraiBarbi Send a message via MSN to SamuraiBarbi Send a message via Yahoo to SamuraiBarbi
dalto
Veteran Member
Join Date: Jul 2007
Old 09-06-2007 , 21:35   Re: Getting Entity Index
Reply With Quote #2

I think you could do this with the weapons extension. Like this.

Code:
public OnChangeActiveWeapon(client, oldWeapon, newWeapon)
{
    decl String:oldWeaponName[50];
    GetEdictClassname(oldWeapon, oldWeaponName, sizeof(oldWeaponName));
    if(oldWeapon && !newWeapon && !strcmp(oldWeaponName, "weapon_hegrenade"))
    {
        // oldWeapon is the ent index of an hegrenade
        // do what you need to do here
    }
}
EDIT: You would need to load the weapons extension to use this function.

Last edited by dalto; 09-06-2007 at 21:37.
dalto is offline
SamuraiBarbi
Senior Member
Join Date: Aug 2006
Location: United States
Old 09-06-2007 , 22:17   Re: Getting Entity Index
Reply With Quote #3

I'm not sure how that's supposed to work. maybe i just don't understand how that works. am i supposed to supply oldWeapon and newWeapon args to OnChangeActiveWeapon?

Also, if anyone knows how to use FindEntityByClassname and could give me an example I'd appreciate it. I'm very new to Sourcemod and am trying to avoid using extensions until I get a better grip on how to just code from vanilla Sourcemod.
SamuraiBarbi is offline
Send a message via AIM to SamuraiBarbi Send a message via MSN to SamuraiBarbi Send a message via Yahoo to SamuraiBarbi
patches11
Junior Member
Join Date: Aug 2007
Old 09-06-2007 , 22:47   Re: Getting Entity Index
Reply With Quote #4

OnChangeActiveWeapon is what's called a "forward". A forward is essentially an event listener, which other plugins (written in SourcePawn, the language of SourceMod) or extensions (written in C++) can call to communicate events and information about them. From what dalto is saying, there's an extension that allows you to monitor players' weapon changes using a forward. You could then make a global array to track all players' weapons.

Mind you, changing a weapon does not indicate the firing of said weapon. I don't know how one would go about doing that in HL2DM (my sole Source multiplayer game of interest), but in CSS the event name is weapon_fire, which contains the player that fired it and the weapon used. Look on the dev wiki: http://wiki.alliedmods.net/Events_(SourceMod_Scripting) and http://wiki.alliedmods.net/Game_Events_(Source)

The reason that using OnChangeActiveWeapon and oldweapon works I assume is because a player can only have one grenade.

Also, your code doesn't take into account that there might already be a grenade in flight when another is fired; if the newly fired grenade has a higher entity index than the first, only the old one will be processed.

Last edited by patches11; 09-06-2007 at 22:51.
patches11 is offline
pRED*
Join Date: Dec 2006
Old 09-06-2007 , 23:17   Re: Getting Entity Index
Reply With Quote #5

Have a play with this if you want.

It gets the thrown grenade (and also sets your view to that of the grenade)
Kinda lets of steer the grenade but nothing like the cs 1.6 version. Fail.
Attached Files
File Type: sp Get Plugin or Get Source (SteerNades.sp - 827 views - 2.3 KB)
pRED* is offline
dalto
Veteran Member
Join Date: Jul 2007
Old 09-06-2007 , 23:18   Re: Getting Entity Index
Reply With Quote #6

Quote:
Originally Posted by patches11 View Post
The reason that using OnChangeActiveWeapon and oldweapon works I assume is because a player can only have one grenade.
Thats part of it. Part of it is that OnChangeActiveWeapon does not do what you might think it does. It is only called in very specific circumstances, one of which is a thrown grenade. It is also called when a weapon is dropped.

The problem with using FindEntityByClassname is that it will find you A grenade, but it might not be the specific grenade you are looking for. One of the reasons your call is not working is because the class name of a grenade is "weapon_hegrenade", not "hegrenade_projectile".

EDIT: I didn't know that the fire_weapon was called when you threw a grenade that would be a much better way to do it. Then you would not be reliant on an extension.

EDIT2: It is worth noting that when you get the weapon name from an event it will be called "hegrenade" instead of "weapon_hegrenade"

Last edited by dalto; 09-06-2007 at 23:21.
dalto is offline
SamuraiBarbi
Senior Member
Join Date: Aug 2006
Location: United States
Old 09-07-2007 , 01:10   Re: Getting Entity Index
Reply With Quote #7

Quote:
Originally Posted by pRED* | NZ View Post
Have a play with this if you want.

It gets the thrown grenade (and also sets your view to that of the grenade)
Kinda lets of steer the grenade but nothing like the cs 1.6 version. Fail.
Thanks all of you for the great suggestions and helping me out with this. I've found that pRed's solution is much closer to what I'm used to ( coming from a lot of eventscripts experience ) and was more what I was looking for.
Much love, you guys kick ass!
SamuraiBarbi is offline
Send a message via AIM to SamuraiBarbi Send a message via MSN to SamuraiBarbi Send a message via Yahoo to SamuraiBarbi
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 23:31.


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