Traveling trader relay overide script

For script writing
Post Reply
wulfwyn
Pie of the Sky
Posts: 29
Joined: Sun Nov 01, 2009 1:55 am
Location: Chandler, AZ

Traveling trader relay overide script

Post by wulfwyn » Tue Aug 23, 2011 2:26 am

This is a small relay over-ride script that I've been working on. Basically, it let's you know when the traveling trader has arrived in main.php (the main map). Just save this file in mafia's relay folder.

I'm still fairly new at scripting (especially with relays), so any seasoned advice on this script is welcome.

Heh, having some problems uploading the file, so, just save this text in notepad (change save as type: to all files) as main.ash

Code: Select all

void main()
{
	buffer trader;
	append (trader, visit_url());
	string market = visit_url ("town_market.php");
	matcher traveling = create_matcher ("tradercart",market);
	boolean heishere = (traveling.find());
	write(trader);

	if (heishere)
	{

	write("<br/><a href=\"traveler.php\"><img src=http://images.kingdomofloathing.com/otherimages/town/tradercart.gif width=100 height=100 align=\"left\"/><a/><center><b><font size=6 face=bold><font color=8D38C9>T<font color=7A5DC7>h<font color=8467D7>e <font color=9172EC>T<font color=9E7BFF>r<font color=A74AC7>a<font color=C45AEC>v<font color=D462FF>e<font color=F778A1>l<font color=E56E94>i<font color=C25A7C>n<font color=B93B8F>g <font color=5CB3FF>T<font color=56A5EC>r<font color=659EC7>a<font color=488AC7>d<font color=357EC7>e<font color=737CA1>r <font color=4863A0>i<font color=2B547E>s <font color=153E7E>h<font color=15317E>e<font color=342D7E>r<font color=151B54>e<font color=250517>!<right><a href=\"traveler.php\"><img src=http://images.kingdomofloathing.com/otherimages/town/tradercart.gif width=100 height=100 align=\"right\"><a/>");

	}
}

I'm also attaching code for the newer version here. Currently, it's not completely tested, but looks like it'll work. This one will check only once a day when you go to the main page, instead of checking 'every' time that you do.

Here it is:

Code: Select all

void main()
{
	buffer trader;
	append (trader, visit_url());
	string market = visit_url ("town_market.php");
	int check = get_property ("_tradercheck").to_int();

	if (check == 0)
	{

		matcher traveling = create_matcher ("tradercart",market);
		boolean heishere = (traveling.find());

		if (heishere)
		{
			check = 2;
			set_property ("_tradercheck", (check).to_string());
		}
		else
		{
			check = 1;
			set_property ("_tradercheck", (check).to_string());
		}
	}

	if (check == 2)
	{
			append (trader, "<br/><a href=\"traveler.php\"><img src=http://images.kingdomofloathing.com/otherimages/town/tradercart.gif width=100 height=100 align=\"left\"/><a/><center><b><font size=6 face=bold><font color=8D38C9>T<font color=7A5DC7>h<font color=8467D7>e <font color=9172EC>T<font color=9E7BFF>r<font color=A74AC7>a<font color=C45AEC>v<font color=D462FF>e<font color=F778A1>l<font color=E56E94>i<font color=C25A7C>n<font color=B93B8F>g <font color=5CB3FF>T<font color=56A5EC>r<font color=659EC7>a<font color=488AC7>d<font color=357EC7>e<font color=737CA1>r <font color=4863A0>i<font color=2B547E>s <font color=153E7E>h<font color=15317E>e<font color=342D7E>r<font color=151B54>e<font color=250517>!<right><a href=\"traveler.php\"><img src=http://images.kingdomofloathing.com/otherimages/town/tradercart.gif width=100 height=100 align=\"right\"><a/>");
	}


	write(trader);
}

Last edited by wulfwyn on Sun Aug 28, 2011 4:26 am, edited 1 time in total.

User avatar
lotsofphil
Leader of rum ham
Posts: 4075
Joined: Mon Mar 01, 2010 3:56 pm

Re: Traveling trader relay overide script

Post by lotsofphil » Tue Aug 23, 2011 11:20 am

Neat idea, wulf. I've never used a relay override script, so am not one to test it.

User avatar
Verdigris97
Colonel Contest
Posts: 739
Joined: Thu Jan 21, 2010 6:14 pm
Location: Northern CA

Re: Traveling trader relay overide script

Post by Verdigris97 » Tue Aug 23, 2011 1:18 pm

This is a nice example that shows the basic structure of an override, and it is short enough that it can be comprehended even by slow, attention-deficit old(er) farts like me. ("Why isn't this written in FORTRAN so I can convert it to C?")

Thanks for posting this, Wulf.

User avatar
lostcalpolydude
Forum Maestro
Posts: 2940
Joined: Wed Apr 23, 2008 6:54 pm

Re: Traveling trader relay overide script

Post by lostcalpolydude » Tue Aug 23, 2011 5:18 pm

I probably would have made the script only check once per day and set a preference to track it (beginning with _ in the name to have mafia reset at rollover), but it's not like the main page is loaded often anyway.
bmaher: Softcore character
lostcalpolydude: Hardcore character (abandoned)

wulfwyn
Pie of the Sky
Posts: 29
Joined: Sun Nov 01, 2009 1:55 am
Location: Chandler, AZ

Re: Traveling trader relay overide script

Post by wulfwyn » Wed Aug 24, 2011 12:45 pm

lost, do you mean set_property() and get_property()?

If enough people are interested in this then I can set something up. Might take awhile though, just started with classes again, semester is going to be heck....

I'm thinking a decent way to do it might be to create a breakfast script that sets the property if he's around, which would change the relay override to just check the preferences instead of the market.

alternatively, I could set 2 preferences in the override script, one to show whether it was checked, and one to show whether the trader is here. This is probably preferable, since it means less work on the end user. They wouldn't have to deal with setting up/changing their breakfast settings.

User avatar
lostcalpolydude
Forum Maestro
Posts: 2940
Joined: Wed Apr 23, 2008 6:54 pm

Re: Traveling trader relay overide script

Post by lostcalpolydude » Wed Aug 24, 2011 5:05 pm

The preference would be empty as mafia logs in. When the override script runs, it could be set to "yes" or "no", or really any two values you wanted. With 3 possible values you can tell if it has already been run and whether the trader is here all at once.
bmaher: Softcore character
lostcalpolydude: Hardcore character (abandoned)

wulfwyn
Pie of the Sky
Posts: 29
Joined: Sun Nov 01, 2009 1:55 am
Location: Chandler, AZ

Re: Traveling trader relay overide script

Post by wulfwyn » Sun Aug 28, 2011 4:20 am

I've attached the new code at the top of the page. Thanks everyone for the help!

Post Reply