• 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 The return value

Status
Not open for further replies.

Thys

New Member
Joined
Apr 8, 2013
Messages
5
Reaction score
0
Hello guys, makes some days that I am learning to program in LUA and min there was a doubt that not able to solve, I'm wanting to create an NPC that changes the price of items it sells, and before he change the price it checks if the player contains the storage value that I set up, if he has it assigns the new value and sends a message (which I created to test the function) is function should be performed at the time that the player appears in the NPC.

As a test I am using npc digger (selling pot in venore), soon after the line
Code:
local shopModule = ShopModule:new()

npcHandler:addModule(shopModule)

I added this:
Code:
local value = 0

function onCreatureAppear(cid)

if(getPlayerStorageValue(cid,2203) == 2203 or getPlayerStorageValue(cid,2203) == 1 ) then

  value = 10

  doBroadcastMessage("OI THYAGO VOCE RECEBEU 10 DE DESCONTO NA MINHA LOJA", 22)

else

  value = 5

end

return value

end

I am wanting to change the value of the Health Potion, that is, if the player has the storage value 2203 (which I setup) it will decrease 10, that is, by default the value of the Health Potion is 45, with the "discount" has to be 35
Code:
shopModule:addBuyableItem({'health potion'}, 7618, 45-value, 1, 'health potion')

Well..He is validating certain, is not only changing the value, that is, it continues with the value of the local variable (which is 0).

Could help me??

To prove that the validation is being performed correctly, there's a print of the message that appears if the player has the storage value that I setup:
l35184printotj.gif

I hope to help, thanks :)
 
Last edited:
From Taibaner's script
Code:
local trade = {
    [7618] = {price = 45, discount = 35}, 
}


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


local trade = {
    [7618] = {price = 45, discount = 35}, 
}


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 shopWindow = {}


    local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
        if trade[item] and not doPlayerRemoveMoney(cid, trade[item].price*amount) then
            selfSay("You don't have enough money.", cid)
        else
            doPlayerAddItem(cid, item, amount)
            doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. trade[item].price*amount .. " gold.")
            --selfSay("Here you are!", cid)
        end
        return true
    end
    
    local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
        doPlayerRemoveItem(cid, item, amount)
        doPlayerAddMoney(cid, trade[item].discount*amount)
        doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. trade[item].price*amount .. " gold.")
        --selfSay("Here you are!", cid)
        return true
    end


    if msgcontains(msg, 'trade') then
        selfSay(getCreatureStorage(cid, 2203) > 0 and "OI THYAGO VOCE RECEBEU 10 DE DESCONTO NA MINHA LOJA" or "These are my offers.", cid)
        for var, ret in pairs(trade) do
            table.insert(shopWindow, {id = var, subType = 0, buy = getCreatureStorage(cid, 2203) > 0 and ret.discount or ret.price, sell = 0, name = getItemNameById(var)})
        end
        openShopWindow(cid, shopWindow, onBuy, onSell)
    end
    return true
end


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Status
Not open for further replies.
Back
Top