AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] CS:S On-Player Weapons Hide/Show (https://forums.alliedmods.net/showthread.php?t=152165)

psychonic 03-05-2011 13:07

[SNIPPET] CS:S On-Player Weapons Hide/Show
 
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 }

blodia 03-05-2011 20:32

Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
 
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.

Martin 08-13-2011 10:33

Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
 
It's Only Support SDKHooks??
I have tried I used Hooks in Sourcemod1.1, And it was no effect.

:cry:

psychonic 08-13-2011 10:34

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

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

:cry:

SourceMod 1.1 ? That doesn't even still run on current games.

Martin 08-15-2011 02:28

Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
 
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 ?。。:wink:

psychonic 08-15-2011 08:45

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

Originally Posted by Martin (Post 1532823)
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 ?。。:wink:

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.

DarkEnergy 08-19-2011 20:03

Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
 
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

Qes 09-02-2016 10:55

Re: [SNIPPET] CS:S On-Player Weapons Hide/Show
 
How do to a player with the flag B saw the gun opponents?


All times are GMT -4. The time now is 05:08.

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