diff --git a/config/docs.cfg b/config/docs.cfg
index 9d8f543c..69bd18ff 100644
--- a/config/docs.cfg
+++ b/config/docs.cfg
@@ -590,6 +590,8 @@ docexample [echo $votepending] [Output: if there is currently a vote pending, re
docident [onSpawn] [If this alias exists it will be run every time someone spawns.];
docident [onKill] [If this alias exists it will be run every time a player is killed.];
docident [onFlag] [If this alias exists it will be run every time a flag action occurs.];
+docident [onConnect] [If this alias exists it will be run every time you or another player join(s) your server.];
+docident [onNameChange] [If this alias exists it will be run every time you or another player change(s) of name.];
docident [mdldyncache] [];
docargument [V] [] [min 1/max 32/default 2];
docident [mdlstatcache] [];
diff --git a/docs/reference.xml b/docs/reference.xml
index 80710521..07c4bb2c 100644
--- a/docs/reference.xml
+++ b/docs/reference.xml
@@ -1840,6 +1840,30 @@ addOnLoadAlways [
If defined, this will be executed each time a flag action occurs.
+
+
+
+
+ If defined, this will be executed when you or another player join(s) a server.
+
+
+
+
+
+
+ If defined, this will be executed each time a player spawns.
+
+
+
+
+
+
+
+ If defined, this will be executed when you or another player change(s) his name.
+
+ The alias is executed before the name is effectively changed, so you can still get the previous name of the client from this alias.
+
+
This will append the passed 2nd argument to any existing content of the alias named in the 1st argument. Several popular aliases have predefined shortcuts using this scriptalias: addOnQuit, addOnLoadOnce, addOnLoadAlways. Check config/scripts.cfg for possible omissions in that list.
@@ -1878,12 +1902,7 @@ echo foo
-
-
-
-
- If defined, this will be executed each time a player spawns.
-
+
Whether the values returned by getposition are integers (0) or floating-point numbers (1).
diff --git a/source/src/client.cpp b/source/src/client.cpp
index 5e678e8a..261c6f83 100644
--- a/source/src/client.cpp
+++ b/source/src/client.cpp
@@ -561,6 +561,11 @@ void gets2c() // get updates from the server
connpeer = NULL;
connected = 1;
conoutf(_("connected to server"));
+ if(identexists("onConnect"))
+ {
+ defformatstring(onconnect)("onConnect %d", -1);
+ execute(onconnect);
+ }
throttle();
if(editmode) toggleedit(true);
break;
diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp
index e79dbc9b..6fe2285f 100644
--- a/source/src/clientgame.cpp
+++ b/source/src/clientgame.cpp
@@ -189,7 +189,14 @@ void newname(const char *name)
{
if(name[0])
{
- filtertext(player1->name, name, 0, MAXNAMELEN);//12345678901234//
+ string tmpname;
+ filtertext(tmpname, name, 0, MAXNAMELEN);
+ if(identexists("onNameChange"))
+ {
+ defformatstring(onnamechange)("onNameChange %d \"%s\"", player1->clientnum, tmpname);
+ execute(onnamechange);
+ }
+ copystring(player1->name, tmpname);//12345678901234//
if(!player1->name[0]) copystring(player1->name, "unarmed");
updateclientname(player1);
addmsg(SV_SWITCHNAME, "rs", player1->name);
@@ -287,7 +294,7 @@ void playerinfo(const char *cn, const char *attr)
if(!*cn || !cn || !*attr || !attr) return;
int clientnum = atoi(cn); // get player clientnum
- playerent *p = clientnum == player1->clientnum ? player1 : getclient(clientnum);
+ playerent *p = clientnum == player1->clientnum || clientnum < 0 ? player1 : getclient(clientnum);
if(!p)
{
conoutf("invalid clientnum");
@@ -329,9 +336,7 @@ void playerinfo(const char *cn, const char *attr)
void playerinfolocal(const char *attr)
{
- string cn;
- itoa(cn, player1->clientnum);
- playerinfo(cn, attr);
+ playerinfo("-1", attr);
}
COMMANDN(player, playerinfo, ARG_3STR);
@@ -351,12 +356,15 @@ void teaminfo(const char *team, const char *attr)
int t_deaths = 0;
int t_points = 0;
+ string teammembers = "";
+
loopv(players) if(players[i] && players[i]->team == t)
{
t_frags += players[i]->frags;
t_deaths += players[i]->deaths;
t_points += players[i]->points;
t_flags += players[i]->flagscore;
+ sprintf("%s %d", teammembers, players[i]->clientnum);
}
loopv(discscores) if(discscores[i].team == t)
@@ -380,6 +388,7 @@ void teaminfo(const char *team, const char *attr)
ATTR_INT(deaths, t_deaths);
ATTR_INT(points, t_points);
ATTR_STR(name, newstring(team_string(t)));
+ ATTR_STR(players, teammembers);
conoutf("invalid attribute");
}
@@ -902,8 +911,11 @@ void dokill(playerent *pl, playerent *act, bool gib, int gun)
{
if(pl->state!=CS_ALIVE || intermission) return;
- defformatstring(killevent)("onKill %d %d %d %d", act->clientnum, pl->clientnum, gun, gib ? 1 : 0);
- if(identexists("onKill")) execute(killevent);
+ if(identexists("onKill"))
+ {
+ defformatstring(killevent)("onKill %d %d %d %d", act->clientnum, pl->clientnum, gun, gib ? 1 : 0);
+ execute(killevent);
+ }
string pname, aname, death;
copystring(pname, pl==player1 ? "you" : colorname(pl));
diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp
index 91e2e7d6..2787bbf5 100644
--- a/source/src/clients2c.cpp
+++ b/source/src/clients2c.cpp
@@ -532,6 +532,11 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
{
if(strcmp(d->name, text))
conoutf(_("%s is now known as %s"), colorname(d), colorname(d, text));
+ if(identexists("onNameChange"))
+ {
+ defformatstring(onnamechange)("onNameChange %d \"%s\"", d->clientnum, text);
+ execute(onnamechange);
+ }
copystring(d->name, text, MAXNAMELEN+1);
updateclientname(d);
}
@@ -571,13 +576,13 @@ void parsemessages(int cn, playerent *d, ucharbuf &p)
else // new client
{
conoutf(_("connected: %s"), colorname(d, text));
- if(identexists("onNewPlayer"))
- {
- defformatstring(onnewplayer)("onNewPlayer %d", d->clientnum);
- execute(onnewplayer);
- }
}
copystring(d->name, text, MAXNAMELEN+1);
+ if(identexists("onConnect"))
+ {
+ defformatstring(onconnect)("onConnect %d", d->clientnum);
+ execute(onconnect);
+ }
loopi(2) d->setskin(i, getint(p));
d->team = getint(p);
if(m_flags) loopi(2)