ArcEmu: Lua Npc Help - 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

Labels

Make sure when posting a help or release topic you put [c++] or [lua] BEFORE your topic title!
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Lua Npc Help Help with a lua npc

#1 User is offline   Godrick 

  • Newbie
  • Group: Members
  • Posts: 9
  • Joined: 07-May 12
  • Gender:Male
  • Location:United States
  • Server OS:Windows

Posted 07 May 2012 - 06:01 AM

Hey everyone so im trying to make an npc for donations on my server heres what i would like it to do
Get the donation token for the player and give them the gear and vise versa take the gear and give them a token here's what i have ( This maybe totally wrong im an ok programmer in VB/command shell so i made this by reading a teleporter script someone posted and the lua wiki)

function On_talk(unit, event, player)
unit:GossipCreateMenu(50, player, 0)
unit:GossipMenuAddItem(2, "Donation Armor", 1, 0)
pUnit:GossipSendMenu(player) 
end
function On_item
if (intid == 1) then 
	if (player:HasItem(52030, 1) == True) then
	player:RemoveItem(52030, 1)
	player:AddItem(37, 1)
	elseif
		(player:HasItem(52030, 1) == False) then
		player:SendBroadcastMessage("You do not have the required item") 
		player:GossipComplete() 
		end
		
RegisterUnitGossipEvent(94946, 1, "On_talk") 
RegisterUnitGossipEvent(94946, 2, "On_item")


error i get

[06:03][Arcemu] [ERR] C:\xxxxx\xxxxxx\Desktop\Arcemu\code\src\scripts\src\LuaEngin
e\LUAEngine.cpp:92 report scripts\donations.lua:7: '(' expected near 'if'
[06:03][Arcemu]LuaEngine: Loaded 3 Lua scripts.)


its a common error normally an easy fix but i have done trail and error a million times getting different errors

EDIT-changed a bit had a typo

Any help is appreciated
0

#2 User is offline   Satanail 

  • Enthusiast
  • PipPipPip
  • Group: Members
  • Posts: 150
  • Joined: 11-March 12
  • Gender:Male
  • Location:Absurdistan
  • Server OS:Windows

Posted 07 May 2012 - 07:36 AM

There are a lot of errors in this script:
1.) What is this??
function On_item

When you add a gossip submenu selector, there must be some arguments after the function like so:
function On_item(unit, event, player, id, intid, code)

These arguments are used by the script and a gossip submenu does not work without them. If you notice the argument intid, it is later used to determine the id of the gossip option, that player selects. You use if (intid == 1)then at row 7 of your script, but the function does not have any arguments so you get an error. The server does not know what is intid.

2.)
Take a look at this thing:
function On_item
if (intid == 1) then 
        if (player:HasItem(52030, 1) == True) then
        player:RemoveItem(52030, 1)
        player:AddItem(37, 1)
        elseif
                (player:HasItem(52030, 1) == False) then
                player:SendBroadcastMessage("You do not have the required item") 
                player:GossipComplete() 
                end

Now, when you close a function there must be end, also when you have "if" statement, it also must be closed with an end. Here you have just one end to close if (player:HasItem(52030, 1) == True) then and nothing else, so the finction and if (intid == 1) then are not closed. There are 2 more errors for ya :P I do recommend you to use notepad ++ for your scripts, because it helps you monitor this kind of stuff.

3.)"if (player:HasItem(52030, 1) == True) then" This should return true by default so there is no need to check if it is true. "if(player:HasItem(52030))then" will be enough for this row. Also no need to check the count of the item/s, because the npc requires just one item 52030 to add item 37 to the player's inventory.

4.) In LUA, you must use "true" and "false" rather than "True" and "False". The capital letters may cause you trouble.

Ok, so i did what i could with the script you provided and it worked perfectly, but i had to add another gossip menu "Bye", because the NPC was not sending the menu to me but it was calling the submenu function right away when i right-clicked it. Don't know if this is some core issue or there is something else that should be done to this script. At the moment you can either give the donation item to the npc or close the gossip. Here is the script.
local NPC_ID = 94946

function On_talk(unit, event, player)
unit:GossipCreateMenu(50, player, 0)
unit:GossipMenuAddItem(2, "Donation Armor", 1, 0)
unit:GossipMenuAddItem(2, "Bye", 2, 0)
unit:GossipSendMenu(player)
end

function On_item(unit, event, player, id, intid, code)
if (intid == 1)then 
        if(player:HasItem(52030))then
			player:RemoveItem(52030, 1)
			player:AddItem(37, 1)
			player:GossipComplete()
        elseif(player:HasItem(52030) == false) then
             player:SendBroadcastMessage("You do not have the required item") 
             player:GossipComplete() 
         end
elseif(intid == 2)then
	player:GossipComplete() 
	end
end
                
RegisterUnitGossipEvent(NPC_ID, 1, "On_talk") 
RegisterUnitGossipEvent(NPC_ID, 2, "On_item")

0

#3 User is offline   Godrick 

  • Newbie
  • Group: Members
  • Posts: 9
  • Joined: 07-May 12
  • Gender:Male
  • Location:United States
  • Server OS:Windows

Posted 07 May 2012 - 09:08 AM

HA thanks a ton made the changes and works perfect and lol i didnt even notice i left out the
(unit, event, player, id, intid, code)
now to add a few more things :P Thanks again
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