peonso / tibialegacyserver

Tibia Legacy Server is a OpenTibia 7.72 real map server.
32 stars 29 forks source link

npcs don't buy empty vials, or buy filled ones together #79

Closed peonso closed 8 years ago

peonso commented 8 years ago

https://github.com/peonso/tibialegacyserver/issues/78#issuecomment-250509710

shopModule:addSellableItem({'vial', 'potion', 'flask'}, 2006, 5)

if msgcontains(msg, 'vial') then
npcHandler:say("I will give you 5 gold for every empty vial of yours, accept?", 1)
talk_state = 857
elseif talk_state == 857 and msgcontains(msg, 'yes') then
    if SellPlayerEmptyVials(cid) == true then
    npcHandler:say("Here's your money!", 1)
    talk_state = 0
    else
    npcHandler:say("You don't have any empty vials!", 1)
    talk_state = 0
    end
end
tarantonio commented 8 years ago

@peonso , do you have this function in libs?

function SellPlayerEmptyVials(cid)
    emptyvialmoney = 0
    while doPlayerRemoveItem(cid, 2006, 1, 0) == true do
        emptyvialmoney = (emptyvialmoney+5)
    end
    if getNumberValue(emptyvialmoney) > 0 then
        doPlayerAddMoney(cid, getNumberValue(emptyvialmoney))
        return true
    else
        return false
    end
end
peonso commented 8 years ago

No, it works 100%? I was thinking about update sell module, some NPCs are using it and it bugs, it buy full vials.

tarantonio commented 8 years ago

Try my code first, if it works ok you'll have more time to think about sell module

peonso commented 8 years ago

Thanks @tarantonio!

This:

function sellPlayerEmptyVials(cid)
    local emptyvialmoney = 0
    while doPlayerRemoveItem(cid, 2006, 1, 0) == true do
        emptyvialmoney = 5 + emptyvialmoney
    end
    if emptyvialmoney > 0 then
        doPlayerAddMoney(cid, emptyvialmoney)
        return true
    else
        return false
    end
end

And this:

if msgcontains(msg, 'vial') or msgcontains(msg, 'deposit') or msgcontains(msg, 'flask') then
    npcHandler:say("I will pay you 5 gold for every empty vial. Ok?", 1)
    talk_state = 857
elseif talk_state == 857 and msgcontains(msg, 'yes') then
    if sellPlayerEmptyVials(cid) == true then
        npcHandler:say("Here's your money!", 1)
        talk_state = 0
    else
        npcHandler:say("You don't have any empty vials!", 1)
        talk_state = 0
    end
end