Skip to content

Commit

Permalink
add example gamehud script
Browse files Browse the repository at this point in the history
also: getfrags, getflags, getdeaths show hudplayer's stats instead of player1
  • Loading branch information
sauerbraten committed Dec 3, 2020
1 parent bee533f commit 03ae011
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,41 @@ a.k.a. Features
- `showkpd`: when 1, shows the players' frags/death ratio
- `showaccuracy`: when 1, shows the players' overall accuracy
- `showdamage`: when 1, shows the players' overall damage dealt; when 2, shows the players' overall net damage (= dealt - received); always hidden in insta modes

![ectf, duel, multiple teams](https://i.imgur.com/tS9FK1I.gif)

- adds damage-related cubescript commands:
- `getdamagepotential`
- `getdamagedealt`
- `getdamagereceived`
- `getdamagewasted` (= potential - dealt)
- `getnetdamage` (= dealt - received)

all of these commands (as well as `getaccuracy`) default to showing your own stats across all weapons. however, they all take two optional integer arguments to query by weapon and player: `/<cmd> [weapon] [cn]` (use -1 to query damage across all weapons)

![ectf, duel, multiple teams](https://i.imgur.com/tS9FK1I.gif)
All of these commands (as well as `getaccuracy`) default to showing your own stats across all weapons. However, they all take two optional integer arguments to query by weapon and player: `/<cmd> [weapon] [cn]` (use -1 to query damage across all weapons)

To use these new commands to show comed-like statistics in the game hud in the lower right corner, put the following into your autoexec.cfg:

```
gamehud = [
format "^f7SG: ^f1%1%% ^f7CG: ^f1%2%% ^f7RL: ^f1%3%% ^f7RI: ^f1%4%% ^f7GL: ^f1%5%% ^n^t^f7frags: ^f0%6 ^f7deaths: ^f3%7 ^f7acc: ^f2%8%% ^f7kpd: ^f5%9" (
round (getaccuracy 1) 0.1 )(
round (getaccuracy 2) 0.1 )(
round (getaccuracy 3) 0.1 )(
round (getaccuracy 4) 0.1 )(
round (getaccuracy 5) 0.1 )(
getfrags )(
getdeaths )(
round (getaccuracy) 0.1 )(
round (divf (getfrags) (max (getdeaths) 1)) 0.1
)
]
```

### [hudfragmessages.patch](./patches/scoreboard.patch)

- enables frag messages showing the weapon used to complete the frag (on by default)
![fragmessages](https://i.imgur.com/K4GL6oB.png)

- adds the following variables:
- `hudfragmessages`: when 0, no frag messages are shown
- `hudfragmessageduration`: how long each message will be shown, in milliseconds, between 100 (= 0.1s) and 10,000 (= 10s)
Expand All @@ -42,8 +63,6 @@ a.k.a. Features
when hudfragmessagey<=0.5 (new messages appearing in the upper half of the screen), older messages will be stacked above newer ones, otherwise (new messages appear in the lower half), older messages are shown below newer ones
- `hudfragmessagescale`: size of the messages, between 0.0 and 1.0

![fragmessages](https://i.imgur.com/K4GL6oB.png)

## Installation

The latest builds are always at https://github.com/sauerbraten/p1xbraten/releases/latest. *You do not need to download anything but the correct executable in order to run this client mod!*
Expand Down
18 changes: 12 additions & 6 deletions patches/scoreboard.patch
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,21 @@ Index: src/fpsgame/fps.cpp
if(local) damage = d->dodamage(damage);
else if(actor==player1) return;

@@ -531,9 +534,8 @@
ICOMMAND(getfrags, "", (), intret(player1->frags));
ICOMMAND(getflags, "", (), intret(player1->flags));
ICOMMAND(getdeaths, "", (), intret(player1->deaths));
@@ -528,12 +533,11 @@
}
}

- ICOMMAND(getfrags, "", (), intret(player1->frags));
- ICOMMAND(getflags, "", (), intret(player1->flags));
- ICOMMAND(getdeaths, "", (), intret(player1->deaths));
- ICOMMAND(getaccuracy, "", (), intret((player1->totaldamage*100)/max(player1->totalshots, 1)));
- ICOMMAND(gettotaldamage, "", (), intret(player1->totaldamage));
- ICOMMAND(gettotalshots, "", (), intret(player1->totalshots));
+ ICOMMAND(gettotaldamage, "", (), intret(playerdamage(player1, DMG_DEALT)));
+ ICOMMAND(gettotalshots, "", (), intret(playerdamage(player1, DMG_POTENTIAL)));
+ ICOMMAND(getfrags, "", (), intret(hudplayer()->frags));
+ ICOMMAND(getflags, "", (), intret(hudplayer()->flags));
+ ICOMMAND(getdeaths, "", (), intret(hudplayer()->deaths));
+ ICOMMAND(gettotaldamage, "", (), intret(playerdamage(NULL, DMG_DEALT)));
+ ICOMMAND(gettotalshots, "", (), intret(playerdamage(NULL, DMG_POTENTIAL)));

vector<fpsent *> clients;

Expand Down
10 changes: 5 additions & 5 deletions src/fpsgame/fps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ namespace game
}
}

ICOMMAND(getfrags, "", (), intret(player1->frags));
ICOMMAND(getflags, "", (), intret(player1->flags));
ICOMMAND(getdeaths, "", (), intret(player1->deaths));
ICOMMAND(gettotaldamage, "", (), intret(playerdamage(player1, DMG_DEALT)));
ICOMMAND(gettotalshots, "", (), intret(playerdamage(player1, DMG_POTENTIAL)));
ICOMMAND(getfrags, "", (), intret(hudplayer()->frags));
ICOMMAND(getflags, "", (), intret(hudplayer()->flags));
ICOMMAND(getdeaths, "", (), intret(hudplayer()->deaths));
ICOMMAND(gettotaldamage, "", (), intret(playerdamage(NULL, DMG_DEALT)));
ICOMMAND(gettotalshots, "", (), intret(playerdamage(NULL, DMG_POTENTIAL)));

vector<fpsent *> clients;

Expand Down

0 comments on commit 03ae011

Please sign in to comment.