• 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 Citizen addon NPC ;-/

Diemorko

New Member
Joined
Jan 31, 2011
Messages
64
Reaction score
0
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local shortsword = 2406 -- TUTAJ WPISZ ID SHORT SWORDA
local book1 = 1955 -- TUTAJ WPISZ ID KSIĄŻKI1
local book2 = 12497 -- TUTAJ WPISZ ID KSIĄŻKI2
local book3 = 12406 -- TUTAJ WPISZ ID KSIĄŻKI3
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

-- Storage IDs --

fdruid        = 22043
sdruid        = 22044

newaddon    = 'Just in time! Your backpack is finished. Here you go, I hope you like it.'
noitems        = 'Sorry, but that\'s not enough leather to make one of these backpacks.'
noitems2    = 'Sorry, but that\'s not enough leather to make one of these backpacks.'
already        = 'It seems you already have this addon, don\'t you try to mock me son!'


function citizenfirst(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if isPremium(cid) then
    addon = getPlayerStorageValue(cid,fdruid)
    if addon == -1 then
        if getPlayerItemCount(cid,5878)>= 100 then
        if doPlayerRemoveItem(cid,5878,100) and getPlayerSex(cid) == 1 then
            doCreatureSay('Just in time! Your backpack is finished. Here you go, I hope you like it.')           
            doSendMagicEffect(getCreaturePosition(cid), 13)
            setPlayerStorageValue(cid,fdruid,1)
            doPlayerAddOutfit(cid, 128, 1)
        elseif doPlayerRemoveItem(cid,5878,100) and getPlayerSex(cid) == 0 then
            doCreatureSay('Just in time! Your backpack is finished. Here you go, I hope you like it.')           
            doSendMagicEffect(getCreaturePosition(cid), 13)
            setPlayerStorageValue(cid,fdruid,1)
            doPlayerAddOutfit(cid, 136, 1)
        end   
        else
            selfSay(noitems)
        end
    else
        selfSay(already)
    end
    end

end




node1 = keywordHandler:addKeyword({'minotaur leather'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?'})
node1:addChildKeyword({'yes'}, citizenfirst, {})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I know, it\'s quite some work... don\'t lose heart, just keep killing minotaurs and you\'ll eventually get lucky.', reset = true})

node2 = keywordHandler:addKeyword({'minotaur leathers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ah, right, almost forgot about the backpack! Have you brought me 100 pieces of minotaur leather as requested?'})
node2:addChildKeyword({'yes'}, citizenfirst, {})
node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I know, it\'s quite some work... don\'t lose heart, just keep killing minotaurs and you\'ll eventually get lucky.', reset = true})


    if(msgcontains(msg, 'help')) then
        npcHandler:say("I lost my book\'s somewhere, if you bring me one of them then i will reward you. Do you have my book?.", cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if(doPlayerRemoveItem(cid, book1, 1) or doPlayerRemoveItem(cid, book2, 1) or doPlayerRemoveItem(cid, book3, 1))  then
                doPlayerAddItem(cid, shortsword, 1)
            setPlayerStorageValue(cid, 10001, 1)
                npcHandler:say("Thank you stranger! Please, this is your reward. Go back if you find another one.", cid)
            else
                npcHandler:say("You don\'t have a book! Bring it to me and then we will talk..", cid)
        end
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then 
        npcHandler:say("Come back if you got that book.", cid)
        end
        return true
        end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Why it's not work? no any error :-/ He dont respond for addon :-/
 
Why do you complicate it that much?

If you want you can try this other easier way to make the npc:

xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Addons" script="data/npc/scripts/addoner.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="134" head="76" body="5" legs="17" feet="76" addons="3"/>
    <parameters>
    <parameter key="message_greet" value="Greetings |PLAYERNAME|. I can sell you many nice {addons}!." />
    </parameters>
</npc>

.lua

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


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

npcHandler:setMessage(MESSAGE_GREET, "Greetings |PLAYERNAME|. Say {addons} to know which addons i can sell or just say {help} for more info.")

function playerBuyAddonNPC(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if (parameters.confirm ~= true) and (parameters.decline ~= true) then
        if(getPlayerPremiumDays(cid) == 0) and (parameters.premium == true) then
            npcHandler:say('Sorry, but this addon is only for premium players!', cid)
            npcHandler:resetNpc()
            return true
        end
        if (getPlayerStorageValue(cid, parameters.storageID) ~= -1) then
            npcHandler:say('You already have this addon!', cid)
            npcHandler:resetNpc()
            return true
        end
        local itemsTable = parameters.items
        local items_list = ''
        if table.maxn(itemsTable) > 0 then
            for i = 1, table.maxn(itemsTable) do
                local item = itemsTable[i]
                items_list = items_list .. item[2] .. ' ' .. getItemNameById(item[1])
                if i ~= table.maxn(itemsTable) then
                    items_list = items_list .. ', '
                end
            end
        end
        local text = ''
        if (parameters.cost > 0) and table.maxn(parameters.items) then
            text = items_list .. ' and ' .. parameters.cost .. ' gp'
        elseif (parameters.cost > 0) then
            text = parameters.cost .. ' gp'
        elseif table.maxn(parameters.items) then
            text = items_list
        end
        npcHandler:say('Did you bring me ' .. text .. ' for ' .. keywords[1] .. '?', cid)
        return true
    elseif (parameters.confirm == true) then
        local addonNode = node:getParent()
        local addoninfo = addonNode:getParameters()
        local items_number = 0
        if table.maxn(addoninfo.items) > 0 then
            for i = 1, table.maxn(addoninfo.items) do
                local item = addoninfo.items[i]
                if (getPlayerItemCount(cid,item[1]) >= item[2]) then
                    items_number = items_number + 1
                end
            end
        end
        if(getPlayerMoney(cid) >= addoninfo.cost) and (items_number == table.maxn(addoninfo.items)) then
            doPlayerRemoveMoney(cid, addoninfo.cost)
            if table.maxn(addoninfo.items) > 0 then
                for i = 1, table.maxn(addoninfo.items) do
                    local item = addoninfo.items[i]
                    doPlayerRemoveItem(cid,item[1],item[2])
                end
            end
            doPlayerAddOutfit(cid, addoninfo.outfit_male, addoninfo.addon)
            doPlayerAddOutfit(cid, addoninfo.outfit_female, addoninfo.addon)
            setPlayerStorageValue(cid,addoninfo.storageID,1)
            npcHandler:say('Here you are.', cid)
        else
            npcHandler:say('You do not have needed cash!', cid)
        end
        npcHandler:resetNpc()
        return true
    elseif (parameters.decline == true) then
        npcHandler:say('Not interested? Maybe other addon?', cid)
        npcHandler:resetNpc()
        return true
    end
    return false
end

local noNode = KeywordNode:new({'no'}, playerBuyAddonNPC, {decline = true})
local yesNode = KeywordNode:new({'yes'}, playerBuyAddonNPC, {confirm = true})

-- citizen (done)
local outfit_node = keywordHandler:addKeyword({'citizen'}, playerBuyAddonNPC, {premium = false, cost = 0, items = {{2160,100}}, outfit_female = 136, outfit_male = 128, addon = 1, storageID = 60001})
    outfit_node:addChildKeywordNode(yesNode)
    outfit_node:addChildKeywordNode(noNode)
local outfit_node = keywordHandler:addKeyword({'second citizen}, playerBuyAddonNPC, {premium = false, cost = 0, items = {{2160,200}}, outfit_female = 136, outfit_male = 128, addon = 2, storageID = 60002})
    outfit_node:addChildKeywordNode(yesNode)
    outfit_node:addChildKeywordNode(noNode)

keywordHandler:addKeyword({'addons'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can give you {citizen} addon.'})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You must say {citizen} or {second citizen} for the complete info.'})

npcHandler:addModule(FocusModule:new())

I got this

Code:
items = {{2160,100}}

Because i want it to cost 100 crystal coin, but you can put the ID item and the quantity you want, for example:

Code:
items = {{5890,100}, {5902,50}, {2480,1}}

I hope it works for you ^^
 
Back
Top