Greetings Otland!
If someone has a little time to expend on me, I need some help with this script :huh: :
I really need an editable NPC script for my server because I could make a conversation with a player, add item, remove money/item, teleport, etc.
But this one has a problem, If there are 2 or more NPC's in range with this script, when I say "hi" the NPC's answer me at the same time, even if I'm not close enough to them.
For example, I have one NPC to teleport you and another NPC to give you an item, then when you say "hi, yes" to one of them, they answer both and therefore Teleporting you and giving you the item.
This is my first time working with NPC's, I try but I can't seem to be able to repair it myself :'d
If someone has a little time to expend on me, I need some help with this script :huh: :
Code:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Bye.')
focus = 0
talk_start = 0
end
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function onCreatureSay(cid, type, msg)
msg = string.lower(msg)
if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 3 then
selfSay('Hello, Would you like to obtain your Vampire Tokens for 300k?')
focus = cid
talk_start = os.clock()
elseif (msgcontains(msg, 'yes') ) then
if getPlayerItemCount(cid,2152) < 30 and getPlayerItemCount(cid,2160) < 1 then
selfSay('Sorry, but you dont have enough money.')
focus = 0
talk_start = 0
else
doPlayerAddItem(cid, 9020, 10)
doPlayerRemoveMoney(cid, 300000)
talk_start = os.clock()
end
elseif (msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 3) then
selfSay('Excuse me, Im busy with someone at this moment.')
elseif (msgcontains(msg, 'bye') and focus == cid and getDistanceToCreature(cid) < 3) then
selfSay('Alright, Hope to see you around here again.')
focus = 0
talk_start = 0
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('I have no time!')
end
focus = 0
end
end
I really need an editable NPC script for my server because I could make a conversation with a player, add item, remove money/item, teleport, etc.
But this one has a problem, If there are 2 or more NPC's in range with this script, when I say "hi" the NPC's answer me at the same time, even if I'm not close enough to them.
For example, I have one NPC to teleport you and another NPC to give you an item, then when you say "hi, yes" to one of them, they answer both and therefore Teleporting you and giving you the item.
This is my first time working with NPC's, I try but I can't seem to be able to repair it myself :'d
Last edited: