Page 1 of 1

Item Scripts

Posted: Mon Sep 07, 2009 6:14 am
by LethalEncounter
I have added Item Script support into the emu and it will hit the public svn server tomorrow. Item scripts are LUA scripts that are added to an item that allows you to do custom actions based on a players action. For example, some quests are attached to items and when examined they pop up a box that requires the player to pick certain options. These scripts will allow you to do that. There are currently three functions that are automatically called: obtained(Item, Player), examined(Item, Player), and destroyed(Item, Player). To set them up you just need to specify the full path to the LUA script via the lua_script field in the items table (you wont get the field until you are running the code that supports it).

Here is an example based on the Tainted quest in Queen's Colony:

Code: Select all

--this function is called whenever a player examines an item in their inventory
function examined(Item, Player)
	-- When implementing the full quest you would need to display this only on the initial examination
	-- since this is an example, I am leaving out the HasQuest and GetQuestStep checks
	conversation = CreateConversation()
	AddConversationOption(conversation, "Examine the parchment.", "ExamineFirstParchment")
        AddConversationOption(conversation, "Put the parchment away.", "CloseDialog")
        StartItemConversation(conversation, Item, Player, "The edges of the parchment are torn and jagged as though ripped from a much larger document.")
end

function ExamineFirstParchment(Item, Player)
	-- Send quest update for the Tainted quest for this step
	conversation = CreateConversation()
        AddConversationOption(conversation, "Put the parchment away.", "CloseDialog")
        StartItemConversation(conversation, Item, Player, "You can barely make out some writing on this scrap: \"The toxic crawlers will be useful to cover our ... the totem ...\" The reference to a totem is puzzling.  Why would someone want a totem covered in spiders?  There must be more pieces of this parchment amongst these toxic crawlers.")
end

function CloseDialog(Item, Player)
	CloseItemConversation(Item, Player)
end

--this function is called whenever a player receives an item (doesn't matter how)
function obtained(Item, Player)
	--you could use this for quests but since this is a test it will only display a message
	Emote(Player, "received the item and the villagers rejoiced!", 0, Player)
end


--this function is called whenever a player destroys an item
function destroyed(Item, Player)
	
end

Re: Item Scripts

Posted: Mon Sep 07, 2009 9:35 am
by Scatman
This looks awesome LE :) Thanks so much!