• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

ModalWindow help

Otfan125

Well-Known Member
Joined
Mar 1, 2008
Messages
171
Solutions
1
Reaction score
56
Location
Thais
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
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
 
I really dont tihnk there is a way to do this. to be able to "right click" an NPC to use it is client side maybe OTclient can do it. Your best solution to do this in tibia client is to make players right click use or CTRL + click.
Didn't @whitevo already do this? Idk how he did, maybe he can tell y
 
Once again... Not possible... LOL Whitevo uses onLook (Shift Click) you can just right click on the npc!
 
what about attackable flag?
Not sure what exactly do you mean, But if i had to take a guess...
I could make the NPC attackable, and within the npc.lua (script) it sets a flag, making you UNABLE to kill the npc and makes you stop attacking the NPC, while setting off the functions that make the ModWindow pop up....
 
Yes I trigger npc window trough onLook (aka shift+click)

Right click is served for the options you can do with object and that can be only changed in Client if I'm not wrong.

In source you can make npc attackable
 
Here's basically what I'm trying to do, If the player selects one of the options and clicks corfirm, a new dialoque block should appear, and new options should be given!

pretty cool idea huh? I'm sure i'm not the first to come up with this, but I'd love to see it work !

I'd also like to see it work by instead of syaing "Hi" to the npc, Right clicking him would do the job!

http://s33.postimg.org/pg5mcver3/test.png
test.png
https://otland.net/threads/tfs-1-2-npc-dialogue-tree.235201/
 
whoah thats very similar to what I have already :D
I see, however, that in order to bring up the dialogue box, the player still must say "hi" which he still receives the "Greetings, |PLAYERNAME|", which i'm trying to remove :(

I want a NPC to work only as a talkaction object, nothing of that "GREETINGS, |PLAYERNAME|" stuff or "GOOD BYE"

I know I can change these by setting up parameters in the .xml, but i don't want to CHANGE them, i want to GET RID of them :P

I want npcs to work as such:
Player: Hi
Npc: sendModuleWindowToPlayer
 
Back
Top