thinking about next crimbo already

wyli romesco

New member
hi,
i have been trying to create a script that will let me automate sending gift packages. after spending two days trying to teach myself ash i ended up with something that took the input that i wanted, didn't return any error msgs but also didn't actually do anything.

my non-script was based around the send_gift stuff in zarqon's zlib and town_sendgift.php, which seems to be the key.

ideally what i want is a script that will let me send plain brown wrappers each containing an item from hagnk's whilst in HC. i can do this manually obviously but i would like some automation. particularly i would like to be able to input a comma delimited list of recipients and to have them all receive the same gift. input for item name and outside msg would be ideal too.

in case you hadn't guessed already this is a request for help ;). this script idea is motivated by my philanthropic desire to give stuff away and is for the greater good. i appreciate, however, that time is meat and i would definitely be sending some goodies to anyone who can come up with something useful. thankyou for listening :D.
 
The scripting discussion board may be a better place for this, as what you're trying to do is discuss/create a new script, as opposed to sharing an existing script...
 
Also, a good start if you're wanting to learn is, post what you've done, and we'll help you try to figure it out from there. :)

If you have a partial, non-functional script... we can try to figure out why. :)
 
hi, thanks for the quick responses. happy to be moved if i'm in the wrong place - apologies.
i guess i'm mostly concerned that you're going to laugh at my feeble attempt at scripting and it probably just needs to be scrapped and started over anyway.

void main( string players, item gift )
{
foreach recipient in $strings[players]
if (is_giftable(gift))
visit_url ("town_sendgift.php?pwd&towho="+recipient+"&whichpackage=1&fromwhere=1&sendmeat=0&howmany1=1&whichitem1="+gift+"&action=Yep.&giftsend=Send+Package");
}

er, that's pretty much it. as i say it allows input, doesn't report any errors, and then it does NOTHING :P
 
Can't put in item gift... might work with gift.to_int() or something like that. Also, you go from string players, to strings players. Not sure if the change from string to strings will kill things...

Edit: Other differences...
zarqon uses package 3, not package 1.
No 'note' in your message.
No 'insidenote' in your message.
Your url has 'fromwhere' set to 1 instead of 0. That looks likely to be the proper Hagnik choice.

My guess is that the biggest problem you have though is not turning the gift into an int properly.
 
Last edited:
As Theraze said, you need to turn "gift" into an int with to_int() in the URL. This way it should work if you only input one player and scratch the foreach.

If you pass a string to your script, it has to parse it to find the different player names. This is (loosely) what I used in this script:
PHP:
boolean sendPackages( string input )
{
	string [ int ] targets;

	matcher m = create_matcher("[\\s]*([^,]+?)[\\s]*(,|$)", input);
	while ( m.find() )
	{
		targets[ count( targets ) ] = m.group( 1 ).to_lower_case() ;
	}

	foreach i, recipient in targets
	{
		(...)
	}
}
The Regular Expression matches anything between commas, so you simply input a comma separated list of player names and it turns it into a map on which you can do the foreach.

You could of course send the package directly each time a player name is parsed, instead of saving the name in a map.
 
Last edited:
hi thankyou for the much appreciated help. still not getting much of a result except that when i go into the gift shop to send one package manually i get an error message saying that the player name is invalid although the package has already gone as if the script was maybe working in the background and expecting multiple recipients. will keep tinkering around :).
 
I just remembered zlib's send_gift() function. Everything you need is in there.

Simply import zlib to use it:
PHP:
import "zlib.ash"; 

void main( string players, item gift ) 
{
	if ( !is_giftable( gift ) ) abort( "You can't send a " + gift + "." ); 

	int [ item ] goodies;
	goodies[ gift ] = 1; 

	string target;
	matcher m = create_matcher( "[\\s]*([^,]+?)[\\s]*(,|$)", players );  
	while ( m.find() )  
	{ 
		target = m.group( 1 );         
		print( "Sending a gift to " + target ); 
		if( !send_gift( target, "", 0, goodies ) ) 
			abort( "Something happened while sending a " + gift + " to " + target ); 
	} 
}
 
Last edited:
Back
Top