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

When storage is 20, add mount to player

Deepling

Just a spammer
Joined
Jun 29, 2015
Messages
1,835
Solutions
1
Reaction score
555
Location
Poland
Hello!

Could someone help me with script that makes player with storage 2500 = 20 get War Horse mount and when storage 2500 = 40 add Armoured Fire Horse?

I'm using TFS 1.3 version 10.99

Thanks!
 
Last edited:
Solution
Lua:
function onLogin(player)
    if (player:getStorageValue(2500) == 20 and not player:hasMount(17)) then
        player:addMount(17)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You received War Horse!")
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    elseif (player:getStorageValue(2500) == 40 and not player:hasMount(23)) then
        player:addMount(23)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You received Armoured War Horse!")
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    end
 
    return true
end
You don't said when a player should get, used onLogin.
I'm not good, but hope it works, can't test because I don't have 10.99 client.

edit.
Fixed elseif, thanks @Xikini
Lua:
function onLogin(player)
    if (player:getStorageValue(2500) == 20 and not player:hasMount(17)) then
        player:addMount(17)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You received War Horse!")
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    elseif (player:getStorageValue(2500) == 40 and not player:hasMount(23)) then
        player:addMount(23)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You received Armoured War Horse!")
        player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS)
    end
 
    return true
end
You don't said when a player should get, used onLogin.
I'm not good, but hope it works, can't test because I don't have 10.99 client.

edit.
Fixed elseif, thanks @Xikini
 
Last edited:
Solution
It can be NPC script, when you say "war horse" and your storage 2500 is 20 or higher you get mount, else NPC say "You don't have enough points"
 
Lua:
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

local temp = {}

local cfg = {
    stg = 2500, -- The storage,

    buyAble = {
        ['war horse'] = {
            cost = 20, -- The amount it should cost to get the mount.
            mountId = 17, -- The id of the mount.
        },
        ['armoured fire horse'] = {
            cost = 40,
            mountId = 18,
        },
    },

}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if npcHandler.topic[cid] < 2 then
       if msgcontains(msg, 'offers') then
            local str = "I have these mount"..(#cfg.buyAble > 1 and "s " or " ").."to offer: "
            for k,v in pairs(cfg.buyAble) do
                str = str .. "({"..k.."}) "
            end  
            selfSay(str, cid)
            npcHandler.topic[cid] = 2
            temp[cid] = nil
        end
    elseif npcHandler.topic[cid] == 2 then 
        for k,v in pairs(cfg.buyAble) do
            if msg == k then
                selfSay('Are you sure you would like to buy the '..k..' mount for '..cfg.buyAble[k].cost..' points?', cid)  
                npcHandler.topic[cid] = 3
                temp[cid] = k
                break
            end
        end
    elseif npcHandler.topic[cid] == 3 then
        if msgcontains(msg, 'yes') then
            if temp[cid] ~= nil then
                if player:getStorageValue(cfg.stg) >= cfg.buyAble[temp[cid]].cost then
                    if not player:hasMount(cfg.buyAble[temp[cid]].mountId) then
                        player:addMount(cfg.buyAble[temp[cid]].mountId)
                        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
                        player:setStorageValue(cfg.stg, (player:getStorageValue(cfg.stg)-cfg.buyAble[temp[cid]].cost))
                        selfSay('Hope you enjoy your new mount!', cid)
                    else
                        selfSay('Sorry, buy you already have this mount.', cid)
                    end
                else
                    selfSay('Sorry.. You still need '..(player:getStorageValue(cfg.stg) < 0 and cfg.buyAble[temp[cid]].cost or cfg.buyAble[temp[cid]].cost-player:getStorageValue(cfg.stg))..' points in order to buy this mount. Come back once you have them', cid)
                end
            else
                selfSay('Sorry, somethings not right. Please try again later.', cid)
                print('Error: Got to .Buy mount. With a nil value on Temp[cid].')
            end
        elseif msgcontains(msg, 'no') then
            selfSay('Would you like to look at my {offers} again?', cid)
        end                  
        npcHandler.topic[cid] = 0
        temp[cid] = nil
    end

    return true
end

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

Should be working.
If you have any problems just tell me.
Regards Alw
 
Only scripting error I see in Duke's code was a space on line 6.
Code:
else if
elseif
It really should give an error, as there would be a missing "end".

I don't know 1.x+ scripting enough to help further though.

Npc above looks good.
Not sure if he wants the points removed though.
From the discussion so far, I don't think he wants the points removed, but no way to know unless he tells us.
 
Only scripting error I see in Duke's code was a space on line 6.
Code:
else if
elseif
It really should give an error, as there would be a missing "end".

I don't know 1.x+ scripting enough to help further though.

Npc above looks good.
Not sure if he wants the points removed though.
From the discussion so far, I don't think he wants the points removed, but no way to know unless he tells us.
Works now, cheers! :)

Lua:
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

local temp = {}

local cfg = {
    stg = 2500, -- The storage,

    buyAble = {
        ['war horse'] = {
            cost = 20, -- The amount it should cost to get the mount.
            mountId = 17, -- The id of the mount.
        },
        ['armoured fire horse'] = {
            cost = 40,
            mountId = 18,
        },
    },

}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if npcHandler.topic[cid] < 2 then
       if msgcontains(msg, 'offers') then
            local str = "I have these mount"..(#cfg.buyAble > 1 and "s " or " ").."to offer: "
            for k,v in pairs(cfg.buyAble) do
                str = str .. "({"..k.."}) "
            end 
            selfSay(str, cid)
            npcHandler.topic[cid] = 2
            temp[cid] = nil
        end
    elseif npcHandler.topic[cid] == 2 then
        for k,v in pairs(cfg.buyAble) do
            if msg == k then
                selfSay('Are you sure you would like to buy the '..k..' mount for '..cfg.buyAble[k].cost..' points?', cid) 
                npcHandler.topic[cid] = 3
                temp[cid] = k
                break
            end
        end
    elseif npcHandler.topic[cid] == 3 then
        if msgcontains(msg, 'yes') then
            if temp[cid] ~= nil then
                if player:getStorageValue(cfg.stg) >= cfg.buyAble[temp[cid]].cost then
                    if not player:hasMount(cfg.buyAble[temp[cid]].mountId) then
                        player:addMount(cfg.buyAble[temp[cid]].mountId)
                        player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
                        player:setStorageValue(cfg.stg, (player:getStorageValue(cfg.stg)-cfg.buyAble[temp[cid]].cost))
                        selfSay('Hope you enjoy your new mount!', cid)
                    else
                        selfSay('Sorry, buy you already have this mount.', cid)
                    end
                else
                    selfSay('Sorry.. You still need '..(player:getStorageValue(cfg.stg) < 0 and cfg.buyAble[temp[cid]].cost or cfg.buyAble[temp[cid]].cost-player:getStorageValue(cfg.stg))..' points in order to buy this mount. Come back once you have them', cid)
                end
            else
                selfSay('Sorry, somethings not right. Please try again later.', cid)
                print('Error: Got to .Buy mount. With a nil value on Temp[cid].')
            end
        elseif msgcontains(msg, 'no') then
            selfSay('Would you like to look at my {offers} again?', cid)
        end                 
        npcHandler.topic[cid] = 0
        temp[cid] = nil
    end

    return true
end

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

Should be working.
If you have any problems just tell me.
Regards Alw

This one also works, for sure I will have use of it ^^

Thanks for help @DukeeH @Alw and @Xikini ;)



 
Back
Top