Under the button "1" I mean the choice of the primary weapon. (1-primary, 2-secondary, 3- knife and so forth).
Do you think it's more reliable to handle button pressing than to catch the weapon slot selection event?
unfortunally client side commands slot1, slot2 etc. etc. not work on server.
It depends how complicated your backbag system goes, you maybe end with combine both methods...
Then there is SDKHooks types to get weapon equip, switch, drop action.
Greetings.
As a participant in ElectricStalin's project, i would like to share some new data.
Due to lack of instruments in SourcePawn for creating proper inventory (classes, string input/output for functions), we spawn entities of weapons, then keep those entities out of player's sight somewhere on the map. Since we use Valve maps (verifeid workshop maps too, the point is: "non-custom") we rejected the idea to create container on map for weapon entities.
Slowly getting to the point.
During weapon swap we teleport weapon entities between buffer point and client's hands. In some cases a duped weapon entity flies through map from buffer point to player in addition to teleporting. Not every map object cen stop such ghost weapon.
Futhermore, if other player catches such bird and then tries to use it at the same time the weapon's owner uses the real copy of the weapon, this crushes server at "OnPlayerRunCmd".
*edit
I made one sample... not perfect tough. Csgo
This handle only primary and secondary weapons.
-To store weapon in backbag, swap weapon from ground ("E" button - use)
- you may see flash of dropping weapon on ground , but it should be invisible after 5 sec.
- After collecting weapons with swap method, use "TAB" button - score
this change your weapon from backbag. You may hear dropping weapon and falsh of it, but it still in your backbag.
- These weapons stored in backbag, are actually hidden with command "DisableDraw" and disabled for pickup by players "m_bCanBePickedUp"
for(int i = 1; i <= MaxClients; i++) { if(IsClientInGame(i)) OnClientPutInServer(i); } }
public Action CmdDropCB(int client, const char[] command, int arg) { bCmdDrop[client] = true; RequestFrame(CmdDropReset, client);
return Plugin_Continue; }
public void CmdDropReset(any data) { bCmdDrop[data] = false; }
public void OnClientPutInServer(int client) { if(hBackbag[client] != null) delete hBackbag[client];
hBackbag[client] = new ArrayList(32); SDKHookEx(client, SDKHook_WeaponDropPost, WeaponDropPost); //drop }
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2]) { static int sbuttons[MAXPLAYERS+1];
public void WeaponDropPost(int client, int weapon) { if(weapon == -1) return;
// player drop weapon command if(bCmdDrop[client]) { return; }
// Works only after few seconds of drop DispatchKeyValue(weapon, "OnUser1", "!self,DisableDraw,,8,-1"); DispatchKeyValue(weapon, "OnUser1", "!self,DisableDraw,,3,-1"); DispatchKeyValue(weapon, "OnUser1", "!self,DisableDraw,,2,-1"); DispatchKeyValue(weapon, "OnUser1", "!self,DisableDraw,,1,-1"); AcceptEntityInput(weapon, "FireUser1"); AcceptEntityInput(weapon, "DisableDraw");
Yes) Player can carry many weapons. In clientsWeapon[][] i store indexes. And player can scroll weapons by pressing "1".
what your doing won't work, u have to detect the last weapon in a given slot that your in, within onplayerruncmd when it detects a change in what u last selected, give the next weapon in your array to the player, this will allow u too press the 1 key to cycle the weapons you have. I do this in my l4d2 primaries plugin.
Last edited by MasterMind420; 10-31-2017 at 20:14.
Your crash in game code far away from OnPlayerRunCmd, I doubt it is even related.
You can't just latch onto the first thing that you recognise, especially when it is just a hook stub.
Frames are exponentially less relevant the further they are from the top of the stack.
EDIT: The fatal error that caused the crash is "CLagCompensationManager::StartLagCompensatio n with NULL CUserCmd!!!"
Whch is a classic one and the SDK actually has a comment blaming what you're doing:
Code:
// This can hit if m_hActiveWeapon incorrectly gets set to a weapon not actually owned by the local player
// (since lag comp asks for the GetPlayerOwner() which will have m_pCurrentCommand == NULL,
// not the player currently executing a CUserCmd).