ArcEmu: [Lua] Scripting items - ArcEmu

Jump to content

Toggle shoutbox Lastest Announcements

dfighter  : (07 December 2014 - 12:06 PM) Arcemu is in hibernation mode, please read http://arcemu.org/fo...showtopic=26903
dfighter  : (01 January 2013 - 05:56 PM) Arcemu wishes you all a happy new year!
Hasbro  : (12 September 2012 - 10:01 AM) Please excuse our outage from the web! Our web host had a major malfunction!
dfighter  : (01 September 2012 - 04:05 PM) Since the spam bots just don't want to stop, I've enabled admin verification when registering.
dfighter  : (23 January 2012 - 09:56 PM) Please note that from now on you will need to confirm your email on the wiki in order to edit it!
Hasbro  : (31 December 2011 - 12:50 PM) Happy New Years all!
Navid  : (26 December 2011 - 04:09 AM) Merry Christmas !!!!!! Happy holidays all :)
WAmadeus  : (24 December 2011 - 03:54 PM) Merry Christmas to all!
dfighter  : (24 December 2011 - 11:05 AM) The Arcemu team wishes y'all a Merry Christmukkah!
Hasbro  : (05 October 2011 - 12:53 PM) Looking for web designers for upcoming web related project. If you're interested in designing user interfaces contact me
dfighter  : (02 September 2011 - 03:47 PM) So who here wants vehicles in Arcemu? :P http://arcemu.org/fo...showtopic=25440
Hasbro  : (14 August 2011 - 03:25 PM) Join us on irc, grab an irc client and connect to irc.freenode.net join channel #arcemu /server irc.freenode.net:6667 /join #arcemu
jackpoz  : (03 August 2011 - 05:33 AM) to all Lua Engine (old one) users: please check http://arcemu.org/fo...showtopic=25274
Hasbro  : (20 May 2011 - 05:27 PM) Looking for people experienced with CMake configuration and setup! Contact me asap
Hasbro  : (15 May 2011 - 05:03 PM) ArcEmu is recruiting C++ programmers, contact Hasbro if interested.
paroxysm  : (03 May 2011 - 06:26 PM) Updated luabridge gossip example to describe the whole gossip creation process rather than just how to create menu. Gossip tutorial
paroxysm  : (23 April 2011 - 11:35 AM) Lua writers can refer to the Luabridge Tutorials section in the Wiki to learn how to write gossip code correctly.
Hasbro  : (20 April 2011 - 05:22 PM) Thank you for your continuous contribution of bug reports, we are working on them.
Hasbro  : (17 April 2011 - 03:20 AM) Please consider donating to support our bills. Donations can be sent using PayPal to donations@arcemu.org - Thank you for your support.
paroxysm  : (10 April 2011 - 12:43 AM) Refer to the Luabridge Tutorials section in the Wiki to learn the new syntax of luabridge.
Resize Shouts Area

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Lua] Scripting items

#1 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 16 November 2009 - 03:52 AM

Lua Items Tutorial

1. Intro
Due to popular demand and my recent understanding of this feature, I will explain to you how to script an item to perform actions when right-clicked. Basic Lua knowledge, and understanding gossip are a big help in fully understanding this tutorial.

SECRET OF THE PRO'S #1

Quote

Lua does not stand for anything. It means 'Moon' in Portuguese, is pronounced LOO-ah, and is typed simply as 'Lua'.


2. The SQL Involved
Probably the trickiest part to item scripting. There are two SQL-related things that you need to know before diving into the Lua.

  • 1. You need to set the value of the column "flags" to "1" in your database.
  • 2. You need to set a "dummy" On-Use spell for the item.


I will now go into detail on how to do this, using WoW-V's item creators:
  • 1. Make an item using WoW-V's item creators. As the On-Use spell, enter 37745. Don't worry about any cooldowns. 37745 is the "dummy" spell I mentioned earlier, it does absolutely nothing. Here's how mine came out: Necroessence
EDIT: Another good spell to use is 33208 if you find problems with "players seeming to slide after using item"
  • 2. Download your item, make sure you remember the entry ID. In my case, I'm using 74772 as my entry ID.
  • 3. Execute that SQL onto your database as you normally would to add an item to your server.
  • 4. Now we will change the flags of the item to 1 as I mentioned we need to do above. This can be done using the following query:

UPDATE `items` SET `flags`='1' WHERE (`entry`='your entry id here') 

So, in my case:
UPDATE `items` SET `flags`='1' WHERE (`entry`='74772') 

Execute that query on your world database. If you do not know how to execute a query, look in your database program's help file.

3. Item Gossip Lua
I will post an example script on this, because it is almost identical to regular NPC gossip, and therefore not much explaining is needed. Here's my Item Gossip for Necroessence:
function Necroessence_OnGossipTalk(item, event, player, pMisc)	
	item:GossipCreateMenu(3545, player, 0)
	item:GossipMenuAddItem(3, "Accept the call of death...", 1, 0)
	item:GossipMenuAddItem(3, "Back to humanity", 2, 0)
	item:GossipSendMenu(player)
end

function Necroessence_OnGossipSelect(item, event, player, id, intid, code, pMisc)
	if(intid == 1) then
		player:SetModel(15945)
		player:GossipComplete()
	end

	if(intid == 2) then
		player:DeMorph()
		player:GossipComplete()
	end
end

RegisterItemGossipEvent(74772, 1, "Necroessence_OnGossipTalk")
RegisterItemGossipEvent(74772, 2, "Necroessence_OnGossipSelect")

Put that in a .lua file, restart your server, clear your cache, then right click on the Necroessence in your backpack, and have a go. All it does is turn you into a Lich when you select "Accept the call of death..." and back into a human again when you select "Back to humanity" The key difference between this and regular gossip is that you use RegisterItemGossipEvent instead of RegisterUnitGossipEvent.

Now let's build up on my script above. I don't want people to be able to use Necroessence when they are in combat. A simple modification does this:
function Necroessence_OnGossipTalk(item, event, player, pMisc)	
        if (player:IsInCombat() == true) then
		player:SendAreaTriggerMessage("You are in combat!")
	else
	        item:GossipCreateMenu(3545, player, 0)
	        item:GossipMenuAddItem(3, "Accept the call of death...", 1, 0)
	        item:GossipMenuAddItem(3, "Back to humanity", 2, 0)
	        item:GossipSendMenu(player)
        end
end

function Necroessence_OnGossipSelect(item, event, player, id, intid, code, pMisc)
	if(intid == 1) then
		player:SetModel(15945)
		player:GossipComplete()
	end

	if(intid == 2) then
		player:DeMorph()
		player:GossipComplete()
	end
end

RegisterItemGossipEvent(74772, 1, "Necroessence_OnGossipTalk")
RegisterItemGossipEvent(74772, 2, "Necroessence_OnGossipSelect")

SECRET OF THE PRO'S #2

Quote

You can make gossip menu options coloured! To do this, you wrap the special colour modifier tags around the text. These tags are, "|cFF###### text |r", where ###### is your hex colour number. (http://html-color-codes.com/ to find the numbers.) Remember to put the "|r" after your text, because it signifies the end of the colour change.

So, say I wanted the "Accept the call of death..." option red, and the other blue. I'd do this:
function Necroessence_OnGossipTalk(item, event, player, pMisc)	
	item:GossipCreateMenu(3545, player, 0)
	item:GossipMenuAddItem(3, "|cFFFF0000 Accept the call of death... |r", 1, 0)
	item:GossipMenuAddItem(3, "|cFF0000FF Back to humanity |r", 2, 0)
	item:GossipSendMenu(player)
end



4. Gossip sucks, I don't want it
Me either! So, I've made another example for you. This is the [item]180535[/item] script without annoying gossip menus.
local transformed = 0
local itemid = 74772

function Necroessence_OnGossipTalk(item, event, player, pMisc)	
        if (player:IsInCombat()==true) then
                player:SendAreaTriggerMessage("You are in combat!")
	else
	        if (transformed == 0) then
		        player:SetModel(15945)
		        transformed = 1
	        else
		        player:DeMorph()
		        transformed = 0
                end
	end
end

RegisterItemGossipEvent(itemid, 1, "Necroessence_OnGossipTalk")


5. Moar examples!
Item fuser: (Not Fully Tested)
local item1id = 71337 --item1
local item2id = 71338 --item2
local item3id = 71339 --fused item

function fusion_OnGossip(item, event, player, pMisc)
	if (player:IsInCombat()==true) then
        	player:SendAreaTriggerMessage("You are in combat!")
	else
		if (player:GetItemCount(item1id) > 0 and player:GetItemCount(item2id) > 0) then
			player:RemoveItem(item1id, 1)
			player:RemoveItem(item2id, 1)
			player:AddItem(item3id, 1)
		else
			player:SendAreaTriggerMessage("Missing items required for fusion")
		end
	end
end

RegisterItemGossipEvent(item1id, 1, "fusion_OnGossip")
RegisterItemGossipEvent(item2id, 1, "fusion_OnGossip")

More may be coming...

I hope you enjoyed this tutorial,
Hypersniper
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#2 User is offline   Shauren 

  • Helper
  • Group: Contributor
  • Posts: 808
  • Joined: 04-November 08
  • Gender:Male
  • Location:Poland
  • Interests:hmm, wow?

Posted 16 November 2009 - 09:39 AM

small note: use a dummy spell that has not been scripted in core yet
0

#3 User is offline   Maglile 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 11-January 10

Posted 11 January 2010 - 02:49 PM

Oh hey shauren
0

#4 User is offline   ckrat67 

  • Member
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 12-October 09

Posted 23 February 2010 - 10:05 AM

ok so lets say there's an item for a quest like a net for example... like you have to catch some fish do you add a function that does something like if theres a school of red snappers then add the red snappers item to your bag? and then update the quest? wait that sucked i mean how do you do this for quests? so i can stop such quests bugging
0

#5 User is offline   psychobandit 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 174
  • Joined: 09-May 09
  • Gender:Male

Posted 01 March 2010 - 01:47 AM

Kind of on the same line as the post above mine, What if you want to script an Item that already exists in the DB? Like the person above said, in the case of a bugged quest? The Item is supposed to spawn a creature but doesn't so I want to write an LUA to make that same item spawn the creature, do I still have to create a whole new Item or can I just modify the existing item?
0

#6 User is offline   Shadoxfix 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 312
  • Joined: 30-December 09
  • Gender:Male
  • Location:Netherlands

Posted 01 March 2010 - 03:06 AM

You can modify the existing items.
0

#7 User is offline   psychobandit 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 174
  • Joined: 09-May 09
  • Gender:Male

Posted 02 March 2010 - 02:34 AM

So then I just have to change the existing Items flag to 1 & the rest is LUA? I ask only because I have been messing with this LUA for months now & no matter what I do, it wont work. I'll post it if I need to but I am really trying not to have someone else do it, I'm stubborn & want to get it working myself (even though I'm asking for help in here :) ).
0

#8 User is offline   hypersniper 

  • Advanced Member
  • Group: Retired
  • Posts: 227
  • Joined: 21-November 08
  • Gender:Male

Posted 02 March 2010 - 04:01 AM

Take a look around, there are plenty of scripts that employ the simple :SpawnCreature command. Look at them as a reference if you need help. Just follow the outlines mentioned in the guide and add something like player:SpawnCreature(entry,x,y,z,o,faction,duration) in the body of the function.
Please don't PM me asking to fix, correct or look-over your scripts. Please post a new thread in the Lua Scripting section so others can learn and help.
0

#9 User is offline   psychobandit 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 174
  • Joined: 09-May 09
  • Gender:Male

Posted 02 March 2010 - 04:09 AM

View Posthypersniper, on 02 March 2010 - 04:01 AM, said:

Take a look around, there are plenty of scripts that employ the simple :SpawnCreature command. Look at them as a reference if you need help. Just follow the outlines mentioned in the guide and add something like player:SpawnCreature(entry,x,y,z,o,faction,duration) in the body of the function.



Heh, I have, repeatedly. The latest version has exactly that. 'Tis why it's pissing me off so much. There is NO reason it shouldn't work.....I even thought maybe I had the LUA engine shut off but I have a teleport LUA that works just fine.
0

#10 User is offline   Wolferine 

  • Member
  • Pip
  • Group: Members
  • Posts: 19
  • Joined: 27-November 09

Posted 03 March 2010 - 01:31 PM

Could you write a guide on normal scripting of items, their own functions in place of gossips?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users