This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [Question] Lua Teleporter errors  (Read 1152 times)

jar0fair

  • Registred Member
  • Race Changer
  • *****
  • Posts: 30
    • View Profile
[Question] Lua Teleporter errors
« on: August 01, 2015, 04:21:54 pm »
Hiya,

I've been playing around with a code for a simple teleporter npc that only has one location. I've checked the code over and over again, and I just can't see why it is giving an error. Here is the code:

Code: [Select]
-- Variables
local npcid = 50003

-- On Triggers
function OnTalk(Unit, Event, player)
Player:GossipMenuAddItem(2, "I am ready to go ashore.", npcid , 1)
Player:GossipMenuAddItem(2, "Never mind.", npcid , 2)
Player:GossipSendMenu(1, unit)
end

function OnSelect(Unit, Event, player, intid, code)
if (intid == 1) then
Player:Teleport(810, 13613.44842, 13608.508789, 12.098165, 1.535403)
Player:GossipComplete()
end

if (intid == 2) then
Player:GossipComplete()
end
end


-- RegisterUnitEvents
RegisterCreatureGossipEvent(npcid, 1, OnTalk)
RegisterCreatureGossipEvent(npcid, 2, OnSelect)

And whenever I click on the NPC I get an error in the server console saying

"lua:6: calling "GossipMenuAddItem" on bad self (bad argument : Player expected, got table)

Does anyone have any idea what might be going on here?
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Krang Stonehoof

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 164
    • View Profile
Re: [Question] Lua Teleporter errors
« Reply #1 on: August 01, 2015, 07:00:14 pm »
You are using wrong arguments in the code. As you can see, in the function
Code: [Select]
function OnTalk(Unit, Event, player) you are using player argument, (but you use it as 'player'), while in code, you use Player... You have to make sure they are identic.

Change function OnTalk(Unit, Event, player) to function OnTalk(Unit, Event, Player) and it works.

Same thing for

function OnSelect(Unit, Event, player, intid, code)
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Rochet2

  • Contributors
  • Polygonshifter
  • *****
  • Posts: 59
    • View Profile
    • http://rochet2.github.io/
Re: [Question] Lua Teleporter errors
« Reply #2 on: August 01, 2015, 10:13:06 pm »
My recommendaion is to stay away from using variables starting with capital letter especially when handling things like Player and Creature etc.
These are global tables that are used to hold all the methods for those types - so similarly to C++ Player is the "class" of the player.

If you use Player in your code you might accidently screw up other user's code.
You can not mess up the actual metatables used for the userdata like this, but I do not recommend trying.

Krang Stonehoof is right about the case sensitivity, however the parameters are also mislocated.
All hooks in Eluna have event as the first argument.

You can .. uh .. almost .. see.. here:
http://eluna.emudevs.com/Global/Registe ... Event.html
How the argument order you should use is (event, player, creature) and for the select hook (event, player, creature, sender, intid, code).

Also for future posting.. there are several lua engines (luabridge, LHA, Eluna...) it would be nice to know at least which core you are using to know which lua engine is being talked about.


I wrote a little something recently in the doc folder. Could be good for a beginner to check out:
https://github.com/ElunaLuaEngine/Eluna ... s/USAGE.md
https://github.com/ElunaLuaEngine/Eluna ... DETAILS.md
« Last Edit: January 01, 1970, 01:00:00 am by Admin »