• 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!

Lua onUse NPC

Otfan125

Well-Known Member
Joined
Mar 1, 2008
Messages
171
Solutions
1
Reaction score
56
Location
Thais
Hello guys,
As you may have noticed I do have a few posts on the Support thread, however I hope I'm not breaking any rules as I believe my questions may help those who are interested (and of course, me)

So what I'm trying to do, or been trying to do is, to somehow go around the idea that a player should say "Hi" to gain a NPC's attention. I've been using the search tool here in the forums, and I found something: https://otland.net/threads/npc-chat-window.85762/


So while I'm learning lua and the way the server works as a whole, a possible solution to this, I believe, is to create a CreatureScript that activates when the player logins and that when a player tries to "attack" a NPC, it disable's the attack, and acts as an attention getter on the NPC, and runs the .lua script for the NPC

I have this .lua script on my Creaturescript that i believe should work, but doesn't:
Code:
function onUse(cid, target)
    if(isNpc(target))then return doCreatureSay(cid, "Hi!", TALKTYPE_SAY) and false end
end

I've added this to my creaturescripts.xml (as you can tell I got it from the thread link above)
Code:
    <event type="login" name="NpcAttack" event="script" value="npcattack.lua"/>

and I added this to the login.lua, removing the registerCreatureEvent and replacing it with registerEvent (i did this because if i kept registerEvent, i could login to my character, and registerCreatureEvent didn't allow me)
Code:
    player:registerEvent("NpcAttack")

As I spend more time here in the forums and scripting, I'm thankful for everyone who has helped me so far, and the fast replies that this forum offers
 
Hello guys,
As you may have noticed I do have a few posts on the Support thread, however I hope I'm not breaking any rules as I believe my questions may help those who are interested (and of course, me)

So what I'm trying to do, or been trying to do is, to somehow go around the idea that a player should say "Hi" to gain a NPC's attention. I've been using the search tool here in the forums, and I found something: https://otland.net/threads/npc-chat-window.85762/


So while I'm learning lua and the way the server works as a whole, a possible solution to this, I believe, is to create a CreatureScript that activates when the player logins and that when a player tries to "attack" a NPC, it disable's the attack, and acts as an attention getter on the NPC, and runs the .lua script for the NPC

I have this .lua script on my Creaturescript that i believe should work, but doesn't:
Code:
function onUse(cid, target)
    if(isNpc(target))then return doCreatureSay(cid, "Hi!", TALKTYPE_SAY) and false end
end

I've added this to my creaturescripts.xml (as you can tell I got it from the thread link above)
Code:
    <event type="login" name="NpcAttack" event="script" value="npcattack.lua"/>

and I added this to the login.lua, removing the registerCreatureEvent and replacing it with registerEvent (i did this because if i kept registerEvent, i could login to my character, and registerCreatureEvent didn't allow me)
Code:
    player:registerEvent("NpcAttack")

As I spend more time here in the forums and scripting, I'm thankful for everyone who has helped me so far, and the fast replies that this forum offers
cus on use is an action
 
update 'onUse' function to this
Code:
function onCombat(cid, target)
Code:
<event type="combat" name="NpcAttack" event="script" value="npcattack.lua"/>
Always check your console for errors.

Most likely you would've received an error advising the script could not find 'function onCombat'.
 
I still dont understand the difference between having to attack it rather then using the floor tile other then having the npc walk around lol
 
update 'onUse' function to this
Code:
function onCombat(cid, target)
Code:
<event type="combat" name="NpcAttack" event="script" value="npcattack.lua"/>
Always check your console for errors.

Most likely you would've received an error advising the script could not find 'function onCombat'.

actually I get

>> Loading script systems
[Error - CreatureEvent::configureEvent] Invalid type for creature event: NpcAtta
ck
[Warning - BaseEvents::loadFromXml] Failed to configure event


But i beleive thats because the version of TFS that i'm using doesn't have "type=combat" , i'm using the TFS in the distributions thread, the very first post (sticky)
 
I still dont understand the difference between having to attack it rather then using the floor tile other then having the npc walk around lol
cause if i'm able to attack it, set a flag and make the npc.lua script run, then i don't have to make the player CTRL+right-click the NPC, and click "use" which wouldn't make sense since what I want the player to do with the npc is TALK not USE :p
 
cause if i'm able to attack it, set a flag and make the npc.lua script run, then i don't have to make the player CTRL+right-click the NPC, and click "use" which wouldn't make sense since what I want the player to do with the npc is TALK not USE :p
But if you just ctrl + left click thats all you have to do? Thats the same as right click use? if you use attack its the exact same thing except you press alt and left click.... My head hurts
 
But if you just ctrl + left click thats all you have to do? Thats the same as right click use? if you use attack its the exact same thing except you press alt and left click.... My head hurts
ctrl + left click makes this little menu pop-up:
image.png

right click ATTACKS the target, it doesn't give you the same pop-up? not sure what you meant by that! :O

I want the player to be able to right click a NPC and be able to get the Dialogue Box:
test.png


If i want to right click a NPC, then by the way tibia is set-up, I will ATTACK the npc. So I want to make the NPC attackable, and when I do attack it, the script executes and shows me the Dialogue box

My head hurts too :(
 
ctrl + left click makes this little menu pop-up:
image.png

right click ATTACKS the target, it doesn't give you the same pop-up? not sure what you meant by that! :O

I want the player to be able to right click a NPC and be able to get the Dialogue Box:
test.png


If i want to right click a NPC, then by the way tibia is set-up, I will ATTACK the npc. So I want to make the NPC attackable, and when I do attack it, the script executes and shows me the Dialogue box

My head hurts too :(

ahh you are using tibia classiv control.... You freak LOL
9255ec72b39afa4c47012f0ba894f87c.png
 
Actually using CTRL+right click isn't that bad :O Now I must create an ActionID that will give me the dialogue box!
any pointers on how to use the dialogue box as a ActionID? I did it as a function in npc.lua, now i gotta give the same function to a ground tile :s
thank you for all your help guys :P
 
Actually using CTRL+right click isn't that bad :O Now I must create an ActionID that will give me the dialogue box!
any pointers on how to use the dialogue box as a ActionID? I did it as a function in npc.lua, now i gotta give the same function to a ground tile :s
thank you for all your help guys :p
Code:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(config)
    return true
end
 
Code:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:sendDamageWindow(config)
    return true
end
I replaced player:sendDamageWindow(config) with sendModalWindowToPLayer and they both gave me the same errors D:


Lua Script Error: [Action Interface]
data/actions/scripts/quests/baddemon.lua:onUse
data/actions/scripts/quests/baddemon.lua:2: attempt to call global 'sendModalWin
dowToPlayer' (a nil value)
stack traceback:
[C]: in function 'sendModalWindowToPlayer'
data/actions/scripts/quests/baddemon.lua:2: in function <data/actions/sc
ripts/quests/baddemon.lua:1>
 
this is what i have in actions.xml

<!-- Talk -->
<action uniqueid="1001" script="quests/baddemon.lua" />

where baddemon.lua is where i have the script you posted :b
 
Nop D: I haven't been able to download it.... I was thinking of continuing this whole thing tomorrow since i've been trying to make it work since i woke up today T_T
 
Back
Top