SERVER: Clean, improve readability for appending Score to Clients

This commit is contained in:
cypress 2024-06-09 17:16:38 -07:00
parent 0d06eae388
commit 8810ab5636
19 changed files with 83 additions and 59 deletions

View file

@ -150,7 +150,7 @@ void() crawler_da10 =[ 9, crawler_da1 ] {crawler_attack_choose(0); self.frame
//37-39
void() crawler_die1 =[ 0, crawler_die2] {SetZombieHitBox(CRAWLER_BBOX);self.frame = 37;};
void() crawler_die2 =[ 1, crawler_die3] {self.frame = 38;};
void() crawler_die3 =[ 2, SUB_Null] {self.iszomb = 0; self.frame = 39;self.nextthink = time + 3;self.think = removeZombie; addmoney(other, 60, true); if (crawler_num > 0) {crawler_num = crawler_num - 1;}};
void() crawler_die3 =[ 2, SUB_Null] {self.iszomb = 0; self.frame = 39;self.nextthink = time + 3;self.think = removeZombie; Player_AddScore(other, 60, true); if (crawler_num > 0) {crawler_num = crawler_num - 1;}};
//====================== Crawler Tesla Death ============================
void() crawler_death_wunder1 =[ 72, crawler_death_wunder2 ] {tesla_arc(); play_sound_z(4); };

View file

@ -596,23 +596,6 @@ float() crandom =
return 2*(random() - 0.5);
}
void(entity person, float expamt, float doublepoint) addmoney =
{
if (person.classname != "player" || person.downed)
return;
if (expamt > 0 && doublepoint == TRUE && x2_finished > time) {
expamt *= 2;
person.score += expamt;
}
// Combine the positive score with the powerup score tally
if (expamt > 0)
total_powerup_points += expamt;
person.points += expamt;
};
float(entity them, entity me) PlayerIsLooking =
{
float ret = false;

View file

@ -144,8 +144,8 @@ void() EndGameSetup =
NotifyGameEnd();
}
game_over = true;
addmoney(self, -self.points, 0);
addmoney(self, self.score, 0);
Player_RemoveScore(self, self.points);
Player_AddScore(self, self.score, false);
return;
}
@ -212,7 +212,8 @@ void() GetDown =
float point_difference;
point_difference = self.points;
point_difference -= 10*rint((self.points*0.95)/10);
addmoney(self, point_difference * -1, false);
Player_RemoveScore(self, point_difference);
self.requirespower = point_difference;
#ifdef FTE
@ -396,7 +397,7 @@ void () GetUp =
self.teslacount = 0;
if (!player_count) {
addmoney(self, self.requirespower, false);
Player_AddScore(self, self.requirespower, false);
}
Weapon_AssignWeapon(0, self.weaponbk, self.currentmagbk, self.currentammobk);
@ -427,27 +428,30 @@ void(entity attacker, float d_style) DieHandler =
if (attacker.classname == "player") {
attacker.kills++;
float points_earned = 0;
switch(d_style) {
case S_HEADSHOT:
addmoney(attacker, 100, true);
points_earned = 100;
attacker.headshots++;
break;
case S_KNIFE:
addmoney(attacker, 130, true);
points_earned = 130;
break;
case S_TESLA:
addmoney(attacker, 50, true);
points_earned = 50;
break;
case S_FLAME:
addmoney(attacker, 50, true);
points_earned = 50;
// override their death sound (FIXME: make a new sound..)
sound(self, CHAN_BODY, "sounds/pu/drop.wav", 1, ATTN_NORM);
break;
default:
addmoney(attacker, 60, true);
points_earned = 60;
break;
}
Player_AddScore(attacker, 50, true);
}
}
@ -459,8 +463,8 @@ void(entity victim,entity attacker, float damage, float d_style) DamageHandler =
entity old_self;
if (victim.classname == "ai_zombie" || victim.classname == "ai_dog") {
if (attacker.classname == "player" && (victim.health - damage)> 0) {
addmoney(attacker, 10, 1);
if (attacker.classname == "player" && (victim.health - damage) > 0) {
Player_AddScore(attacker, 10, true);
}
victim.health = victim.health - damage;
@ -472,9 +476,9 @@ void(entity victim,entity attacker, float damage, float d_style) DamageHandler =
}
if (victim.health <= 0)
addmoney(attacker, 60, 1);
Player_AddScore(attacker, 60, true);
else
addmoney(attacker, 10, 1);
Player_AddScore(attacker, 10, true);
}
if (victim.health <= 0 || instakill_finished > time) {
@ -639,11 +643,11 @@ void(entity inflictor, entity attacker, float damage2, float mindamage, float ra
if (final_damage < other.health)
{
addmoney(self, 10, 0);
Player_AddScore(self, 10, false);
}
else if (final_damage > other.health)
{
addmoney(self, 60, 0);
Player_AddScore(self, 10, false);
}
else
{

View file

@ -97,7 +97,6 @@ entity local_client;
.float points;
.float cost;
.float cost2;
void(entity person, float expamt , float doublepoint) addmoney;
//stats
.float score;

View file

@ -287,7 +287,7 @@ if (self.state == STATE_TOP || self.state == STATE_UP)
default:
break;
}
addmoney(other, self.cost*-1, 0);
Player_RemoveScore(other, self.cost);
self.solid = SOLID_NOT;
}
else

View file

@ -343,7 +343,7 @@ void() button_touch =
other.semi_actions |= SEMIACTION_USE;
if(other.points >= self.cost) {
self.enemy = other;
addmoney(other, 0 - self.cost, FALSE);
Player_RemoveScore(other, self.cost);
button_fire();
return;
@ -421,7 +421,7 @@ void() touch_ending =
if (other.points < self.cost)
return;
addmoney(other, -self.cost, 0);
Player_RemoveScore(other, self.cost);
entity tempe;
entity players = find(world, classname, "player");

View file

@ -300,7 +300,7 @@ void() touch_perk =
useprint(other, 9, price, self.sequence);
if (other.points >= price && other.button7 && !(other.semi_actions & SEMIACTION_USE)) {
addmoney(other, -price, 0);
Player_RemoveScore(other, price);
// Play the sound of the bottle "vending"
sound(self, CHAN_ITEM,"sounds/machines/vend.wav", 1, 1);

View file

@ -437,7 +437,8 @@ void() MBOX_TeddyLeave =
void() MBOX_PresentTeddy =
{
// Return the Player's points.
addmoney(self.owner.owner, mystery_box_cost, 0);
Player_AddScore(self.owner.owner, mystery_box_cost, false);
// Broadcast the bad luck.
sound(self, CHAN_ITEM, "sounds/misc/buy.wav", 1, ATTN_NONE);
sound(self, 2, "sounds/misc/giggle.wav", 1, ATTN_NONE);
@ -510,7 +511,6 @@ void() Float_Change =
return;
}
else {
addmoney(self.owner.owner, mystery_box_cost, 0);
self.model = "models/props/teddy.mdl";
setmodel(self, self.model);
self.angles_y = self.angles_y - 90;
@ -688,7 +688,7 @@ void() MBOX_Touch =
if (other.points >= mystery_box_cost)
{
sound (self, CHAN_ITEM, mystery_box_open_sound, 1, ATTN_NORM);
addmoney(other, -mystery_box_cost, FALSE);
Player_RemoveScore(other, mystery_box_cost);
self.boxstatus = 1;
self.owner = other;
MBOX_PlayOpenAnimation();

View file

@ -172,7 +172,8 @@ void(entity pap, entity buyer) PAP_UpgradeWeapon =
tempe = self;
self = buyer;
addmoney (self, -pap.cost, 0);
Player_RemoveScore(self, pap.cost);
// Spawn Upgrade Spark if permitted
if (!(pap.spawnflags & PAP_SPAWNFLAG_NOSPARK))

View file

@ -250,7 +250,7 @@ void() PU_NukeFinalize =
players = find(world,classname,"player");
while(players)
{
addmoney(players, 400*nuke_powerups_activated, 1);
Player_AddScore(players, 400 * nuke_powerups_activated, true);
players = find(players,classname,"player");
}
@ -390,7 +390,7 @@ void() PU_CarpenterFinalize =
// Reward Players with Points
while(players) {
addmoney(players, 200, 1);
Player_AddScore(players, 200, true);
players = find(players, classname, "player");
}

View file

@ -285,7 +285,7 @@ void() teleport_touch =
return;
}
addmoney(other, -self.cost, 0);
Player_RemoveScore(other, self.cost);
SUB_UseTargets();

View file

@ -251,7 +251,7 @@ void zapper_touch () {
}
zapper_start(self.zappername);
addmoney(other, -1*self.cost, false);
Player_RemoveScore(other, self.cost);
}
}

View file

@ -378,7 +378,7 @@ void() trigger_awardpoints_touch =
if (other.stance != PLAYER_STANCE_PRONE && (self.spawnflags & SPAWNFLAG_TRIGGERSCORE_REQUIREPRONE))
return;
addmoney(other, self.points, (self.spawnflags & SPAWNFLAG_TRIGGERSCORE_APPLY2XPOINTS));
Player_AddScore(other, self.points, (self.spawnflags & SPAWNFLAG_TRIGGERSCORE_APPLY2XPOINTS));
if (self.noise != "")
sound(self, 0, self.noise, 1, 1);

View file

@ -199,7 +199,7 @@ void () WallWeapon_TouchTrigger =
other.reload_delay = 0;
// Subtract the cost from player points.
addmoney(other, wcost*-1, 0);
Player_RemoveScore(other, wcost);
if (self.enemy) {
oldent = self;
@ -244,7 +244,7 @@ void () WallWeapon_TouchTrigger =
other.reload_delay = 0;
// Subtract the cost from player points.
addmoney(other, wcost*-1, 0);
Player_RemoveScore(other, wcost);
if (self.enemy) {
oldent = self;
@ -276,7 +276,7 @@ void () WallWeapon_TouchTrigger =
other.reload_delay = 0;
sound(other, 0, "sounds/misc/ching.wav", 1, 1);
//other.boughtweapon = true;
addmoney(other, 0 - self.cost2, FALSE);
Player_RemoveScore(other, self.cost2);
other.grenades = other.grenades | 2;
other.secondary_grenades = 2;
nzp_bettyprompt(other);
@ -311,7 +311,7 @@ void () WallWeapon_TouchTrigger =
other.reload_delay = 0;
sound(other, 0, "sounds/misc/ching.wav", 1, 1);
//other.boughtweapon = true;
addmoney(other, 0 - self.cost, FALSE);
Player_RemoveScore(other, self.cost);
other.primary_grenades = 4;
if (self.enemy)
{
@ -336,7 +336,7 @@ void () WallWeapon_TouchTrigger =
return;
} else {
W_HideCrosshair(other);
addmoney(other, -self.cost2, FALSE);
Player_RemoveScore(other, self.cost2);
sound(other, 0, "sounds/misc/ching.wav", 1, 1);
other.ach_tracker_coll++;
if (self.enemy)
@ -376,7 +376,7 @@ void () WallWeapon_TouchTrigger =
sound(other, 0, "sounds/misc/ching.wav", 1, 1);
other.reload_delay = 0;
addmoney(other, -1*self.cost, 0);
Player_RemoveScore(other, self.cost);
if (self.enemy) {
oldent = self;
self = self.enemy;

View file

@ -62,7 +62,8 @@ void() Window_repaired =
if (maxreward > totalreward)
{
sound(self, 0,"sounds/misc/ching.wav", 1, ATTN_NORM);
addmoney(self.enemy, 10, 1);
Player_AddScore(self.enemy, 10, true);
totalreward = totalreward + 10;
}
screen_shake();

View file

@ -261,6 +261,41 @@ float(float dir) checkMovement =
}
}
#define Player_RemoveScore(who, value) Player_ChangeScore(who, -value, false)
#define Player_AddScore(who, value, impacted_by_2x_points) Player_ChangeScore(who, value, impacted_by_2x_points)
//
// Player_ChangeScore(who, value, impacted_by_2x_points)
// Appends the given value to the provided clients
// current score, potentially multiplied if the
// Double Points Power-Up is active.
//
void(entity who, float value, float impacted_by_2x_points) Player_ChangeScore =
{
// We shouldn't ever allow a player in Last Stand to have
// their score modified.
if (who.downed)
return;
// Multiply the value if it is to be impacted by Double
// Points
if (impacted_by_2x_points && x2_finished > time)
value *= 2;
// The value was positive, so we should do two things:
// 1. add this to our point threshold check for Power-Up
// spawning.
// 2. add the value to our total score, which is displayed
// at the end of the game to rank every player.
if (value > 0) {
who.score += value;
total_powerup_points += value;
}
// Append the value to our current score.
who.points += value;
};
//
// Player_CanStandHere
// Performs a tracebox and will return true
@ -874,7 +909,7 @@ void() PlayerSpawn =
self.secondary_grenades = -1; // shows that we both don't have betties AND shouldn't draw the image onscreen
if (!self.points)
addmoney(self, G_STARTPOINTS, 0);
Player_AddScore(self, G_STARTPOINTS, false);
self.weaponmodel = GetWeaponModel(self.weapon, 0);// Give weapon model
self.weapon2model = GetWeapon2Model(self.weapon);

View file

@ -28,6 +28,7 @@
*/
void(vector where, float type) Spawn_Powerup;
void(entity who, float value, float impacted_by_2x_points) Player_ChangeScore;
// Whether the command prohibits client-sending.
float client_parse_override;
@ -84,7 +85,7 @@ float(string params) Command_addmoney =
}
// Assign points to the player.
addmoney(self, point_value, 0);
Player_ChangeScore(self, point_value, false);
return COMMAND_SUCCESS;
}

View file

@ -85,7 +85,7 @@ void(entity hit_ent, entity arc_parent, entity arc_owner, float arc_num, float d
// 50 points for waffe kills
if(arc_owner.classname == "player") {
arc_owner.kills += 1;
addmoney(arc_owner, 50, true);
Player_AddScore(arc_owner, 50, true);
}
}

View file

@ -1567,7 +1567,7 @@ void () Impulse_Functions =
break;
case 22:
if (cheats_have_been_activated) {
addmoney(self, 10000, 0);
Player_AddScore(self, 10000, true);
rounds += 4;
}
break;
@ -1822,7 +1822,7 @@ void() CheckPlayer =
self.progress_bar_time = 0;
self.progress_bar_percent = 0;
self.revived = 0;
addmoney(self, ent.requirespower, false);
Player_AddScore(self, ent.requirespower, false);
#ifdef FTE