1 scripting question please help!

Forum Archive - from http://theuniversal.net
Locked
User avatar
flametard
Posts: 1245
Joined: Sun Apr 01, 2007 2:05 am
Location: Join NR! faction name: 'NR new recruits' password: 'Truth'
Contact:

1 scripting question please help!

Post 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.
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post 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.
User avatar
flametard
Posts: 1245
Joined: Sun Apr 01, 2007 2:05 am
Location: Join NR! faction name: 'NR new recruits' password: 'Truth'
Contact:

Post by flametard »

THANKS!!! spam is fine, some of my other usable items spam too so it'll fit right in :D
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post 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
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post 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 :)
User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post 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
User avatar
Mit
Staff
Staff
Posts: 3551
Joined: Sun Sep 21, 2003 10:14 pm
Location: Unknown

Post by Mit »

i believe the modern terminology for that is, um, facepalm? :]
Locked