Jump to content

Photo

Item Editor: OnItemLost script slot


  • Please log in to reply
4 replies to this topic

#1 Alucard648

Alucard648

    Wizard

  • Members
  • Location:castle Dracula

Posted 08 October 2018 - 03:08 PM

I would want to see OnItemLost script slot to run when item with script attached into this slot is removed from Link`s inventory. Example usage is to undo effects of OnPickup scipt attached to that item on it`s removal. This will help reduce clutter in global script.


  • Thunderfist likes this

#2 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 08 October 2018 - 04:00 PM

When would this run? I can only think of LikeLikes taking items.

 

The pickup script doesnt run when you get the item from string control codes or per script. Would this?


Edited by Avataro, 08 October 2018 - 04:03 PM.


#3 Alucard648

Alucard648

    Wizard

  • Members
  • Location:castle Dracula

Posted 09 October 2018 - 11:53 AM

When would this run? I can only think of LikeLikes taking items.

 

The pickup script doesnt run when you get the item from string control codes or per script. Would this?

Here are ways to cause Link to lose equipment items: 

1. When item with "Can be Eaten" flag set on was eaten by enemy with Eat[Items] ability.

2. When item with "Remove after Used" flag set on was activated.

3. Via "\17\X" string control code.

4. Via scripts.



#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 13 October 2018 - 08:52 AM

Here are ways to cause Link to lose equipment items: 
1. When item with "Can be Eaten" flag set on was eaten by enemy with Eat[Items] ability.
2. When item with "Remove after Used" flag set on was activated.
3. Via "\17\X" string control code.
4. Via scripts.



Ehhhh.... I suppose that this would be possible. It's something that I'll consider once we do sprite scripts. Those have automatic priority.


FWIW, future script type plans and ideas are:

Sprite Scripts
Item Active Script: Runs continually while the item is on the screen.
NPC Active Script: NPC COntrol script.
LWeapon/EWeapon Active Script: Weapon control script.

Game-Event-Level Global
Link Active Script: Runs at all times, for Link.
DMap Active Script: Runs on every screen of a dmap.
Screen Active Script: Runs perpetually on a single screen.

We may also consider Link Init, Link Death, and a few other things.
  • Alucard648, Emily and Thunderfist like this

#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 03 March 2019 - 08:31 AM

I would want to see OnItemLost script slot to run when item with script attached into this slot is removed from Link`s inventory. Example usage is to undo effects of OnPickup scipt attached to that item on it`s removal. This will help reduce clutter in global script.


Right, so, something that I added to 2.55, is itemdata->RunScript()

As such, this won't need a specific slot, but it can run from Link's active script something like this:
 
bool firstplay = true;

//Link active script
link script links
{
	int collected_items[256];
	int item_scripts[512];
	int data[2048];
	const int REMOVAL_SCRIPT = 0; //array index of data[]
	void run()
	{
		data[REMOVAL_SCRIPT] = Game->GetItemScript("ItemRemoval");
		while(1)
		{
			CheckInventory();
			Waitdraw();
			Waitframe();
		}
		
	}
	void CheckInventory()
	{
		for ( int q = 1; q < 512; ++q )
		{
			if ( collected_items[q] )
			{
				if ( !Link->Item[q] )
				{
					itemdata id = Game->LoadItemData(q);
					id->Script = data[REMOVAL_SCRIPT];
					id->RunScript();
					collected_items[q] = 0; //Fuly remove from inventory. 
				}
			}
		}
		
	}
}

item script ItemRemoval
{
	void run()
	{
		bool done = false;
		//effect here
		//can be made to run for more than one frame
		//with a while loop as of 2.55 Alpha 2 or 3 or 4. 
		while(!done) 
		{
			//when our oop ends
			done = true;
			Waitframe();
		}
		//when done, set back the original item script
		this->Script = links.item_scripts[this->ID];
		
	}
}

//Link Init Script
link script linkinit
{
	void run()
	{
		int collectscriptid = Game->GetItemScript("ItemCollect"); //cache here
		itemdata id;
		for ( int q = 1; q < 512; ++q )
		{
			id = Game->LoadItemData(q);
			id->PScript = collectscriptid; //auto-set the collect script for every item in the quest
		}
		if ( firstplay )
		{
			for ( int q = 1; q < 512; ++q )
			{
				id = Game->LoadItemData(q);
				links.item_scripts[q] = id->Script; //cache all original item scripts at the very start of the game 
			}
			firstplay = false;
		}
	}
}

//Generic collect script to put on a items. 
//Can be forced on all items with Link's init script at the start of every session 
//Marks if Link owns an item, for use when toggling Link->Item[] elsewhere. 
item script ItemCollect
{
	void run()
	{
		links.collected_items[this->ID] = 1;
	}
}
It could be a huge pain and burden on the game engine to check something like this internally, as I am not sure how much use it would ever see.

Alternatively, you could run a function in Link's active script to perform whatever the item script would do, when he loses an item.

Note that you can also check things such as Link-Eaten, and all npc attributes (including original editor values, such as base HP), such as what items they eat, in 2.55.

I've considered adding the ability to run arbitrary scripts, however, because you can make a generic script item, that seems extraneous, and it would require a lot of extra work, because item scripts still need a valid item on which to run.

const int I_SCRIPTRUNNER = 511;

//Usage: RunArbitraryItemScript("MyScript");
void RunArbitraryItemScript(int scriptname, untyped args)
{
	itemdata id = Game->LoadItemData(I_SCRIPTRUNNER);
	id->Script = Game->GetItemScript(scriptname);
	for ( int q = 0; q < 8; ++q ) id->InitD[q] = args[q];
	id->RunScript();
}

  • Alucard648 likes this


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users