Raised This Month: $ Target: $400
 0% 

Advanced EventScripts Example: King of the Hill


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mattie
Veteran Member
Join Date: Jan 2005
Old 03-26-2005 , 22:42   Advanced EventScripts Example: King of the Hill
Reply With Quote #1

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
Attached Files
File Type: zip kinghill.zip (1.5 KB, 233 views)
Mattie is offline
BigBabyJesus
Junior Member
Join Date: Mar 2005
Old 03-27-2005 , 00:06  
Reply With Quote #2

sounds awesome, but is there a way to maybe give the person who is the king like extra health?
BigBabyJesus is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 03-27-2005 , 00:34  
Reply With Quote #3

Quote:
Originally Posted by BigBabyJesus
sounds awesome, but is there a way to maybe give the person who is the king like extra health?
No command for that, yet. But you can give them other benefits like playing certain sounds when they get kills, etc. That's not too hard to work into it.

I'll consider adding health/money commands since those exist in all my other plugins but ES.
Mattie is offline
Rebell
Veteran Member
Join Date: Nov 2004
Location: GERMANY
Old 03-27-2005 , 06:51  
Reply With Quote #4

really nice idea ;)

go on!
__________________
Rebell is offline
Cr3V3TT3
Senior Member
Join Date: Jul 2004
Location: V'dauban
Old 03-27-2005 , 07:45  
Reply With Quote #5

Code:
alias kingreset "es_msg The king has been exiled (i.e. disconnected).;resetking"
You could be more precise with the event var "reason"
Code:
alias kingreset "es_msg The king has been exiled ( event_var(reason) ).;resetking"
But this it' s awsome


Will it be a plugin contest?
Cr3V3TT3 is offline
Send a message via MSN to Cr3V3TT3
BugMeNotDummy
Member
Join Date: Jan 2005
Old 04-16-2005 , 16:30  
Reply With Quote #6

I can't get this scripts to work. I put the server.cfg stuff into my server.cfg in the cfg folder. Then I put all the other files in the cfg/events folder. Is there something that I am missing because it is not working? All of my other scripts work.
BugMeNotDummy is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 04-16-2005 , 16:35  
Reply With Quote #7

Quote:
Originally Posted by BugMeNotDummy
I can't get this scripts to work. I put the server.cfg stuff into my server.cfg in the cfg folder. Then I put all the other files in the cfg/events folder. Is there something that I am missing because it is not working? All of my other scripts work.
I assume you have eventscripts_subdirectory set to events? Is it true that all your other working scripts are sitting next to "cfg/events/player_say.cfg" for example?

This script is difficult to debug if it's not working. You have to see what aliases it created and be sure it says "Init King of the hill" or whatnot when the map loads.

I'm revising this one slightly for the next release, so you might have better luck with that version.
-Mattie
Mattie is offline
BugMeNotDummy
Member
Join Date: Jan 2005
Old 04-16-2005 , 18:08  
Reply With Quote #8

I am testing to see what the problem is and I was wondering how a new king is selected. If the current king disconnects.
BugMeNotDummy is offline
kingpin
Veteran Member
Join Date: Apr 2004
Location: kpsforum.com
Old 04-16-2005 , 18:09  
Reply With Quote #9

it waits untill next map to select a new king rather than pick one mid map.
__________________
kingpin is offline
Send a message via ICQ to kingpin Send a message via AIM to kingpin Send a message via MSN to kingpin Send a message via Yahoo to kingpin Send a message via Skype™ to kingpin
BugMeNotDummy
Member
Join Date: Jan 2005
Old 04-16-2005 , 18:38  
Reply With Quote #10

Is there a way to make it select a new king if the king leaves, because that is the problem.
BugMeNotDummy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode