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

[TF2][SOLVED] Detect ammo pickup


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
=MaTi=
Member
Join Date: Jan 2008
Old 01-08-2010 , 11:35   [TF2][SOLVED] Detect ammo pickup
Reply With Quote #1

Is it possible to detect wether a client has touched an ammo pickup or the resupply cabinet? I've tried to use SDKHook_Touch from SDKHooks, but the problem is, it doesn't return the cliend index of a player that touched the item only the edict index of a touched entity.

What I'm trying to do, is to increase the max ammo reserves of some weapons, so if player picks up some ammo, I will manually set it to exceed the maximum value when needed.

Thanks in advance for any help!

Last edited by =MaTi=; 01-09-2010 at 20:54.
=MaTi= is offline
Pawn 3-pg
Senior Member
Join Date: Jul 2009
Old 01-08-2010 , 14:08   Re: [TF2] Detect ammo pickup
Reply With Quote #2

The resupply cabinet code you are looking for is here (post #4).
Edit: You may also be interested in the post_inventory_application event. It's what the Equipment Manager uses to detect when you touch a cabinet.

I'm successfully using SDKHooks to detect when a player touches a medpack, but I can't remember how to get the client from the entity and I don't have the plugin in front of me. If nobody else posts the answer, I'll look it up when I get home tonight.
Pawn 3-pg is offline
Damizean
SourceMod Donor
Join Date: Mar 2009
Old 01-08-2010 , 17:16   Re: [TF2] Detect ammo pickup
Reply With Quote #3

There was an usermessage for item pickup, but I don't remember if it fired for health or for ammunition. Use meta game to get the list of all the available usermessages.
__________________
Dat annoying guy
Damizean is offline
Send a message via AIM to Damizean Send a message via MSN to Damizean
Pawn 3-pg
Senior Member
Join Date: Jul 2009
Old 01-08-2010 , 23:38   Re: [TF2] Detect ammo pickup
Reply With Quote #4

This is what you need. Just change the item names from health kits to ammo packs.

PHP Code:
public OnPluginStart()
{
  
HookEntityOutput("item_healthkit_small",  "OnPlayerTouch",    EntityOutput_HealthKit);
  
HookEntityOutput("item_healthkit_medium""OnPlayerTouch",    EntityOutput_HealthKit);
  
HookEntityOutput("item_healthkit_full",   "OnPlayerTouch",    EntityOutput_HealthKit);
}

public 
EntityOutput_HealthKit(const String:output[], calleractivatorFloat:delay)
{
  
PrintToChatAll("Healthkit touched")
  if (
activator && activator <= GetMaxClients() && IsClientInGame(activator) && IsPlayerAlive(activator))
  {
    
RemoveEdict(caller);
//do stuff here
  
}

Pawn 3-pg is offline
=MaTi=
Member
Join Date: Jan 2008
Old 01-09-2010 , 06:03   Re: [TF2] Detect ammo pickup
Reply With Quote #5

Quote:
Originally Posted by Pawn 3-pg View Post
This is what you need. Just change the item names from health kits to ammo packs.

PHP Code:
public OnPluginStart()
{
  
HookEntityOutput("item_healthkit_small",  "OnPlayerTouch",    EntityOutput_HealthKit);
  
HookEntityOutput("item_healthkit_medium""OnPlayerTouch",    EntityOutput_HealthKit);
  
HookEntityOutput("item_healthkit_full",   "OnPlayerTouch",    EntityOutput_HealthKit);
}

public 
EntityOutput_HealthKit(const String:output[], calleractivatorFloat:delay)
{
  
PrintToChatAll("Healthkit touched")
  if (
activator && activator <= GetMaxClients() && IsClientInGame(activator) && IsPlayerAlive(activator))
  {
    
RemoveEdict(caller);
//do stuff here
  
}

It works, but it's fired only when player picks the medkit up. Is it possible to fire it whenever the medkit is touched, wether the player picks it up or not?
=MaTi= is offline
J-Factor
Junior Member
Join Date: Jul 2009
Old 01-09-2010 , 11:52   Re: [TF2] Detect ammo pickup
Reply With Quote #6

Quote:
Originally Posted by =MaTi= View Post
It works, but it's fired only when player picks the medkit up. Is it possible to fire it whenever the medkit is touched, wether the player picks it up or not?
Try the OnCacheInteraction output. I use it to simulate grabbable power-ups in one of my plugins without requiring the player to have a lack of ammo/health.

Last edited by J-Factor; 01-09-2010 at 11:52. Reason: changed event to output
J-Factor is offline
=MaTi=
Member
Join Date: Jan 2008
Old 01-09-2010 , 12:23   Re: [TF2] Detect ammo pickup
Reply With Quote #7

Quote:
Originally Posted by J-Factor View Post
Try the OnCacheInteraction output. I use it to simulate grabbable power-ups in one of my plugins without requiring the player to have a lack of ammo/health.
Thanks, it works. However, there is anotehr problem. If I remvoe medkit/ammo pack with RemoveEdict, the game won't detect that it's gone, and it won't reappear again until the next round. Is there a way to prevent it, or will I have to write my own code for respawning the removed pickups?
=MaTi= is offline
J-Factor
Junior Member
Join Date: Jul 2009
Old 01-09-2010 , 12:51   Re: [TF2] Detect ammo pickup
Reply With Quote #8

Edit: After thinking about it...

I'm not immediately aware of a way to cause a kit/pack to "despawn" such that it'll reappear where it should be. Simulating it manually shouldn't be too much trouble though.

1. Instead of using RemoveEdict simply use the inputs Disable/Enable/Toggle
2. Start a timer for 10 seconds (I think that's how long it takes)
3. Disable/Enable/Toggle again
4. Play the item spawn sound (look at the engineer dropping ammopack plugin for this)

Last edited by J-Factor; 01-09-2010 at 13:15.
J-Factor is offline
=MaTi=
Member
Join Date: Jan 2008
Old 01-09-2010 , 20:48   Re: [TF2] Detect ammo pickup
Reply With Quote #9

Quote:
Originally Posted by J-Factor View Post
1. Instead of using RemoveEdict simply use the inputs Disable/Enable/Toggle
2. Start a timer for 10 seconds (I think that's how long it takes)
3. Disable/Enable/Toggle again
4. Play the item spawn sound (look at the engineer dropping ammopack plugin for this)
I've tried that, but apparently, function EntityOutput_HealthKit is called even for a disabled entity, which resulted in timer being fired multiple times.
However, I've checked that dropping ammopack plugin, and apparently pickups can be simply spawned with DispatchSpawn, without any additional work required. The code below removes any touched medkit, and spawns a new one after 10 seconds.

PHP Code:
public OnPluginStart()
{
    
HookEntityOutput("item_healthkit_small",  "OnCacheInteraction",    EntityOutput_HealthKit);
    
HookEntityOutput("item_healthkit_medium""OnCacheInteraction",    EntityOutput_HealthKit);
    
HookEntityOutput("item_healthkit_full",   "OnCacheInteraction",    EntityOutput_HealthKit);
}

public 
EntityOutput_HealthKit(const String:output[], calleractivatorFloat:delay)
{
  
PrintToChatAll("Healthkit touched")
  if (
activator && activator <= GetMaxClients() && IsClientInGame(activator) && IsPlayerAlive(activator))
  {
        
decl Float:Pos[3];
        
GetEntPropVector(callerProp_Send"m_vecOrigin"Pos);
        
PrintToChat(activator"Pos: %f %f %f"Pos[0], Pos[1], Pos[2]);
        new 
Handle:dataPackHandle CreateDataPack();
        
decl String:classname[32];
        
GetEdictClassname(callerclassnamesizeof(classname));
        
RemoveEdict(caller);
        
WritePackString(dataPackHandleclassname);
        
WritePackFloat(dataPackHandlePos[0]);
        
WritePackFloat(dataPackHandlePos[1]);
        
WritePackFloat(dataPackHandlePos[2]);
        
CreateTimer(10.0Timer_MedkitdataPackHandle);
    }
}  

public 
Action:Timer_Medkit(Handle:timerany:dataPackHandle)
{
    
ResetPack(dataPackHandlefalse);
    
decl String:classname[32];
    
ReadPackString(dataPackHandleclassnamesizeof(classname));
    new 
Ammopack CreateEntityByName(classname);
    
DispatchSpawn(Ammopack);
    
decl Float:Pos2[3];
    
Pos2[0] = ReadPackFloat(dataPackHandle);
    
Pos2[1] = ReadPackFloat(dataPackHandle);
    
Pos2[2] = ReadPackFloat(dataPackHandle);
    
TeleportEntity(AmmopackPos2NULL_VECTORNULL_VECTOR);

Thanks a lot to all of you for the help! I would never have figured it out by myself.

Last edited by =MaTi=; 01-09-2010 at 20:58.
=MaTi= is offline
FoxMulder
Senior Member
Join Date: Jan 2009
Location: Orlando, FL
Old 10-22-2010 , 18:16   Re: [TF2][SOLVED] Detect ammo pickup
Reply With Quote #10

Resurrecting an old thread but I did a search for this.

Instead of removing the AmmoPack entity you can just do this. This will disable the health/ammo then enable it back in 8 seconds.

PHP Code:
/////////////////////////////////////////////////
//Toggle the healthkit so it turns off then //
//send "toggle" event to the event queue //
//so it reappears in a few seconds          //
////////////////////////////////////////////////

AcceptEntityInput(closestEntity,"toggle");
new 
String:addoutput[64];
 
Format(addoutputsizeof(addoutput), "OnUser1 !self:toggle::8.0:1");
SetVariantString(addoutput);
AcceptEntityInput(closestEntity"AddOutput");
AcceptEntityInput(closestEntity"FireUser1");
        
//emit Regenerate sound from health pack
EmitSoundToAll(SOUND_REGENERATE,closestEntity); 
__________________
FoxMulder 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 23:44.


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