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

How to check if player is firing weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Unreal1
AlliedModders Donor
Join Date: Dec 2010
Old 12-22-2012 , 15:37   How to check if player is firing weapon
Reply With Quote #1

Hello! I wanted to make a plugin that is an AFK manager, but instead of checking a players location to set them as AFK, it checks if a player has fired a weapon. Is this possible?
Unreal1 is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 12-22-2012 , 15:49   Re: How to check if player is firing weapon
Reply With Quote #2

Now this is for CS:S, but it should work on other games (not TF2 though, I don't think).
You could make a global array of ints that stores the time at which a client last fired his weapon, then compare it with the current time and do the magic.
Something like:
PHP Code:
new g_iClientLastWeaponShoot[MAXPLAYERS 1];
public 
OnPluginStart()
{
    
HookEvent("weapon_fire"Event_WeaponFire);
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    
g_iClientLastWeaponShoot[GetClientOfUserId(GetEventInt(event"userid"))] = 0;
}

public 
Action:Event_WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
g_iClientLastWeaponShoot[client] != 0)
    {
        if (
GetTime() - g_iClientLastWeaponShoot[client] >= 3)
        {
            
KickClient(client);
        }
    }

This is very simple, but it should get the idea across.
__________________
Need help? PM me or add me on Steam.
My Steam




Quote:
Originally Posted by Rp.KryptoNite View Post
For some reason his Plugin never worked for me ,
@credits were added
im not stealing any plugins dude its my THING
minimoney1 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-22-2012 , 17:44   Re: How to check if player is firing weapon
Reply With Quote #3

The weapon_fire event is CS-specific.

It sounds like you don't actually need to know that they fired, just that they pushed their attack button/key.

You can use the OnPlayerRunCommand forward to check for any buttons being held down (including "IN_ATTACK") or for mouse movement via the view angles.
psychonic 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 13:50.


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