Skip to content

Commit

Permalink
Refactor to not hook mid-usermessage
Browse files Browse the repository at this point in the history
Fixes #14.
  • Loading branch information
nosoop committed Apr 5, 2021
1 parent bbddec7 commit db3cd71
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public void OnPluginStart() {
delete hGameConf;


HookUserMessage(GetUserMessageId("PlayerLoadoutUpdated"), OnPlayerLoadoutUpdated);
HookUserMessage(GetUserMessageId("PlayerLoadoutUpdated"), OnPlayerLoadoutUpdated,
.post = OnPlayerLoadoutUpdatedPost);

CreateVersionConVar("cwx_version", "Custom Weapons X version.");

Expand Down Expand Up @@ -228,9 +229,16 @@ Action EquipItemCmdTarget(int client, int argc) {
return Plugin_Handled;
}

int s_LastUpdatedClient;

Action OnPlayerLoadoutUpdated(UserMsg msg_id, BfRead msg, const int[] players,
int playersNum, bool reliable, bool init) {
int client = msg.ReadByte();
s_LastUpdatedClient = GetClientSerial(client);
}

void OnPlayerLoadoutUpdatedPost(UserMsg msg_id, bool sent) {
int client = GetClientFromSerial(s_LastUpdatedClient);
int playerClass = view_as<int>(TF2_GetPlayerClass(client));

for (int i; i < NUM_ITEMS; i++) {
Expand Down

0 comments on commit db3cd71

Please sign in to comment.