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

Solved NPC Script

Testerus

Intermediate OT User
Joined
Mar 18, 2014
Messages
673
Reaction score
126
Hello, I've got a problem with an NPC script.
Basically an NPC that asks you to kill a wolf or more then rewards you 1 exp when you complete the quest.

I'm using: The Forgotten Server - version 0.3.6 - Edited By Cyko V8 (Crying Damson)

It worked for a friend that tried it on: The Forgotten Server, version 0.3.7_SVN (Crying Damson)

creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="Wolf" script="wolf.lua"/>
creaturescripts/scripts/login.lua
Code:
registerCreatureEvent(cid, "Wolf")
creaturescripts/scripts/wolf.lua
Code:
local t = {
   [{"wolf", "war wolf", "werewolf"}] = {started = 45003, storage = 45004, kills = 1, raceName = "Wolves", npcName = "Pelt Trader",}
}
function onKill(cid, target, damage, flags)
   for v, k in pairs(t) do
     local master = getCreatureMaster(target)
     if(master and master ~= target) then return true end
     if(bit.band(flags, 1) == 1 and isMonster(target) and isInArray(v, getCreatureName(target))) then
       if(getCreatureStorage(cid, k.started) == 1) then
         if(getCreatureStorage(cid, k.storage) < 0) then
           doCreatureSetStorage(cid, k.storage, 0)
         end
         if(getCreatureStorage(cid, k.storage) < k.kills) then
           doCreatureSetStorage(cid, k.storage, getCreatureStorage(cid, k.storage) + 1)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have defeated " .. getCreatureStorage(cid, k.storage) .. " out of " .. k.kills .. " " .. k.raceName .. "!")
         elseif getCreatureStorage(cid, k.storage) == k.kills then
           local mr = math.random(9)
           if (mr == 9) then
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have defeated enough " .. k.raceName .. "!  " .. k.npcName .. " is waiting to hear the results of your mission!")
           end
         end
       end
     end
   end
   return true
end
npc/Pelt Trader
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Pelt Trader" script="data/npc/scripts/pelt_trader.lua" walkinterval="500" floorchange="0">
   <health now="100" max="100"/>
   <look type="137" head="78" body="51" legs="86" feet="33" addons="3"/>
</npc>
npc/scripts/pelt_trader
Code:
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 onThink()  npcHandler:onThink()  end

   function greet(cid)
     talkState[cid] = 0
     return true
   end

   function getNpcName()
     return getCreatureName(getNpcId())
   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

   local player_gold  = getPlayerItemCount(cid,2148)
  local player_plat  = getPlayerItemCount(cid,2152)*100
  local player_crys  = getPlayerItemCount(cid,2160)*10000
  local player_money  = player_gold + player_plat + player_crys

   if msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
  
   elseif msgcontains(msg, "quest") and (getPlayerStorageValue(cid,45003) < 1) then
     selfSay("Can you kill some wolves for me? I'll collect the pelts from their dead bodies later.", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
     selfSay("Great! Talk to me about quest when you have killed 20 wolves.", cid)
     setPlayerStorageValue(cid,45003,1)
     talkState[talkUser] = 0
  
   elseif msgcontains(msg, "quest") and (getPlayerStorageValue(cid,45003) == 1) then
     selfSay("Have you killed 20 wolves yet?", cid)
     talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
     if getPlayerStorageValue(cid,45004) == 20 then
       selfSay("Great! Here is your reward! 1 exp!", cid)
       doPlayerAddExperience(cid, 1)
       setPlayerStorageValue(cid,45004,21) -- stops creature script from telling player that they have killed enough wolves
       setPlayerStorageValue(cid,45003,2) -- ends 'quest'
       talkState[talkUser] = 0
     else
       selfSay("I don't see enough blood on your hands!.", cid)
       talkState[talkUser] = 0
     end  


   elseif msgcontains(msg, "no") and talkState[talkUser] >= 1 then
     selfSay("No then.", cid)
     talkState[talkUser] = 0
   end
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Besides
Code:
kills = 1,
needing to be
Code:
kills = 20,
and the npc having more functions then it's actually using, I can't find the problem. :(
 
Back
Top