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

Lua Why this npc dont say nothing when i say hi

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
It selling promotes, ok, its work...
But when i say hi, him dont talk nothing

Code:
<parameter key="message_greet" value="Hello, |PLAYERNAME|. I sell {promotion}"/>

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="[NPC]The King" script="data/npc/scripts/promote.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="332" head="21" body="87" legs="107" feet="95"/>
  <parameters>
  <parameter key="message_greet" value="Hello, |PLAYERNAME|. I sell {promotion}"/>
  </parameters>
</npc>

Code:
  local config = {
  promote1 = 20000, -- preço da primeira promotion
  promote2 = 10000000, -- preço da segunda promotion
  rookPromote1 = {13, 10000}, -- {id da vocação, preço}
  rookPromote2 = {14, 5000000} -- {id da vocação, preço}
  }
  
  local keywordHandler = KeywordHandler:new()
  local npcHandler = NpcHandler:new(keywordHandler)
  NpcSystem.parseParameters(npcHandler)
  local talkState = {}
  
  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 creatureSayCallback(cid, type, msg)
  msg = string.lower(msg)
  local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  
  if not npcHandler:isFocused(cid) then
  return false
  end
  
  local price
  if (getPlayerVocation(cid) >= 1 and getPlayerVocation(cid) <= 4) then
  price = 20000
  elseif (getPlayerVocation(cid) >= 5 and getPlayerVocation(cid) <= 8) then
  price = 10000000
  elseif (getPlayerVocation(cid) == 0) then
  price = 10000
  elseif (getPlayerVocation(cid) == 13) then
  price = 5000000
  end
  
  if msgcontains(msg, 'promotion') or msgcontains(msg, 'promote') then
  if (getPlayerLevel(cid) < 20 ) then
         selfSay("You need level 20 to be promoted!", cid)
  return true
  end
  if getPlayerVocation(cid) == 0 or getPlayerVocation(cid) == config.rookPromote1[1] then
         selfSay("Do you want to buy promotion for " .. price .. " gold coins?", cid)
  talkState[talkUser] = 2
  elseif getPlayerVocation(cid) > 8  and getPlayerVocation(cid) < config.rookPromote1[1] then
  selfSay("Sorry, you are already promoted.", cid)
         talkState[talkUser] = 0
  elseif not isPremium(cid) and ((getPlayerVocation(cid) > 4 and getPlayerVocation(cid) < config.rookPromote1[1]) or getPlayerVocation(cid) == config.rookPromote1[1]) then
  selfSay("Sorry, you must be VIP to buy second promotion.", cid)
  talkState[talkUser] = 0
  else
         selfSay("Do you want to buy promotion for " .. price .. " gold coins?", cid)
  talkState[talkUser] = 1
  end
  elseif talkState[talkUser] == 1 then
  if msgcontains(msg, 'yes') then
  if doPlayerRemoveMoney(cid, price) then
  doPlayerSetPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
           selfSay("You are now promoted!", cid)
  else
           selfSay("Sorry, you do not have enough money.", cid)
  end
  end
  talkState[talkUser] = 0
  elseif talkState[talkUser] == 2 then
  if getPlayerVocation(cid) == 0 then
  if doPlayerRemoveMoney(cid, config.rookPromote1[2]) then
  doPlayerSetPromotionLevel(cid, 1)
           selfSay("You are now promoted!", cid)
  else
           selfSay("Sorry, you do not have enough money.", cid)
  end
  elseif getPlayerVocation(cid) == config.rookPromote1[1] then
  if not isPremium(cid) then
           selfSay("Sorry, you must be VIP to buy second promotion.", cid)
  talkState[talkUser] = 0
  return 1
  end
  if doPlayerRemoveMoney(cid, config.rookPromote2[2]) then
  doPlayerSetPromotionLevel(cid, 2)
           selfSay("You are now promoted!", cid)
  else
           selfSay("Sorry, you do not have enough money.", cid)
  end
  end
  talkState[talkUser] = 0
  elseif msgcontains(msg, 'bye') then
       selfSay("Good bye, " .. getPlayerName(cid) .. "!", cid)
  talkState[talkUser] = 0
  end 
  return true
  end
  
  npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  npcHandler:addModule(FocusModule:new())
 
Last edited:
I don't think the npc wants to talk with you. It's as easy as that. :oops:

Hahahaha i think he want, but he dont know nothing about marketing
When i say promotion he sell to me, but he dont show him offer when i say hi

Maybe he is dumb like me :(
 
I think you need to add start your NPC with:
Code:
if msgcontains(msg, 'hi') or msgcontains(msg, 'hail king') then

and after that you can add the lines or msge you want:

Code:
if msgcontains(msg, 'hi') or msgcontains(msg, 'hail king') then
      selfSay("Hello PlayerName, tell me what you need here!", cid)
      talkState[talkUser] = 1

elseif msgcontains(msg, 'promotion') and talkState[talkUser] == 1 then
    (here the script to check all condition to get the promoted)
    selfSay("Are you sure want to be promoted " .. getPlayerName(cid) .. "!", cid)
    talkState[talkUser] = 2

elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then

I think there can be the error.
 
I already posted why it's not working.

Code:
<parameter key="message_greet" value="Hello, |PLAYERNAME|. I sell {promotion}"/>
Needs the onThink function I posted above in order to work.

what you posted will not work

OK ok dont get ANGRY... I dont see the word SOLVED, for that reason I post my opinion... sorry
 
Because you're missing:
Code:
function onThink()    npcHandler:onThink()    end

Ty, was that

I think you need to add start your NPC with:
Code:
if msgcontains(msg, 'hi') or msgcontains(msg, 'hail king') then

and after that you can add the lines or msge you want:

Code:
if msgcontains(msg, 'hi') or msgcontains(msg, 'hail king') then
      selfSay("Hello PlayerName, tell me what you need here!", cid)
      talkState[talkUser] = 1

elseif msgcontains(msg, 'promotion') and talkState[talkUser] == 1 then
    (here the script to check all condition to get the promoted)
    selfSay("Are you sure want to be promoted " .. getPlayerName(cid) .. "!", cid)
    talkState[talkUser] = 2

elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then

I think there can be the error.


Ty to try help me too
 
What makes you think I'm angry?
It's good that you try to help people, but it's even better if you test it and make sure it works first.

It is just a comment, I don't think that you are really angry it is only a metaphor , as a joke

Ty, was that




Ty to try help me too

And thanks for telling me that, I don't have my PC working at the moment when I put the comment but i try to help ppl like me, when I start to manage NPC.

Also I never think on that function that can affect the NPC at higger rate, new thing learned today.
And this is the reason of the community, to learn together.
 
Back
Top