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

Basic Upgrad/Enchant NPC

Tenaria

New Member
Joined
Apr 26, 2009
Messages
142
Reaction score
2
Dear Otland Community,

i tryed to script with my own brain as the thread says an enchant npc or upgrade what ever (iam not even a scripter or someth).

But i get this error (tfs 0.4) :

Code:
[7:29:06.755] [Error - LuaInterface::loadFile] data/npc/scripts/epicizer.lua:27: unexpected symbol near '='
[7:29:06.759] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/epicizer.lua
[7:29:06.763] data/npc/scripts/epicizer.lua:27: unexpected symbol near '='


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


item = 8303
noitem = 'Come back when you have full stuff.'


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, 'enchant') then
         selfSay("Do you want upgrade your item?", cid)
if msgcontains (msg, 'yes') then

doPlayerGetItemCount(cid, 8300) = 5 and
doPlayerGetItemCounter(cid, 2160) = 100 then

doPlayerRemoveItem (cid, 8300, 5)
doPlayerRemveItem (cid, 2160, 100)

doPlayerSendMagicEffect (getCreaturePosition(cid), 19)
doPlayerAddItem (cid, 8303, 1)
else
selfSay (noitem)
end
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Basically i want somebody says "Hi", "enchant" he should bring item ID 8300 and 100 cc, and become itemID 8303.

Thanks for your help :)
 
Solution
jKYGW8a.png


Just some pointers for the future.

Here's something that should work.
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 greet(cid)
    talkState[cid] = 0
    return true
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false...
jKYGW8a.png


Just some pointers for the future.

Here's something that should work.
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 greet(cid)
    talkState[cid] = 0
    return true
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
   
    if msgcontains(msg, "enchant") then
        selfSay("Do you want enchant your item?", cid)
        talkState[talkUser] = 1
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        if getPlayerItemCount(cid, 8300) >= 5 and getPlayerItemCount(cid, 2160) >= 100 then
            doPlayerRemoveItem(cid, 8300, 5)
            doPlayerRemoveItem(cid, 2160, 100)
            doPlayerAddItem(cid, 8303, 1, true)
            selfSay("Great! Here is your item.", cid)
        else
            selfSay("You do not have the required materials to enchant your item.", cid)
        end
        talkState[talkUser] = 0
    elseif talkState[talkUser] == 1 then
        selfSay("Maybe another time then.", cid)
        talkState[talkUser] = 0   
    end
   
    return true   
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
Thank you very much man. You deserved a BJ :p haha joking bro. Thanks for the Script and the little tutorial. I will keep in touch with that and learn step by step. Thanks :))
 
Back
Top