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

Help fix lua error with npc mission.

Karoxer

Member
Joined
Mar 13, 2018
Messages
20
Reaction score
5
Hello, I'm beginner with scripting and trying to learn things by reading other threads. I managed to make simple quests, but now i get some problems and don't have any idea how to fix it.
Quest is simple, npc Joe tell our character to collect items to get prize. When i set collect 1 item its fine, but when i want to add count (for example collect 5 items) script broke. If u could find error, fix it and explain me why its not working I would be delighted.

NPC script:
Lua:
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  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 = Player(cid)
  
    if msg == "quest" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) ~= 2 then
    selfSay('Ive got my old armor for sell, but if you bring me 5 warwolf furs i will give you it for free. Be hasty, I need to delivery those furs to one of the shadows in old camp. {Interested} ?', cid)
    talkState[talkUser] = 1
    end
  
    if msg == "interested" and talkState[talkUser] == 1 then
    selfSay('You are probably too weak to kill such monsters, but you could try talk with guards or hunters. You will find them around the exchange square, still want taking up the {task} ?', cid)
    talkState[talkUser] = 2
    end
  
  if msg == "task" and talkState[talkUser] == 2 then 
    player:setStorageValue(12556, 1)
    selfSay('Okay, come back when you collect all items', cid)
  talkState[talkUser] = 0
  end   
  
  if msg == "task" and player:getStorageValue(12556) == 1 and player:getStorageValue(12555) ~= 2 then
    if player:getItemCount(ItemType(id = 11235, count = 5), :getId()) > 0 then
    player:removeItem(ItemType(id = 11235, count = 5):getId(), 1)
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
    player:addItem(ItemType(2484):getId(), 1)
    player:setStorageValue(12556, 2)
     talkState[talkUser] = 0
    else
       selfSay('You dont have enought furs, come back when you will collect all of them', cid)
    talkState[talkUser] = 0
    end
    end
    
    if msg == "task" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) == 2 then
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
  talkState[talkUser] = 0
    end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Error:
Lua:
[Warning - NpcScript::NpcScript] Can not load script: joe.lua
data/npc/scripts/joe.lua:36: ')' expected near '='
 
Solution
Yes. This method player:getItemCount return how many items of the id passed the player has. So if you want 5. Just use my example. But change it for 5 like:


Lua:
if player:getItemCount(11235) >= 5 then
      player:removeItem(11235, 5)

This way, if player contains 5 or more items of the id 11235 it will remove 5 of them and proceed to the rest of the code
Hello, I'm beginner with scripting and trying to learn things by reading other threads. I managed to make simple quests, but now i get some problems and don't have any idea how to fix it.
Quest is simple, npc Joe tell our character to collect items to get prize. When i set collect 1 item its fine, but when i want to add count (for example collect 5 items) script broke. If u could find error, fix it and explain me why its not working I would be delighted.

NPC script:
Lua:
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  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 = Player(cid)
 
    if msg == "quest" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) ~= 2 then
    selfSay('Ive got my old armor for sell, but if you bring me 5 warwolf furs i will give you it for free. Be hasty, I need to delivery those furs to one of the shadows in old camp. {Interested} ?', cid)
    talkState[talkUser] = 1
    end
 
    if msg == "interested" and talkState[talkUser] == 1 then
    selfSay('You are probably too weak to kill such monsters, but you could try talk with guards or hunters. You will find them around the exchange square, still want taking up the {task} ?', cid)
    talkState[talkUser] = 2
    end
 
  if msg == "task" and talkState[talkUser] == 2 then
    player:setStorageValue(12556, 1)
    selfSay('Okay, come back when you collect all items', cid)
  talkState[talkUser] = 0
  end 
 
  if msg == "task" and player:getStorageValue(12556) == 1 and player:getStorageValue(12555) ~= 2 then
    if player:getItemCount(ItemType(id = 11235, count = 5), :getId()) > 0 then
    player:removeItem(ItemType(id = 11235, count = 5):getId(), 1)
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
    player:addItem(ItemType(2484):getId(), 1)
    player:setStorageValue(12556, 2)
     talkState[talkUser] = 0
    else
       selfSay('You dont have enought furs, come back when you will collect all of them', cid)
    talkState[talkUser] = 0
    end
    end
  
    if msg == "task" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) == 2 then
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
  talkState[talkUser] = 0
    end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Error:
Lua:
[Warning - NpcScript::NpcScript] Can not load script: joe.lua
data/npc/scripts/joe.lua:36: ')' expected near '='

Try use this code:

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  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 = Player(cid)

    if msg == "quest" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) ~= 2 then
    selfSay('Ive got my old armor for sell, but if you bring me 5 warwolf furs i will give you it for free. Be hasty, I need to delivery those furs to one of the shadows in old camp. {Interested} ?', cid)
    talkState[talkUser] = 1
    end

    if msg == "interested" and talkState[talkUser] == 1 then
    selfSay('You are probably too weak to kill such monsters, but you could try talk with guards or hunters. You will find them around the exchange square, still want taking up the {task} ?', cid)
    talkState[talkUser] = 2
    end

  if msg == "task" and talkState[talkUser] == 2 then
    player:setStorageValue(12556, 1)
    selfSay('Okay, come back when you collect all items', cid)
  talkState[talkUser] = 0
  end 

  if msg == "task" and player:getStorageValue(12556) == 1 and player:getStorageValue(12555) ~= 2 then
    if player:getItemCount(ItemType(id = 11235, count = 5), :getId()) > 0 then
    player:removeItem(ItemType(id = 11235, count = 5), :getId(), 1)
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
    player:addItem(ItemType(2484), :getId(), 1)
    player:setStorageValue(12556, 2)
     talkState[talkUser] = 0
    else
       selfSay('You dont have enought furs, come back when you will collect all of them', cid)
    talkState[talkUser] = 0
    end
    end
   
    if msg == "task" and player:getStorageValue(12556) ~= 1 and player:getStorageValue(12556) == 2 then
    selfSay('Thank you so much for helping me! I would be in trouble if i dont delivery those furs. Here is your armor, its little used, but still better than your rags.', cid)
  talkState[talkUser] = 0
    end
  return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Still not working, same error but for 33rd lane of script . Thanks anyway for you effort :)
Lua:
[Warning - NpcScript::NpcScript] Can not load script: joe.lua
data/npc/scripts/joe.lua:33: ')' expected near '='
 
The problem resides in:

Lua:
if player:getItemCount(ItemType(id = 11235, count = 5), :getId()) > 0 then
    player:removeItem(ItemType(id = 11235, count = 5), :getId(), 1)

the :getId() method is being called from nothing.

Also don't make sense to me why create a ItemType passing the count = 5 when you are using the getItemCount method.

You can replace with:

Lua:
if player:getItemCount(11235) > 0 then
      player:removeItem(11235, 1)

But your problem is just to fix the :getId(). I don't now what Id your trying to get. So I can't help you. Don't make much sense to me
 
Last edited:
@TheRatazana I'm newbie with scripting so I'm trying to learn how things works by editing and adding new functions etc. I was trying to edit benjis quest for TFS 1.2 (How to make a quest, and have it show in the quest log.) and i have no idea for what is it (this part with ID's u said make no sense), but like u said it has nonsense cause after deleting it quest works. But still I have no idea where/how to paste number of requested items (i want to make this npc request from player to collect 5 warwolf furs etc.) and dont know how to do this. Was trying to get some ideas from other scripts but their construction was totally different.
if player:getItemCount(ItemType(id = 11235, count = 5)
if player:getItemCount (item = {id = 2157, count = 1},)
if player:getItemCount (rewarditems = {id = 2160, count = 1},) [this one make no sense even for newbie like me but a drowning man clutches at a straw.]
And my additional question, "if player:getItemCount" this part makes that npc check player if he have requested items yes ?
 
Yes. This method player:getItemCount return how many items of the id passed the player has. So if you want 5. Just use my example. But change it for 5 like:


Lua:
if player:getItemCount(11235) >= 5 then
      player:removeItem(11235, 5)

This way, if player contains 5 or more items of the id 11235 it will remove 5 of them and proceed to the rest of the code
 
Solution
Back
Top