--------------------------------------------------------------------------------
001 Loop through room 1 to 1000 and change the color of rooms with the
    static (16) flag.
--------------------------------------------------------------------------------

#loop {1 1000}
{
	#map goto &0;
	#map get roomflags result;
	#if {$result & 16}
	{
		#map set roomcolor <168>
	}
	{
		#map set roomcolor <178>
	}
}

--------------------------------------------------------------------------------
002 Capture session information.
--------------------------------------------------------------------------------

#action {^#SESSION '%1' CONNECTED TO '%2' PORT '%3'}
{
	#var session %1;
	#var address %2;
	#var port %3
}

--------------------------------------------------------------------------------
003 Capture system information. #script stores the output as a list,
    hence the need to convert it into a normal variable.
--------------------------------------------------------------------------------

#script {dir} {pwd}
#var dir $dir[1]

#script {home} {echo $HOME}
#var home $home[1]

--------------------------------------------------------------------------------
004 Automatically reconnect on disconnect.
--------------------------------------------------------------------------------

#event {SESSION DISCONNECTED}
{
	#gts #delay 5 {#session MyMUD 214.241.15.11 3000;loom;mypass}
}

--------------------------------------------------------------------------------
005 Execute a random social at random time intervals.
--------------------------------------------------------------------------------

#tick {randomsocial}
{
    #delay {1d100}
    {
        #if {1d2 == 1}
        {
            #if {1d3 == 1} {cheer}
            #if {1d2 == 1} {greet all}
            #if {1d1 == 1} {smile}
        }
    }
}
{200}

--------------------------------------------------------------------------------
006 Maintain a friendlist.
--------------------------------------------------------------------------------

#variable friendlist {{bubba} {pamela} {cookie} {harry potter}}

#function isfriend
{
    #format name %l {{%0}};

    #list friendlist fnd {$name} result
}


#act {%1 follows you.}
{
    #if {@isfriend{%1}}
    {
        group %1
    }
    {
        unfollow %1
    }
}

#alias {addfriend}
{
	#format name %l {{%0}};

	#list friendlist ins -1 $name;

	#showme $name has been added to your friendlist.
}

#alias {delfriend}
{
	#format name %l {{%0}};

	#if {@isfriend{$name}}
	{
		#list friendlist del @isfriend{$name};
		#showme $name has been deleted from your friendlist.
	}
	{
		#showme $name is not on your friendlist.
	}
}

--------------------------------------------------------------------------------
007 Append a goto to your current room when saving a map
--------------------------------------------------------------------------------

#alias {savemap}
{
        #map write %0;
        #map get roomvnum room;
        #system echo '#map goto $room' >> %0
}

--------------------------------------------------------------------------------
008 Log all text to a file with a timestamp with decisecond precision.
--------------------------------------------------------------------------------

#function {timestamp}
{
	#format utime {%U};

	#format result {%t.%m} {{%Y-%m-%d %H:%M:%S} {$utime % 1000000 / 100000}}
}

#event {RECEIVED LINE}
{
        #line log mylog.txt {<178>@timestamp{} \};
        #line log mylog.txt
}

--------------------------------------------------------------------------------
009 Old school tick support.
--------------------------------------------------------------------------------

#tick {oldtick}
{
	#delay 50 #showme #10 SECONDS TO TICK!!;
	#showme #TICK!!!
}
{60}

--------------------------------------------------------------------------------
010 Execute speedwalks with .
--------------------------------------------------------------------------------

#alias {.%0}
{
	#list cnt clr;

	#parse {%0}
	{
		#if {"&0" >= "0" && "&0" <= "9"}
		{
			#var cnt ${cnt}&0
		}
		#if {"$cnt" == ""}
		{
			#send &0
		}
		{
			#loop {1 $cnt}
			{
				#send &0;
			};
			#list cnt clr
		}
	}   
}

--------------------------------------------------------------------------------
011 Targetting script
--------------------------------------------------------------------------------

#list targets clr

#alias {target}
{
	#if {"%0" == ""}
	{
		#showme {Current targets: $targets}
	}

	#list {targets} {fnd} {%0} {result};
 
	#if {$result}
	{
		#list {targets} {del} {$result};
		#showme Target '%0' removed.
	}
	{
		#list {targets} {srt} {%0};
		#showme Target '%0' added.
	}
}

#act {%1 arrives}
{
	#if {"$targets" == "*{%1}*"} {kill %0}
}

#act {%1 is standing here}
{
	#if {"$targets" == "*{%1}*"} {kill %0}
}

#action {%1 is dead! R.I.P.}
{
	#if {"$targets" == "*{%1}*"} {target %0}
}

--------------------------------------------------------------------------------
012 Finding enemies in a list
--------------------------------------------------------------------------------

#var enemies {{Bubba} {Bob} {Bilbo}}

#function {listfnd}
{
	#list %1 fnd {%2} result
}

#alias {isenemy}
{
	#if {@listfnd{enemies %0}}
	{
		#showme %0 is an enemy
	}
	{
		#showme %0 is not an enemy
	}
}

--------------------------------------------------------------------------------
013 Show items unique to two lists.
--------------------------------------------------------------------------------

#nop list comparing

#var bla {{1}{2}{3}{4}{5}}                   
#var bli {{1}{3}{5}{7}{9}}

#function {listcompare}
{
	#list {result} {clr};

	#forall {$%1}
	{
		#list %2 fnd {&0} found;

		#if {$found == 0}
		{
			#list {result} {srt} {&0}
		}
	};
	#forall {$%2}
	{
		#list %1 fnd {&0} found;
 
		#if {$found == 0}
		{
			#list {result} {srt} {&0}
		}
	}
}	

#showme @listcompare{bla bli}

--------------------------------------------------------------------------------
014 Show xterm 256 colors.
--------------------------------------------------------------------------------

#var bla {}

#forall {a b c d e f}
{
	#forall {a b c d e f}
	{
		#forall {a b c d e f}
		{
			#var bla {$bla <&0&&0&&&0>(&0&&0&&&0)}
		};
		#showme $bla;
		#var bla {}
	}
}

#loop {0 23}
{
	#format tmp {g%+02s} {{&0}};
	#var bla $bla <$tmp>($tmp)
}

#showme $bla

--------------------------------------------------------------------------------
015 Draw a health bar.
--------------------------------------------------------------------------------

#alias {hpbar}
{
        #math {hp_percent}{100 * %1 / %2};
        #math {hpbars1}   {$hp_percent / 5};
        #math {hpbars2}   {20 - $hpbars1};
        
        #format {hpbar} {<011>%+${hpbars1}s<099><000>%+${hpbars2}s<099> };
        
        #showme [$hpbar]
}

hpbar 30 100
