• 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 (TFS 1.4) NPC who give money only one time per character, no per account.

Nyarl666

Member
Joined
Sep 25, 2022
Messages
63
Reaction score
7
Hello.
It overwhelmed me :(
I need an NPC (in TFS 1.4) that gives 10,000 gp to each character only once. Not once an account, but only once per each character from the account.
Now it only gives money if you don't keep it with you. If you throw them out, you can take another one over and over again :(

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Kasian" script="Kasian.lua" walkinterval="2000" floorchange="0" speechbubble="3">
    <health now="100" max="100" />
    <look type="128" head="94" body="113" legs="132" feet="115" addons="2" />
</npc>


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

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if msgcontains(msg, "yes") then
        if player:getMoney() >= 10000 then
        selfSay("You can not take it anymore.", cid)
        else
        selfSay("Enjoy game.", cid)
        player:addItem(2160, 1)
        end
        return
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "|PLAYERNAME|. I am the messenger of King Worldianus. Each newcomer gets 10000 gp to start. Want? By the way, welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!")

npcHandler:addModule(FocusModule:new())
 
Solution
Lua:
    if msgcontains(msg, "yes") then
        if player:getMoney() >= 10000 then
        selfSay("You can not take it anymore.", cid)
        else
        selfSay("Enjoy game.", cid)
        player:addItem(2160, 1)
        end
        return
    end

replace with

Lua:
    local storage = 5000
    if msgcontains(msg, "yes") then
        if player:getStorageValue(storage) == -1 then
            player:addItem(2160, 1)
            player:setStorageValue(storage, 1)
            selfSay("Enjoy game.", cid)
        else
            selfSay("You can not take it anymore.", cid)
        end
    end
Lua:
    if msgcontains(msg, "yes") then
        if player:getMoney() >= 10000 then
        selfSay("You can not take it anymore.", cid)
        else
        selfSay("Enjoy game.", cid)
        player:addItem(2160, 1)
        end
        return
    end

replace with

Lua:
    local storage = 5000
    if msgcontains(msg, "yes") then
        if player:getStorageValue(storage) == -1 then
            player:addItem(2160, 1)
            player:setStorageValue(storage, 1)
            selfSay("Enjoy game.", cid)
        else
            selfSay("You can not take it anymore.", cid)
        end
    end
 
Solution
Lua:
    if msgcontains(msg, "yes") then
        if player:getMoney() >= 10000 then
        selfSay("You can not take it anymore.", cid)
        else
        selfSay("Enjoy game.", cid)
        player:addItem(2160, 1)
        end
        return
    end

replace with

Lua:
    local storage = 5000
    if msgcontains(msg, "yes") then
        if player:getStorageValue(storage) == -1 then
            player:addItem(2160, 1)
            player:setStorageValue(storage, 1)
            selfSay("Enjoy game.", cid)
        else
            selfSay("You can not take it anymore.", cid)
        end
    end
Thank you very very very much! And when I want make another NPC like this I can use this same local storage = 5000 or another? Example: local storage = 5001
 
yeah use a different storage ( make sure the storage has not been used somewhere alredy )
okey. And whats happen when I dont have space? or will it be too heavy? Will he put me underneath? Will he not give it to me? And if it doesn't, will it add +1 to local storage or not?
THX and sorry for question
 
Last edited:
Lua:
    local storage = 5000
    if msgcontains(msg, "yes") then
        if player:getStorageValue(storage) == -1 then
            player:addItem(2160, 1)
            player:setStorageValue(storage, 1)
            selfSay("Enjoy game.", cid)
        else
            selfSay("You can not take it anymore.", cid)
        end
    end

replace with

Lua:
    local storage = 5000
    if msgcontains(msg, "yes") then
        if player:getStorageValue(storage) == 1 then
            selfSay("You can not take it anymore.", cid)
            return true
        end
        local item = Game.createItem(2160, 1)
        if player:addItemEx(item) == RETURNVALUE_NOERROR then
            player:setStorageValue(storage, 1)
            selfSay("Enjoy game.", cid)
        else
            selfSay("It seems like the item is to heavy or you dont have space.", cid)
        end
    end
 
Back
Top