• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] My first Lua script, Will it work?

Status
Not open for further replies.

Pyre

Enthusiast
Lua script error

I am wondering if this script will work?
Code:
function buff_NPC(unit, event, player)
unit:GossipCreateMenu(100, player, 0)
unit:GossipMenuAddItem(0, "Armor + 10%", 1, 0)
unit:GossipMenuAddItem(0, "Damage + 1 - 10%", 2, 0)
unit:GossipMenuAddItem(0, "Resistances + 25", 3, 0)
unit:GossipMenuAddItem(0, "Agility + 10%", 4, 0)
unit:GossipMenuAddItem(0, "Intelligence + 10%", 5, 0)
unit:GossipMenuAddItem(0, "Spirit + 10%", 6, 0)
unit:GossipMenuAddItem(0, "Strength + 10%", 7, 0)
unit:GossipMenuAddItem(0, "Stamina + 10%", 8, 0)
unit:GossipMenuAddItem(0, "Heal Me", 9, 0)
unit:GossipSendMenu(player)
end

function buff_NPC_back(unit, event, player, id, intid, code)
if(intid == 75) then
unit:GossipCreateMenu(78, player, 0)
unit:GossipMenuAddItem(0, "Armor + 10%", 1, 0)
unit:GossipMenuAddItem(0, "Damage + 1 - 10%", 2, 0)
unit:GossipMenuAddItem(0, "Resistances + 25", 3, 0)
unit:GossipMenuAddItem(0, "Agility + 10%", 4, 0)
unit:GossipMenuAddItem(0, "Intelligence + 10%", 5, 0)
unit:GossipMenuAddItem(0, "Spirit + 10%", 6, 0)
unit:GossipMenuAddItem(0, "Strength + 10%", 7, 0)
unit:GossipMenuAddItem(0, "Stamina + 10%", 8, 0)
unit:GossipMenuAddItem(0, "Heal Me", 9, 0)
unit:GossipSendMenu(player)
end

if(intid == 1) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23767, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 2) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23768, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 3) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23769, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 4) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23736, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 5) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23766, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 6) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23738, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 7) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23735, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 8) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23737, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 9) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(25840, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end
end


RegisterUnitGossipEvent(555000, 1, "buff_NPC")
RegisterUnitGossipEvent(555000, 2, "buff_NPC_back")
TheNacho- on owndercore = creds

Error:

Code:
TC> [Eluna]: Searching scripts from `lua_scripts`
lua_scripts/Buff npc.lua:95: attempt to call global 'RegisterUnitGossipEvent' (a
 nil value)
 
Last edited:

FoxGaming

Exalted Member
I'm on mobile or I would give you a more informative answer. I'm just going out on a limb here and saying that the script you posted is for ArcEmu. I'd take a look in the wiki, specifically gossip hooks to fix your error, though if it is for Arc you're going to need to convert the methods properly as well. This should help you with your error though.
http://wiki.emudevs.com/doku.php?id=eluna_gossip_events
 
Last edited:

Foereaper

Founder
Your syntax and method use is of arcemu standard, so no, it won't work for eluna. The above answers should point you in the right direction.
 
a little hint, u can replace the ifs

Code:
function buff_NPC_back(unit, event, player, id, intid, code)
if(intid == 75) then
unit:GossipCreateMenu(78, player, 0)
unit:GossipMenuAddItem(0, "Armor + 10%", 1, 0)
unit:GossipMenuAddItem(0, "Damage + 1 - 10%", 2, 0)
unit:GossipMenuAddItem(0, "Resistances + 25", 3, 0)
unit:GossipMenuAddItem(0, "Agility + 10%", 4, 0)
unit:GossipMenuAddItem(0, "Intelligence + 10%", 5, 0)
unit:GossipMenuAddItem(0, "Spirit + 10%", 6, 0)
unit:GossipMenuAddItem(0, "Strength + 10%", 7, 0)
unit:GossipMenuAddItem(0, "Stamina + 10%", 8, 0)
unit:GossipMenuAddItem(0, "Heal Me", 9, 0)
unit:GossipSendMenu(player)
end

if(intid == 1) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23767, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 2) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23768, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 3) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23769, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 4) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23736, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 5) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23766, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 6) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23738, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 7) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23735, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 8) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23737, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end

if(intid == 9) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(25840, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end
end

to

Code:
function buff_NPC_back(unit, event, player, id, intid, code)
if(intid == 75) then
unit:GossipCreateMenu(78, player, 0)
unit:GossipMenuAddItem(0, "Armor + 10%", 1, 0)
unit:GossipMenuAddItem(0, "Damage + 1 - 10%", 2, 0)
unit:GossipMenuAddItem(0, "Resistances + 25", 3, 0)
unit:GossipMenuAddItem(0, "Agility + 10%", 4, 0)
unit:GossipMenuAddItem(0, "Intelligence + 10%", 5, 0)
unit:GossipMenuAddItem(0, "Spirit + 10%", 6, 0)
unit:GossipMenuAddItem(0, "Strength + 10%", 7, 0)
unit:GossipMenuAddItem(0, "Stamina + 10%", 8, 0)
unit:GossipMenuAddItem(0, "Heal Me", 9, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 1) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23767, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 2) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23768, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 3) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23769, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 4) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23736, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 5) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23766, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 6) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23738, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 7) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23735, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 8) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(23737, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
---------------------------------------------------
elseif(intid == 9) then
unit:GossipCreateMenu(61, player, 0)
unit:FullCastSpellOnTarget(25840, player)
unit:GossipMenuAddItem(0, "[Back]", 75, 0)
unit:GossipSendMenu(player)
end
end
Because u can use only 1 end for the if, elseif is like a else but have a condition.
I dont know in lua but in C if you use if if if if the compiller will read all the ifs but if u use elseif will read one by one and when found the statement stop looking in others elseif

sorry bad english ..
 
If you want the code for last Eluna Version in TrinityCore this is the code :

Code:
local NPC_ID = 555000

function buff_NPC(event, player, unit)
	player:GossipMenuAddItem(0, "Armor + 10%", 1, 0)
	player:GossipMenuAddItem(0, "Damage + 1 - 10%", 2, 0)
	player:GossipMenuAddItem(0, "Resistances + 25", 3, 0)
	player:GossipMenuAddItem(0, "Agility + 10%", 4, 0)
	player:GossipMenuAddItem(0, "Intelligence + 10%", 5, 0)
	player:GossipMenuAddItem(0, "Spirit + 10%", 6, 0)
	player:GossipMenuAddItem(0, "Strength + 10%", 7, 0)
	player:GossipMenuAddItem(0, "Stamina + 10%", 8, 0)
	player:GossipMenuAddItem(0, "Heal Me", 9, 0)
	player:GossipMenuAddItem(0, "Exit", 10, 0)
	player:GossipSendMenu(1,unit)
end

function buff_NPC_back(event, player, unit, sender, intid, code)
	if(intid == 1) then
		player:CastSpell(player,23767)
		player:GossipSendMenu(1,unit)

	elseif(intid == 2) then
		player:CastSpell(player,23768)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 3) then
		player:CastSpell(player,23769)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 4) then
		player:CastSpell(player,23736)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 5) then
		player:CastSpell(player,23766)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 6) then
		player:CastSpell(player,23738)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 7) then
		player:CastSpell(player,23735)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 8) then
		player:CastSpell(player,23737)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)

	elseif(intid == 9) then
		player:CastSpell(player,25840)
		player:GossipMenuAddItem(0, "[Back]", 75, 0)
		player:GossipSendMenu(1,unit)
	elseif(intid==10) then
		player:GossipComplete()
	elseif(intid==75) then
		buff_NPC(event, player, unit)
	end
	
end

RegisterCreatureGossipEvent(NPC_ID, 1, "buff_NPC")
RegisterCreatureGossipEvent(NPC_ID, 2, "buff_NPC_back")

FullCastSpell changed to CastSpell
RegisterUniGossiptEvent changed to RegisterCreatureGossipEvent
Changed If to Elseif
Removed New menu ( code 75 ) and when back call the open gossip function again.
 

Rochet2

Moderator / Eluna Dev
You are using a nonexisting function.
http://eluna.emudevs.com/?search=register

On eluna you use RegisterCreatureGossipEvent( entry, event, function )
the function is the function, not a string like on arcemu.

I made a much simpler version here:
Code:
local buff = 2

local function OnHello(event, player, creature)
    player:GossipMenuAddItem(0, "Armor + 10%", buff, 23767)
    player:GossipMenuAddItem(0, "Damage + 1 - 10%", buff, 23768)
    player:GossipMenuAddItem(0, "Resistances + 25", buff, 23769)
    player:GossipMenuAddItem(0, "Agility + 10%", buff, 23736)
    player:GossipMenuAddItem(0, "Intelligence + 10%", buff, 23766)
    player:GossipMenuAddItem(0, "Spirit + 10%", buff, 23738)
    player:GossipMenuAddItem(0, "Strength + 10%", buff, 23735)
    player:GossipMenuAddItem(0, "Stamina + 10%", buff, 23737)
    player:GossipMenuAddItem(0, "Heal Me", buff, 25840)
    player:GossipSendMenu(100, creature)
end

local function OnSelect(event, player, creature, id, intid, code)
    if (id == buff) then
        player:CastSpell(player, intid, true)
    end
    OnHello(event, player, creature)
end

RegisterCreatureGossipEvent(555000, 1, OnHello)
RegisterCreatureGossipEvent(555000, 2, OnSelect)

PS. Renatokeys, you are have an error in the registering part : ) The strings.
 
Last edited:
You are using a nonexisting function.
http://eluna.emudevs.com/?search=register

On eluna you use RegisterCreatureGossipEvent( entry, event, function )
the function is the function, not a string like on arcemu.

I made a much simpler version here:
Code:
local buff = 2

local function OnHello(event, player, creature)
    player:GossipMenuAddItem(0, "Armor + 10%", buff, 23767)
    player:GossipMenuAddItem(0, "Damage + 1 - 10%", buff, 23768)
    player:GossipMenuAddItem(0, "Resistances + 25", buff, 23769)
    player:GossipMenuAddItem(0, "Agility + 10%", buff, 23736)
    player:GossipMenuAddItem(0, "Intelligence + 10%", buff, 23766)
    player:GossipMenuAddItem(0, "Spirit + 10%", buff, 23738)
    player:GossipMenuAddItem(0, "Strength + 10%", buff, 23735)
    player:GossipMenuAddItem(0, "Stamina + 10%", buff, 23737)
    player:GossipMenuAddItem(0, "Heal Me", buff, 25840)
    player:GossipSendMenu(100, creature)
end

local function OnSelect(event, player, creature, id, intid, code)
    if (id == buff) then
        player:CastSpell(player, intid, true)
    end
    OnHello(event, player, creature)
end

RegisterCreatureGossipEvent(555000, 1, OnHello)
RegisterCreatureGossipEvent(555000, 2, OnSelect)

PS. Renatokeys, you are have an error in the registering part : ) The strings.

hehe forgot to do this part, really nice i like this simple version :D not know it was possible to do this
 
Status
Not open for further replies.
Top