Raised This Month: $ Target: $400
 0% 

Advanced EventScripts: CmdChain.cfg for Alias Chaining


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mattie
Veteran Member
Join Date: Jan 2005
Old 05-19-2005 , 00:10   Advanced EventScripts: CmdChain.cfg for Alias Chaining
Reply With Quote #1

Here's a little "function" cfg file I put together to allow the use of alias chaining quite easily. It basically lets you build up a list of commands at your leisure and then run them all at once.

There are lots of uses for this, and I'm going to create a script pack that uses this. Basically, if you ever wanted to build up a list of commands and then execute them all at once later, this script will come in handy.

For example, if you wanted to use this script to charge a fine for players who hurt team members, you could store the ma_takecash commands into an aliaschain and run that chain all at once in round_start.cfg. (So it will hurt their starting cash, not their cash from the previous round.)

Anyway, here's the script:
Code:
// CmdChain.cfg by Mattie for EventScripts v0.7.7
// Set chain_name equal to the name of the chain to which you want to append
// Set chain_cmd to the command string you want to append to the alias chain
// Set chain_reset to 1 if you want to reset the chain.
// For example:
//    ...
//    setinfo chain_name rewardchain
//    setinfo chain_cmd 0
//    es_format chain_cmd "es_tell %1 %2;ma_givecash %1 500" event_var(userid) "You deserve a reward!"
//    exec CmdChain.cfg
//    ...
//    rewardchain
//

// initialize variables
es_setinfo chaininit 1
es_setinfo tailname 0
es_setinfo tail 0
es_setinfo aliasname 0
es_format tailname "%1_tail" server_var(chain_name)
es_copy tail server_var(tailname)

// A little trick to try to auto-initialize without a server.cfg
// if-test should work with both v0.7.6.1 and v0.7.7
if (server_var(tail) notequalto 0) then es_setinfo chaininit 0

// if they set "chain_reset" to 1, we need to reset all the chain and
//   null-terminate it.
if (server_var(chain_reset) equalto 1) then es_setinfo chaininit 1
if (server_var(chaininit) equalto 1) then es_setinfo server_var(tailname) 0
if (server_var(chaininit) equalto 1) then es_format aliasname "%1_%2" server_var(chain_name) 0
if (server_var(chaininit) equalto 1) then es alias server_var(chain_name) server_var(aliasname)
if (server_var(chaininit) equalto 1) then es alias server_var(aliasname) ""

// if we aren't resetting, let's add to the existing chain, initialize temp vars
if (server_var(chain_reset) notequalto 1) then es_setinfo aliasname 0
if (server_var(chain_reset) notequalto 1) then es_setinfo aliastailname 0
if (server_var(chain_reset) notequalto 1) then es_setinfo aliasinfo 0

// add something to the alias chain, the tail # will increment by 1
if (server_var(chain_reset) notequalto 1) then es_format aliasname "%1_%2" server_var(chain_name) server_var(tail)
if (server_var(chain_reset) notequalto 1) then es_math tail + 1
if (server_var(chain_reset) notequalto 1) then es es_copy server_var(tailname) tail
if (server_var(chain_reset) notequalto 1) then es_format aliastailname "%1_%2" server_var(chain_name) server_var(tail)

// zero out the last alias in the chain (i.e. null-terminate the chain)
if (server_var(chain_reset) notequalto 1) then es alias server_var(aliastailname) ""
if (server_var(chain_reset) notequalto 1) then es_format aliasinfo "%1;%2" server_var(chain_cmd) server_var(aliastailname)

if (server_var(chain_reset) notequalto 1) then es alias server_var(aliasname) server_var(aliasinfo)

// turn off the reset flag so the caller doesn't make a mistake
if (server_var(chain_reset) equalto 1) then setinfo chain_reset 0
Basically, to use it, just follow the example. Whenever you want to add a new command to the chain you:
1. Set "chain_name" to the name of the alias that will execute the chain
2. Set "chain_cmd" to the string you want to append to the command chain
3. exec CmdChain.cfg

So if I did this:
Code:
setinfo chain_name testchain
setinfo chain_cmd "echo Hello"
exec CmdChain.cfg
I would see this when I typed 'alias':
Quote:
testchain_1 :

testchain_0 : echo Hello;testchain_1

testchain : testchain_0
If I then typed:
Code:
chain_cmd "echo Hiya!"
exec CmdChain.cfg
then I'd see this when I later typed 'alias':
Quote:
testchain_2 :

testchain_1 : echo Hiya!;testchain_2

testchain_0 : echo Hello;testchain_1

testchain : testchain_0
As you can see, the chain just moves right along appending the commands I want to execute. So if I typed "testchain" it would say:
Quote:
Hello
Hiya!
If I wanted to start the chain over I would just run:
Code:
setinfo chain_reset 1
exec CmdChain.cfg
And now alias says:
Quote:
testchain_2 :

testchain_1 : echo Hello;testchain_2

testchain_0 :

testchain : testchain_0
Notice that testchain_1 is still there, but isn't in our chain any longer because testchain_0 has been emptied out.

Hope this might come in handy,
-Mattie

P.S. Yes it does say EventScripts v0.7.7 up there because that's all I have at the moment to test with. It may or may not work 100% with v0.7.6.1, but just wait a few days and v0.7.7 will be out. (You'll like it, I bet.)
Mattie is offline
ajax
Veteran Member
Join Date: Jan 2005
Old 05-19-2005 , 02:35  
Reply With Quote #2

that's really cool, and i can already think of a couple uses. i do have one request though... in the future, please do not release Advanced ES code this late at night. i hurt my brain figuring it out.
ajax is offline
Cr3V3TT3
Senior Member
Join Date: Jul 2004
Location: V'dauban
Old 05-19-2005 , 14:54  
Reply With Quote #3

It will be easy to do vector lib with a part of this code :]
Cr3V3TT3 is offline
Send a message via MSN to Cr3V3TT3
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 17:26.


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