• 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
 
ok it's in my files now, and the server runs...

but what does it do? :O


EDIT:

While i'm at it, HOW DO YOU make an npc behave like an object? Untargetable, but you can still communicate with it :b
playing around you can make npc attackable but u cant register an event on it so you cant cancel the attack. combat and attack events were deleted from new tfs and you cant register an event on a npc as far as i know

btw i tried something and worked, the rest is yours-

Code:
function Creature:onTargetCombat(target)
    if self and target then
        if self:isPlayer() and target:isNpc() then
            target:setFocus(self)
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end
    return RETURNVALUE_NOERROR
end
 
Last edited:
Back
Top