Page 1 of 1

1 scripting question please help!

Posted: Sat May 28, 2011 9:04 pm
by flametard
i need to make a usable item do this:

when activated, it counts the number of item x in the players inventory. then it removes all of the players item x and then grants the player the same number of item y. so if the player has 300 item x, it removes all 300 item x and grants 300 item y. if the player has no item x, it messages the player "you need item x for this to work"

is this possible? your help is really appriciated, this is the last script hurdle i need to jump before the planet is playable. thanks.

Posted: Sat May 28, 2011 11:03 pm
by zaroba
this *should* do it. although it would spam the user with a grant and ungrant message for each item they have.

what it does is check to see if the player has more then 0 of the items, then runs a custom event that loops replacing each item one at a time until they are all replaced. once the player has none of the item left on them, the script ends and says 'transaction complete'

Code: Select all

Event (“Useitem”, “item x”)
	{
	if Playerinventory (“item x”) > 0)
		{
		CustomEvent( “replacexy” )
		}
	else
		{
		*msg %player% you need item x for this to work
		}

Event (“Custom”,”replacexy”)
	{
	if Playerinventory (“item x”) > 0)
		{
		*grantitem %player% -1 item x
		*grantitem %player% 1 item y
		CustomEvent( “replacexy” )
		}
	else
		{
		*msg %player% transaction complete
		}
	}
for some reason the forum wants to display the quotations as boxes.
but when copy/pasted into notepad, the boxes appear as quotations.

Posted: Sat May 28, 2011 11:12 pm
by flametard
THANKS!!! spam is fine, some of my other usable items spam too so it'll fit right in :D

Posted: Sat May 28, 2011 11:13 pm
by zaroba
this one is the exact same as above, but should yield less spam.
if a player has more then a hundred of the item, it will replace a hundred at a time
if a player has between 50 and 100, it will replace 50 at a time
if a player has between 25 and 50, it will replace 25 at a time
if a player has between 10 and 25, it will replace 10 at a time
if a player has between 1 and 10, it will replace 1 at a time

Code: Select all

Event (“Useitem”, “item x”)
	{
	if Playerinventory (“item x”) > 0)
		{
		CustomEvent( “replacexy” )
		}
	else
		{
		*msg %player% you need item x for this to work
		}

Event (“Custom”,”replacexy”)
	{
	if Playerinventory (“item x”) > 0)
		{
		if Playerinventory (“item x”) > 9)
			{
			if Playerinventory (“item x”) > 24)
				{
				if Playerinventory (“item x”) > 49)
					{
					if Playerinventory (“item x”) > 99)
						{
						*grantitem %player% -100 item x
						*grantitem %player% 100 item y
						CustomEvent( “replacexy” )
						}
					else
						{
						*grantitem %player% -50 item x
						*grantitem %player% 50 item y
						CustomEvent( “replacexy” )
						}
					}
				else
					{
					*grantitem %player% -25 item x
					*grantitem %player% 25 item y
					CustomEvent( “replacexy” )
					}
				}
			else
				{
				*grantitem %player% -10 item x
				*grantitem %player% 10 item y
				CustomEvent( “replacexy” )
				}
			}
		else
			{
			*grantitem %player% -1 item x
			*grantitem %player% 1 item y
			CustomEvent( “replacexy” )
			}
		}
	else
		{
		*msg %player% transaction complete
		}
	}

once again, copy into notepad to see the boxes as quotations

Posted: Tue May 31, 2011 5:19 pm
by Mit
I haven't tried this, and im not up-to-date with how my own scripting language works, but is there any reason you can't just do this?

Code: Select all

$numItems = Playerinventory("itemX")
$numItemsNeg = 0 - $numItems

*grantitem %player% $numItemsNeg itemX
*grantitem %player% $numItems itemY
If there is a reason, its probably something i can easily fix :)

Posted: Tue May 31, 2011 5:44 pm
by zaroba
lol, that should work too.


can't believe i didn't think of that, especially since some of Delivery Zones scripts did count inventory items and grant vars

Posted: Wed Jun 01, 2011 8:26 pm
by Mit
i believe the modern terminology for that is, um, facepalm? :]