Here's a cute little script I've been running on my test server. It's a little complicated, and some of you pro scripters might be able to tighten/simplify it a little better than I did.
With this set of scripts, the first player into each map is named "king of the hill". From then on, whoever kills the king gets named "king of the hill". It hops around like mad until someone good gets it. The current king is announced each round. It does nothing else except call the fellow a 'king'-- all he gets is bragging rights (i.e. no bonuses or anything, it's just for fun). The announcement looks like this:
Quote:
The king of the hill is Mattie . Kill the king to become the new king!
|
Early warning-- this is rather advanced for an EventScripts script. It takes advantage of the fact that you can delay variable expansion temporarily by quoting part of the line when you first expand variables. This isn't really intended for novices, but hopefully my explanation below will help make things clearer.
It starts by adding the following lines to your server.cfg so that it gets executed once at the beginning of each map.
server.cfg:
Code:
echo Init Kill of the Hill!
alias kingmsg
alias kingfirst "es alias kingmsg es_xmsg The king of the hill is event_var(es_username). Kill the king to become the new king!;alias dokingfirst;;exec events/buildkingfirst.cfg"
alias kingtestswap
alias kingswap "es alias kingmsg es_xmsg The king of the hill is event_var(es_attackername). Kill the king to become the new king!;es kingmsg;exec events/buildking.cfg"
alias kingtestreset
alias kingreset "es_msg The king has been exiled (i.e. disconnected).;resetking"
alias resetking "alias kingreset;alias kingmsg;alias kingtestreset;alias kingswap;alias build_kingtestreset;alias build_kingtestswap"
alias dokingfirst if (event_var(team) notequalto 0) then if (event_var(team) notequalto 1) then kingfirst
This does a lot of things, but mainly just sets up the variables we need for the whole scripting thing. It begins by emptying out the 'kingmsg' alias. This is the alias that will be run each round to announce the current king. (See round_start.cfg below.) It's really the key since being king doesn't mean anything other than being listed in the king announcement.
If you'll notice the aliases for kingfirst (used to appoint the king when the map starts) and kingswap (used to swap kings when a player is killed), they both end in exec'ing special config files. Those files have the 'delayed' expansion magic I mentioned so that the first time they run they set an alias that resolves half of a condition, and when that alias is run later the other half is added. Here's what those scripts look like.
buildkingfirst.cfg:
Code:
// EventScripts v0.3.0
es alias kingtestswap if (event_var(userid) equalto "event_var(userid)) then kingswap"
es alias kingtestreset if (event_var(userid) equalto "event_var(userid)) then kingreset"
As I mentioned, because I use quotes around the second half,
es won't expand them on the first alias. Then when that alias runs later, the condition will expand the second variable, but the first will already be set to the userid it found much earlier. The above script is the one run to prepare for the first player who joins. Since the player_team event we'll use to manage that provides userid, we use userid as the variable for the first half. Userid is also used for the second half because that will be run (as we'll see) in player_death where userid is the name of the victim. Now we'll see how kings are formed normally (i.e. when players kill one another):
buildking.cfg:
Code:
// EventScripts v0.3.0
es alias kingtestswap if (event_var(attacker) equalto "event_var(userid)) then kingswap"
es alias kingtestreset if (event_var(attacker) equalto "event_var(userid)) then kingreset"
This is similar to the script above, but the important thing is that these aliases will run during player_death. The first time the string runs through, it'll place the attacker's userid in the first half ot the condition. Then, when we try to test when that king dies, it'll resolve the second half as the victim of death. Let's look at
player_team.cfg now:
Code:
// EventScripts v0.4.0
dokingfirst
Yeah, that's it. It just calls the alias we setup at the beginning that simply says when a player joins, if he's joining a team that's not the spectators, then execute the
kingfirst alias. That alias sets up the important
kingmsg and builds the conditions we'll be testing for when this King goes to die (by exec'ing the
buildkingfirst.cfg file I mentioned above).
Then we move on to the
player_death.cfg which also looks very simple:
Code:
// EventScripts v0.3.0
kingtestswap
This code here basically tests to see if the victim in a death is the king. If so, it swaps the kingship over to the attacker. The kingmsg is set and the next swap message is built so that it now uses the attacker's ID for comparison.
Now we have the last two easy scripts which just announce the kingship:
round_start.cfg:
Code:
// EventScripts v0.3.0
kingmsg
player_say.cfg:
Code:
// EventScripts v0.3.0
if (event_var(text) equalto "king") then kingmsg
This last script is just a simple say script that will announce the current king whenever anyone types "king" out loud. I figured that'd be handy for tracking down who you want to target for the next round. ;)
One thing I didn't mention is what happens if the king disconnects. Well, we announce it and reset all the variables until the next map. Not very elegant, but it was mean for the king to leave anyway.
player_disconnect.cfg:
Code:
// EventScripts v0.3.0
kingreset
Currently the King of the Hill scripts above have a bug that you could kill a teamie to become king of the hill, but you can fix that if you wish with the new variables I provided in v0.4.0. ;)
I've attached a zipfile of all the scripts. Be careful when you unzip it as it has a copy of server.cfg that you probably don't want to overwrite entirely (just copy and paste the section). In addition, these scripts assume your EventScripts are in your cfg/events directory (through the use of
eventscripts_subdirectory server variable.)
Anyway, enjoy! Let me know if you have any questions. If you want to try it out without using the scripts, head over to my test server listed on my website,
http://mattie.info/cs/.
-Mattie