From 49dbd80fa4c7454630b7728c8319b53f9dac3c85 Mon Sep 17 00:00:00 2001 From: cypress Date: Thu, 28 Dec 2023 10:49:30 -0500 Subject: [PATCH] SERVER/CLIENT: Properly network player fields such as points and kills --- source/client/defs/custom.qc | 6 ++---- source/client/hud.qc | 35 ++++++++++++++++++------------ source/client/main.qc | 38 +++++++++++++++++---------------- source/server/clientfuncs.qc | 41 +++--------------------------------- source/server/player.qc | 19 ----------------- 5 files changed, 46 insertions(+), 93 deletions(-) diff --git a/source/client/defs/custom.qc b/source/client/defs/custom.qc index 9c918b6..c70bbfa 100644 --- a/source/client/defs/custom.qc +++ b/source/client/defs/custom.qc @@ -132,10 +132,6 @@ float interpolating2; float rounds; float perks; float rounds_change; - -float playerpoints[4]; // player point holders, player 1 points are index 0, player 2 at 1... -float playerkills[4]; // player kill holders, player 1 points are index 0, player 2 at 1... -string playernames[4]; // player name holders, player 1 name at index 0, player 2 at 1... float player_count; float score_show; @@ -173,6 +169,8 @@ float fade_time; float fade_type; .float stance; +.float points; +.float kills; float menu_initialized; diff --git a/source/client/hud.qc b/source/client/hud.qc index b7cdd57..91db7e7 100644 --- a/source/client/hud.qc +++ b/source/client/hud.qc @@ -310,15 +310,18 @@ void(float pwidth, float width, float height, float playernum) PointUpdate = void(float width, float height) HUD_Points = { - float pointlength = 0, increm = 10, i = 0, pointwidth = 0, x = 0; + float pointlength = 0, increm = 10, pointwidth = 0, x = 0; float backwidth = 0.8*width; vector TEXTCOLOR = '0 0 0'; - - for (i = 3; i >= 0; i = i - 1) + + for (int i = 3; i >= 0; i = i - 1) { - if (playerpoints[i] == -1) + float player_number = getplayerkeyfloat(i, "viewentity"); + entity client = findfloat(world, playernum, player_number); + + if (client == world || client.movetype == MOVETYPE_TOSS) continue; - + switch(i) { case 1: TEXTCOLOR = TEXT_LIGHTBLUE; break; case 2: TEXTCOLOR = TEXT_ORANGE; break; @@ -326,15 +329,15 @@ void(float width, float height) HUD_Points = default: TEXTCOLOR = [1, 1, 1]; break; } - pointwidth = stringwidth(ftos(playerpoints[i]), 0, [12, 12]); + pointwidth = stringwidth(ftos(client.points), 0, [12, 12]); x = (99 - pointwidth)/2 + GetUltraWideOffset(); if ((i + 1) == getstatf(STAT_PLAYERNUM)) { drawpic([3 + GetUltraWideOffset(), g_height - 97 - (i * 25)], "gfx/hud/moneyback.tga", [96, 24], [1,1,1], 1); - drawstring([x, g_height - 92 - (i * 25)], ftos(playerpoints[i]), [12, 12], TEXTCOLOR, 1, 0); + drawstring([x, g_height - 92 - (i * 25)], ftos(client.points), [12, 12], TEXTCOLOR, 1, 0); } else { drawpic([-7 + GetUltraWideOffset(), g_height - 97 - (i * 25)], "gfx/hud/moneyback_condensed.tga", [96, 24], [1,1,1], 1); - drawstring([x - 9, g_height - 92 - (i * 25)], ftos(playerpoints[i]), [12, 12], TEXTCOLOR, 1, 0); + drawstring([x - 9, g_height - 92 - (i * 25)], ftos(client.points), [12, 12], TEXTCOLOR, 1, 0); } PointUpdate(x + 70, width, height, i + 1); @@ -1392,7 +1395,10 @@ void() HUD_Scores = for (int i = 0; i < 4; i = i + 1) { - if (playerpoints[i] == -1) + float player_number = getplayerkeyfloat(i, "viewentity"); + entity client = findfloat(world, playernum, player_number); + + if (client == world || client.movetype == MOVETYPE_TOSS) break; switch(i) { @@ -1419,17 +1425,18 @@ void() HUD_Scores = } // Name - drawstring([g_width/2 - 245, 200 + (30 * i)], playernames[i], [12, 12], TEXTCOLOR, 1, 0); + string player_name = getplayerkeyvalue(i, "name"); + drawstring([g_width/2 - 245, 200 + (30 * i)], player_name, [12, 12], TEXTCOLOR, 1, 0); // Points - float point_width = stringwidth(ftos(playerpoints[i]), 0, [12, 12]); + float point_width = stringwidth(ftos(client.points), 0, [12, 12]); float point_x = ((g_width/2) - (point_width)/2) + 52; - drawstring([point_x, 200 + (30 * i)], ftos(playerpoints[i]), [12, 12], TEXTCOLOR, 1, 0); + drawstring([point_x, 200 + (30 * i)], ftos(client.points), [12, 12], TEXTCOLOR, 1, 0); // Kills - float kill_width = stringwidth(ftos(playerpoints[i]), 0, [12, 12]); + float kill_width = stringwidth(ftos(client.points), 0, [12, 12]); float kill_x = ((g_width/2) - (kill_width)/2) + 210; - drawstring([kill_x, 200 + (30 * i)], ftos(playerkills[i]), [12, 12], TEXTCOLOR, 1, 0); + drawstring([kill_x, 200 + (30 * i)], ftos(client.kills), [12, 12], TEXTCOLOR, 1, 0); } } } diff --git a/source/client/main.qc b/source/client/main.qc index 6ed9fda..23b2543 100644 --- a/source/client/main.qc +++ b/source/client/main.qc @@ -195,10 +195,6 @@ noref void() CSQC_WorldLoaded = setmodel(v2model,""); mzlflash.renderflags = vmodel.renderflags; mzlflash.origin = vmodel.origin + vmodel_muzzleoffset; - - playerpoints[1] = -1; - playerpoints[2] = -1; - playerpoints[3] = -1; Achievement_Init(); Init_Particles(); @@ -544,6 +540,8 @@ noref void(float isnew) CSQC_Ent_Update = self.drawmask = MASK_ENGINE; setmodel(self, "models/player.mdl"); } + + float old_points = self.points; self.origin_x = readcoord(); self.origin_y = readcoord(); @@ -558,8 +556,12 @@ noref void(float isnew) CSQC_Ent_Update = self.modelindex = readshort(); self.frame = readbyte(); self.movetype = readshort(); - self.flags = readfloat(); + self.flags = readshort(); self.stance = readbyte(); + self.points = readfloat(); // FIXME: this should be made a short, but I know we use price of 1 for some test maps, so I can't do /10 *10 shenanigans. + self.kills = readshort(); + + RegisterPointChange(self.points - old_points, self.playernum); if (self.movetype == MOVETYPE_TOSS) self.solid = SOLID_NOT; @@ -1457,20 +1459,20 @@ noref void() CSQC_Parse_Event = revive_icons[reviveoff_id].draw = false; active_revive_icons--; break; - case EVENT_POINTUPDATE: - float playernum = readbyte(); - float temppoints = readlong(); - RegisterPointChange(readlong(), playernum); - float tempkills = readlong(); - string tempname = readstring(); + // case EVENT_POINTUPDATE: + // float playernum = readbyte(); + // float temppoints = readlong(); + // RegisterPointChange(readlong(), playernum); + // float tempkills = readlong(); + // string tempname = readstring(); - switch(playernum) { - case 1: playerpoints[0] = temppoints; playerkills[0] = tempkills; playernames[0] = tempname; break; - case 2: playerpoints[1] = temppoints; playerkills[1] = tempkills; playernames[1] = tempname; break; - case 3: playerpoints[2] = temppoints; playerkills[2] = tempkills; playernames[2] = tempname; break; - case 4: playerpoints[3] = temppoints; playerkills[3] = tempkills; playernames[3] = tempname; break; - } - break; + // switch(playernum) { + // case 1: playerpoints[0] = temppoints; playerkills[0] = tempkills; playernames[0] = tempname; break; + // case 2: playerpoints[1] = temppoints; playerkills[1] = tempkills; playernames[1] = tempname; break; + // case 3: playerpoints[2] = temppoints; playerkills[2] = tempkills; playernames[2] = tempname; break; + // case 4: playerpoints[3] = temppoints; playerkills[3] = tempkills; playernames[3] = tempname; break; + // } + // break; case EVENT_BLACKOUT: fade_time = readbyte(); fade_type = readbyte(); diff --git a/source/server/clientfuncs.qc b/source/server/clientfuncs.qc index 2bcdf16..391c207 100644 --- a/source/server/clientfuncs.qc +++ b/source/server/clientfuncs.qc @@ -264,35 +264,6 @@ void(float broadcast_time, float type, string str) BroadcastMessage = #endif // FTE } -void(float playernum, float points, float am, float kills, string name, entity person) UpdatePlayerPoints = -{ -#ifdef FTE - - if (player_count == 0) { - WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); - WriteByte(MSG_MULTICAST, EVENT_POINTUPDATE); - WriteByte(MSG_MULTICAST, playernum); - WriteLong(MSG_MULTICAST, points); - WriteLong(MSG_MULTICAST, am); - WriteLong(MSG_MULTICAST, kills); - WriteString(MSG_MULTICAST, name); - msg_entity = person; - multicast('0 0 0', MULTICAST_ONE); - } - else { - WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET); - WriteByte(MSG_MULTICAST, EVENT_POINTUPDATE); - WriteByte(MSG_MULTICAST, playernum); - WriteLong(MSG_MULTICAST, points); - WriteLong(MSG_MULTICAST, am); - WriteLong(MSG_MULTICAST, kills); - WriteString(MSG_MULTICAST, name); - multicast('0 0 0', MULTICAST_ALL); - } - -#endif // FTE -} - void(float count) UpdatePlayerCount = { #ifdef FTE if (count == 0) @@ -567,14 +538,10 @@ float Player_SendEntity( entity ePVEnt, float flChanged ) { WriteShort( MSG_ENTITY, self.modelindex ); // Player Model WriteByte( MSG_ENTITY, self.frame ); // Player's Frame WriteShort( MSG_ENTITY, self.movetype ); // Player Movetype - WriteFloat( MSG_ENTITY, self.flags ); // Flags, important for physics + WriteShort( MSG_ENTITY, self.flags ); // Flags, important for physics WriteByte( MSG_ENTITY, self.stance ); // Player Stance - // WriteCoord( MSG_ENTITY, self.mins_x ); // Min Size X - // WriteCoord( MSG_ENTITY, self.mins_y ); // Min Size Y - // WriteCoord( MSG_ENTITY, self.maxs_z ); // Max Size Z - // WriteCoord( MSG_ENTITY, self.maxs_x ); // Max Size X - // WriteCoord( MSG_ENTITY, self.maxs_y ); // Max Size Y - // WriteCoord( MSG_ENTITY, self.maxs_z ); // Max Size Z + WriteFloat( MSG_ENTITY, self.points ); // Player Score + WriteShort( MSG_ENTITY, self.kills ); // Player Kills return TRUE; } @@ -715,8 +682,6 @@ void(entity person, float expamt, float doublepoint) addmoney = total_powerup_points += expamt; person.points += expamt; - - UpdatePlayerPoints(person.playernum, person.points, expamt, person.kills, person.netname, person); }; float(entity them, entity me) PlayerIsLooking = diff --git a/source/server/player.qc b/source/server/player.qc index 186a6f0..61f007f 100644 --- a/source/server/player.qc +++ b/source/server/player.qc @@ -679,24 +679,6 @@ void() ClientConnect = } }; -void() PollPlayerPoints = -{ - float i, breakpoint; - entity pollent; - breakpoint = 0; - - for (i = 1; i <= 4 && !breakpoint; i++) - { - pollent = findfloat(world, playernum, i); - - if (pollent == world) { - breakpoint = 1; - break; - } - UpdatePlayerPoints(i, pollent.points, pollent.kills, 0, pollent.netname, pollent); - } -} - // // Player_PickSpawnPoint() // Picks a valid spawn point for the @@ -839,7 +821,6 @@ void() PlayerSpawn = #ifdef FTE - PollPlayerPoints(); UpdateV2model("", 0); stuffcmd(self, "cl_gunx 8;cl_guny 16;cl_gunz 25\n"); SetRound(self, G_STARTROUND);