Raised This Month: $32 Target: $400
 8% 

[SNIPPET] CS:S On-Player Weapons Hide/Show


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
psychonic

BAFFLED
Join Date: May 2008
Old 03-05-2011 , 13:07   [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #1

This has come up a couple times before and once again recently in irc. I don't recall there ever being an answer posted, so, this is how you can hide/show the on-player weapons/nades in CS:S

There is a netprop, m_iAddonBits, that controls which items to show on a player. It seems that entities are then created for them clientside and attached, which is why people always had trouble finding them serverside.

m_iAddonBits gets reset on every PostThink so the PostThinkPost hook in SDK Hooks is needed.

Code:
#define CSAddon_NONE            0 #define CSAddon_Flashbang1      (1<<0) #define CSAddon_Flashbang2      (1<<1) #define CSAddon_HEGrenade       (1<<2) #define CSAddon_SmokeGrenade    (1<<3) #define CSAddon_C4              (1<<4) #define CSAddon_DefuseKit       (1<<5) #define CSAddon_PrimaryWeapon   (1<<6) #define CSAddon_SecondaryWeapon (1<<7) #define CSAddon_Holster         (1<<8)

Code used to test:

Code:
#include <sourcemod> #include <sdkhooks> new g_bits[MAXPLAYERS+1]; public OnPluginStart() {     RegConsoleCmd("addbit", addbit);     RegConsoleCmd("removebit", removebit);         for (new i = 1; i <= MaxClients; i++)     {         if (IsClientInGame(i))             OnClientPutInServer(i);     } } public OnClientPutInServer(client) {     SDKHook(client, SDKHook_PostThinkPost, OnPostThinkPost); } public Action:addbit(client, argc) {     decl String:arg1[16];     GetCmdArg(1, arg1, sizeof(arg1));         g_bits[client] |= (1<<StringToInt(arg1));         return Plugin_Handled; } public Action:removebit(client, argc) {     decl String:arg1[16];     GetCmdArg(1, arg1, sizeof(arg1));         g_bits[client] &= ~(1<<StringToInt(arg1));         return Plugin_Handled; } public OnPostThinkPost(client) {     SetEntProp(client, Prop_Send, "m_iAddonBits", g_bits[client]); }

Edit: As blodia has pointed out in his post linked below, you can manually set values for the primary and secondary weapon addons with the following:
Code:
SetEntProp(client, Prop_Send, "m_iPrimaryAddon", weaponid); SetEntProp(client, Prop_Send, "m_iSecondaryAddon", weaponid);

Here are a full list of CS:S weapon ids:
Code:
enum {     CS_WEAPON_NONE,     CS_WEAPON_P228,     CS_WEAPON_GLOCK,     CS_WEAPON_SCOUT,     CS_WEAPON_HEGRENADE,     CS_WEAPON_XM1014,     CS_WEAPON_C4,     CS_WEAPON_MAC10,     CS_WEAPON_AUG,     CS_WEAPON_SMOKEGRENADE,     CS_WEAPON_ELITE,     CS_WEAPON_FIVESEVEN,     CS_WEAPON_UMP45,     CS_WEAPON_SG550,     CS_WEAPON_GALIL,     CS_WEAPON_FAMAS,     CS_WEAPON_USP,     CS_WEAPON_AWP,     CS_WEAPON_MP5NAVY,     CS_WEAPON_M249,     CS_WEAPON_M3,     CS_WEAPON_M4A1,     CS_WEAPON_TMP,     CS_WEAPON_G3SG1,     CS_WEAPON_FLASHBANG,     CS_WEAPON_DEAGLE,     CS_WEAPON_SG552,     CS_WEAPON_AK47,     CS_WEAPON_KNIFE,     CS_WEAPON_P90,     CS_WEAPON_SHIELD,     CS_WEAPON_KEVLAR,     CS_WEAPON_ASSAULTSUIT,     CS_WEAPON_NIGHTVISION }

Last edited by psychonic; 03-15-2011 at 11:05.
psychonic is offline
blodia
Veteran Member
Join Date: Sep 2009
Location: UK
Old 03-05-2011 , 20:32   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #2

i posted similar info here http://forums.alliedmods.net/showpos...9&postcount=14.

i couldn't be bothered to code a snippet so good job lol.
blodia is offline
Martin
BANNED
Join Date: Mar 2009
Location: China
Old 08-13-2011 , 10:33   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #3

It's Only Support SDKHooks??
I have tried I used Hooks in Sourcemod1.1, And it was no effect.

Martin is offline
Send a message via ICQ to Martin
psychonic

BAFFLED
Join Date: May 2008
Old 08-13-2011 , 10:34   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #4

Quote:
Originally Posted by Martin View Post
It's Only Support SDKHooks??
I have tried I used Hooks in Sourcemod1.1, And it was no effect.

SourceMod 1.1 ? That doesn't even still run on current games.
psychonic is offline
Martin
BANNED
Join Date: Mar 2009
Location: China
Old 08-15-2011 , 02:28   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #5

PHP Code:
#include <sourcemod>
#include <hooker>
public Plugin:myinfo 
{
 
name "New Plugin",
 
author "Unknown",
 
description "<- Description ->",
 
version "1.0",
 
url "<- URL ->"
}
#define CSAddon_NONE            0
#define CSAddon_Flashbang1      (1<<0)
#define CSAddon_Flashbang2      (1<<1)
#define CSAddon_HEGrenade       (1<<2)
#define CSAddon_SmokeGrenade    (1<<3)
#define CSAddon_C4              (1<<4)
#define CSAddon_DefuseKit       (1<<5)
#define CSAddon_PrimaryWeapon   (1<<6)
#define CSAddon_SecondaryWeapon (1<<7)
#define CSAddon_Holster         (1<<8) 

public OnPluginStart()
{
 
RegisterHook(HK_ClientPostThink,FW_PostThink);
}
public 
Action:FW_PostThink(client)
{
 
 if(
IsPlayerAlive(client))
 {
  
SetEntProp(clientProp_Send"m_iAddonBits",CSAddon_NONE );
 }
}
 
public 
OnClientPutInServer(client)
{
    
HookEntity(HKE_CCSPlayerclient);
}
public 
OnClientDisconnect(client)
{
    
UnHookPlayer(HKE_CCSPlayerclient);

I tried Hooker's HK_ClientPostThink and HK_ClientPreThink. I found it's not run m_iAddonBits, It can't hide the weapons.Or It's not run for BOT or Anyother reason ?。。
Martin is offline
Send a message via ICQ to Martin
psychonic

BAFFLED
Join Date: May 2008
Old 08-15-2011 , 08:45   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #6

Quote:
Originally Posted by Martin View Post
PHP Code:
#include <sourcemod>
#include <hooker>
public Plugin:myinfo 
{
 
name "New Plugin",
 
author "Unknown",
 
description "<- Description ->",
 
version "1.0",
 
url "<- URL ->"
}
#define CSAddon_NONE            0
#define CSAddon_Flashbang1      (1<<0)
#define CSAddon_Flashbang2      (1<<1)
#define CSAddon_HEGrenade       (1<<2)
#define CSAddon_SmokeGrenade    (1<<3)
#define CSAddon_C4              (1<<4)
#define CSAddon_DefuseKit       (1<<5)
#define CSAddon_PrimaryWeapon   (1<<6)
#define CSAddon_SecondaryWeapon (1<<7)
#define CSAddon_Holster         (1<<8) 

public OnPluginStart()
{
 
RegisterHook(HK_ClientPostThink,FW_PostThink);
}
public 
Action:FW_PostThink(client)
{
 
 if(
IsPlayerAlive(client))
 {
  
SetEntProp(clientProp_Send"m_iAddonBits",CSAddon_NONE );
 }
}
 
public 
OnClientPutInServer(client)
{
    
HookEntity(HKE_CCSPlayerclient);
}
public 
OnClientDisconnect(client)
{
    
UnHookPlayer(HKE_CCSPlayerclient);

I tried Hooker's HK_ClientPostThink and HK_ClientPreThink. I found it's not run m_iAddonBits, It can't hide the weapons.Or It's not run for BOT or Anyother reason ?。。
Hooker hasn't worked on CS:S for a long time. You should be using SDK Hooks 2. If there's a problem, maybe you should make sure that Steam has it fully up to date.
psychonic is offline
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-19-2011 , 20:03   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #7

it looks like it WORKS! iv tried so many times before....

will be integrated in to war3source invis system

video
http://www.youtube.com/watch?v=7aFZT...el_video_title
__________________
War3:Source Developer
"Your CPU is just a bunch of Muxes"

Last edited by DarkEnergy; 08-19-2011 at 20:12.
DarkEnergy is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 09-02-2016 , 10:55   Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
Reply With Quote #8

How do to a player with the flag B saw the gun opponents?
Qes 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 10:16.


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