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

Checking for silencer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Annihilator
Senior Member
Join Date: Nov 2006
Location: Lithuania
Old 07-09-2012 , 17:17   Checking for silencer
Reply With Quote #1

I've been trying to check if player is using an USP with a silencer on using this code:

Code:
FindSendPropOffs("CWeaponUSP","m_bSilencerOn") == 1
As you can guess, it doesnt work, so any ideas why or how should I do this check?
Annihilator is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 07-09-2012 , 17:47   Re: Checking for silencer
Reply With Quote #2

PHP Code:
new Ent = -1;
while ((
Ent FindEntityByClassname(Ent"weapon_usp")) != -1)
{
    if (
GetEntProp(EntProp_Send"m_bSilencerOn") == 1)
    {
        
// this USP has a silencer on
    
}

Assuming that works (I don't know anything about CS:S) you could do GetEntPropEnt(Ent, Prop_Send, m_hOwnerEntity) to find out who owns it. (m_hOwnerEntity is probably incorrect for CS:S)
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)

Last edited by MasterOfTheXP; 07-09-2012 at 17:47.
MasterOfTheXP is offline
TheAvengers2
BANNED
Join Date: Jul 2011
Old 07-10-2012 , 02:28   Re: Checking for silencer
Reply With Quote #3

Quote:
Originally Posted by MasterOfTheXP View Post
m_hOwnerEntity is probably incorrect for CS:S
Naw, it's valid.

Last edited by TheAvengers2; 07-10-2012 at 02:28.
TheAvengers2 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-10-2012 , 03:40   Re: Checking for silencer
Reply With Quote #4

If you want to get a player's weapon, you better start at the player, and iterate trough his weapons, and not iterate trough 4000 entities.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Annihilator
Senior Member
Join Date: Nov 2006
Location: Lithuania
Old 07-10-2012 , 06:16   Re: Checking for silencer
Reply With Quote #5

Well, I'll expand my problem a bit

I've been trying to hook OnTakeDamage and check if the one who dealt damage had a usp with a silencer equiped.

Trying to implement what you suggested I now have this:

PHP Code:
public Action:TakeDamageHook(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
    new 
Ent = -1;
    if((
victim 0) && (victim <= MaxClients) && (attacker 0) && (attacker <= MaxClients) && (IsClientInGame(victim)) && (IsClientInGame(attacker)) && (GetClientTeam(victim) == CS_TEAM_T) && (GetClientTeam(attacker) == CS_TEAM_CT))
    {
        
decl String:WeaponName[64];
        
GetClientWeapon(inflictorWeaponNamesizeof(WeaponName));
        while ((
Ent FindEntityByClassname(attacker"weapon_usp")) != -1)
        {
            if (
StrEqual(WeaponName"weapon_usp") && (GetEntProp(EntProp_Send"m_bSilencerOn") == 1)) //FindSendPropOffs("CWeaponUSP","m_bSilencerOn") == 1)
            
{
                
damage 0.0;
                return 
Plugin_Changed;
            }
        }
    }
    return 
Plugin_Continue;

Well, so far it just crashes the server when someone does dmg with a silenced usp

Well, I have never used FindEntityByClassname or GetEntProp so, I'm guessing the the fault lies there


Edit: Silly me, copied the "while" even when I didnt need it . Fixed and solved

T.y. for the help


Last edited by Annihilator; 07-10-2012 at 06:24.
Annihilator is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-10-2012 , 06:47   Re: Checking for silencer
Reply With Quote #6

yes, that's what I meant, you don't need the FindEntityByClassname function, just get the client's current weapon.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-10-2012 , 06:49   Re: Checking for silencer
Reply With Quote #7

You could use smlib's Client_GetActiveWeaponName() for example.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 07-10-2012 at 06:50.
berni is offline
Annihilator
Senior Member
Join Date: Nov 2006
Location: Lithuania
Old 07-10-2012 , 09:25   Re: Checking for silencer
Reply With Quote #8

Another question:

OnClientPutInServer(client)

Is it called only once, when a player enters a server, or every map change?
Annihilator is offline
Annihilator
Senior Member
Join Date: Nov 2006
Location: Lithuania
Old 07-10-2012 , 15:37   Re: Checking for silencer
Reply With Quote #9

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>

public Plugin:myinfo 
{
    
name "USP with silencer",
    
author "Uno",
    
description "",
    
version "1.0",
    
url ""
};

public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_OnTakeDamageTakeDamageHook);
}

public 
Action:TakeDamageHook(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weaponFloat:damageForce[3], Float:damagePosition[3])
{
    if((
victim 0) && (victim <= MaxClients) && (attacker 0) && (attacker <= MaxClients) && (IsClientInGame(victim)) && (IsClientInGame(attacker)) && (GetClientTeam(victim) == CS_TEAM_T) && (GetClientTeam(attacker) == CS_TEAM_CT))
    {
        if (
GetEntPropEnt(FindEntityByClassname(attacker"weapon_usp"), Prop_Send"m_bSilencerOn") == 1)
        {
            
damage 0.0;
            
PrintToChatAll("\x01Oh noes! \x03%N \x01shot \x04%N \x01!"attackervictim);
            return 
Plugin_Changed;
        }
    }
    return 
Plugin_Continue;

Works when testing on a small server, but doesn't work on a populated server.
No error logs.
Any ideas? :/
Annihilator is offline
TrueSurvivor
Member
Join Date: Jun 2010
Old 07-10-2012 , 16:24   Re: Checking for silencer
Reply With Quote #10

Quote:
Originally Posted by Annihilator View Post
Another question:

OnClientPutInServer(client)

Is it called only once, when a player enters a server, or every map change?
It disconnects and reconnects every client on Map Change, so it is called on every map change.
TrueSurvivor is offline
Reply


Thread Tools
Display Modes

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 07:47.


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