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

How to have price = storage?? -- NPCS

Dangnoob

Member
Joined
Jun 8, 2008
Messages
105
Solutions
2
Reaction score
12
So im stuck right now on how to make it so a price equals a storage value. I really dont understand much about how these npcs work at all. I tried one form,

Code:
function onCreatureSay(cid, type, msg)
    if((msg == "hi") and not (isFocused(cid))) then
        local lvlupprice = ((getPlayerStorageValue(cid, 8080) - 79 ) * 50)
        selfSay("Hello, ".. getCreatureName(cid) .." welcome to the mage shop!", cid, true)
        selfSay("Would you like to see my {offers}?", cid)
        addFocus(cid)
    elseif((isFocused(cid)) and (msg == "wares" or msg == "trade")) then
    local lvlupprice = ((getPlayerStorageValue(cid, 8080) - 79 ) * 50)
        selfSay("You can buy a level up stone here! Buy a level stone up for " .. lvlupprice .. " gold?", cid)
    if (msg == "yes") then
    doPlayerRemoveMoney(cid, lvlupprice)
    end
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid, true)
        closeShopWindow(cid)
        removeFocus(cid)
    end
end


Didn't work, i dont understand how to make the npc take the money.... and then i tried the other lua style that i saw with all the shopModule:addBuyableItem in it, but it appears i cant add an item into the shop except in the beginning..? tried throwing it into here, when you start talking. It didn't work.

Code:
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   
    local lvlupprice = ((getPlayerStorageValue(cid, 8080) - 79 ) * 50)   
   
    shopModule:addBuyableItem({'spellbook'}, 2175, 200, 'spellbook')
   
    if(msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand')) then
        if(isSorcerer(cid) or isDruid(cid)) then
            if(getPlayerStorageValue(cid, 30002) <= 0) then
                selfSay('So you ask me for a {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
                talkState[talkUser] = 1
            else
                selfSay('What? I have already gave you one {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end


Anybody have any idea as to how i could do this? Thx in advance if you can help.
 
What if storage - 79 <= 0? then you would have a strange error.

Any how, you want to base your price on a storage value? Why do you need to substract 79 from that certain value?
 
I do that because of the way my server works. Their level is saved in that storage value. So to increase your level it is, 50 gold for your first level. Aka storage value 80. 100 gold, value 81. So i minus 79 to bring it down to one. So i can make it go up buy 50 each time instead of starting at 80 × 50. @Danger II i never said just do it lol u read wrong. I said i just do. But either way. The storage value doesnt really matter that much. I literally just don't understand how npcs work. If somebody could post a merchant npc in lua or something i could then make this whole script. I just dont get how the whole reply system works and the taking money thing. Nobody would be able to access this npc.below level 80, so it would never make that storage value below 80. 80-79=1. Never lower.
 
If you go your lib/npcsystem/modules.lua, you should find something like this:

Lua:
    function ShopModule:addBuyableItem(names, itemid, cost, subType, realName)

So you can try replacing the next piece of code in your npc script:

Lua:
shopModule:addBuyableItem({'spellbook'}, 2175, 200, 'spellbook')

to this:

Lua:
shopModule:addBuyableItem({'spellbook'}, 2175, lvlupprice, 'spellbook')

Try this and post if you get any errors.

P.S.: Btw, remember to be sure that lvlupprice is a number and that it is bigger than 0.
 
I tried that already. It doesnt work :/ It tries to constantly get the lvlupprice. But it cant because the npc isnt talking to anybody yet. So it cant get the storage value.
 
It's a bit strange, since you should run a function like this, and it is supossed to work when the npc is talking with a player:

Lua:
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, 'first rod') or msgcontains(msg, 'first wand')) then
        if(isSorcerer(cid) or isDruid(cid)) then
            if(getPlayerStorageValue(cid, 30002) <= 0) then
                selfSay('So you ask me for a {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
                talkState[talkUser] = 1
            else
                selfSay('What? I have already gave you one {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif(msgcontains(msg, 'yes')) then
        if(talkState[talkUser] == 1) then
            doPlayerAddItem(cid, items[getPlayerVocation(cid)], 1)
            selfSay('Here you are young adept, take care yourself.', cid)
            setPlayerStorageValue(cid, 30002, 1)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    end

    return true
end

Anyway, try this:

Lua:
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, 'items')) then
        local lvlupprice = ((getPlayerStorageValue(cid, 8080) - 79 ) * 50)
        shopModule:addBuyableItem({'spellbook'}, 2175, lvlupprice, 'spellbook')
    end

    return true
end

Say "hi" and "items" to the npc before saying "spellbook".
 
Back
Top