Otfan125
Well-Known Member
Hello guys,
So I've been trying to make a NPC send a ModalWindow to the player once the player says a keyword, but I seem to be getting some problems. I'm relatively new to lua, but I can understand languages quickly if they are explained to me. Here is the .lua
My guess is that player = Player(cid) makes the variable player BE the information you need to mess around with the actual player, and that functions here are called just like in any other languages
This script works up until i say "here", but when it tries to call sendModalWindowToPlayer, it gives me errors:
any help is greatly appreciated, thank you
So I've been trying to make a NPC send a ModalWindow to the player once the player says a keyword, but I seem to be getting some problems. I'm relatively new to lua, but I can understand languages quickly if they are explained to me. Here is the .lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local player = Player(cid)
local function sendModalWindowToPlayer(player)
player:registerEvent("ModalWindow_Tutorial")
local title = "Pick your favorite color!"
local message = "You get a free tapestry in the color of your choice!"
local window = ModalWindow(1000, title, message)
window:addButton(100, "Confirm")
window:addButton(101, "Cancel")
window:addChoice(1, "Red")
window:addChoice(2, "Orange")
window:addChoice(3, "Yellow")
window:addChoice(4, "Green")
window:addChoice(5, "Blue")
window:addChoice(6, "Purple")
window:setDefaultEnterButton(100)
window:setDefaultEscapeButton(101)
window:sendToPlayer(player)
end
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
-- here comes what the NPC should do
if msgcontains(msg,"here") then
selfSay("Here you are", cid);
sendModalWindowToPlayer(player)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
My guess is that player = Player(cid) makes the variable player BE the information you need to mess around with the actual player, and that functions here are called just like in any other languages
This script works up until i say "here", but when it tries to call sendModalWindowToPlayer, it gives me errors:
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/bad demon.lua:onCreatureSay
data/npc/scripts/bad demon.lua:11: attempt to index local 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/bad demon.lua:11: in function 'sendModalWindowToPlayer'
data/npc/scripts/bad demon.lua:43: in function 'callback'
data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
data/npc/scripts/bad demon.lua:7: in function <data/npc/scripts/bad demo
n.lua:7>
any help is greatly appreciated, thank you