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

TFS 1.2 What im doing wrong in this storage check

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
529
Reaction score
56
Hello, trying to add storage check if player dont have storage X, npc would send message "You have to do blalbalbla first" and if he do have X storage everything would go like normal.

so i created local like
Lua:
local testMission = { 
    [1] = {
        rankName = "test",
        mainStorage = 13251, 
        needstorage = 13250,
its not full config but it gives a sample

then im doing this which doesnt work

Lua:
function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    local vocationId = player:getVocation():getId()

    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)

            if player:getStorageValue(testMission.needstorage) then
            npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("You have to finish previous missions first!", cid)
        end
    else
            return false
        end
    end
so as you can see trying to add getstoragevalue if he doesnt have that storage it sends npcHandler:say("You have to finish previous missions first!", cid) but if he does have it sends
npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
npcHandler.topic[cid] = 0
but my shit doesnt work :D
 
Solution
Getting no errors it just still allows to speak with that npc without having that storage

If you left the code as-is, then you aren't comparing the storage value to anything.

change
Lua:
if player:getStorageValue(rankMission[1].needstorage) then
to
Lua:
if player:getStorageValue(rankMission[1].needstorage) > 0 then

Lua:
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)
            if player:getStorageValue(rankMission[1].needstorage) > 0 then
                npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
                npcHandler.topic[cid] = 0...
Hello, trying to add storage check if player dont have storage X, npc would send message "You have to do blalbalbla first" and if he do have X storage everything would go like normal.

so i created local like
Lua:
local testMission = {
    [1] = {
        rankName = "test",
        mainStorage = 13251,
        needstorage = 13250,
its not full config but it gives a sample

then im doing this which doesnt work

Lua:
function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    local vocationId = player:getVocation():getId()

    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)

            if player:getStorageValue(testMission.needstorage) then
            npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("You have to finish previous missions first!", cid)
        end
    else
            return false
        end
    end
so as you can see trying to add getstoragevalue if he doesnt have that storage it sends npcHandler:say("You have to finish previous missions first!", cid) but if he does have it sends
npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
npcHandler.topic[cid] = 0
but my shit doesnt work :D

Your table is setup like this
Lua:
tableName[key].key = value
But you are currently accessing it like this
Lua:
tableName.key = value

So instead of this..
Lua:
testMission.needstorage
you need to do this
Lua:
testMission[1].needstorage
 
Your table is setup like this
Lua:
tableName[key].key = value
But you are currently accessing it like this
Lua:
tableName.key = value

So instead of this..
Lua:
testMission.needstorage
you need to do this
Lua:
testMission[1].needstorage
Hmm unfortunately didnt worked
 
Getting no errors it just still allows to speak with that npc without having that storage

If you left the code as-is, then you aren't comparing the storage value to anything.

change
Lua:
if player:getStorageValue(rankMission[1].needstorage) then
to
Lua:
if player:getStorageValue(rankMission[1].needstorage) > 0 then

Lua:
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)
            if player:getStorageValue(rankMission[1].needstorage) > 0 then
                npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You have to finish Angel missions first!", cid)
                -- probably want to release focus here
            end
        else
            return false
        end
    end
 
Solution
If you left the code as-is, then you aren't comparing the storage value to anything.

change
Lua:
if player:getStorageValue(rankMission[1].needstorage) then
to
Lua:
if player:getStorageValue(rankMission[1].needstorage) > 0 then

Lua:
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)
            if player:getStorageValue(rankMission[1].needstorage) > 0 then
                npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You have to finish Angel missions first!", cid)
                -- probably want to release focus here
            end
        else
            return false
        end
    end
Still same
 
Hello, trying to add storage check if player dont have storage X, npc would send message "You have to do blalbalbla first" and if he do have X storage everything would go like normal.

so i created local like
Lua:
local testMission = {
    [1] = {
        rankName = "test",
        mainStorage = 13251,
        needstorage = 13250,
its not full config but it gives a sample

then im doing this which doesnt work

Lua:
function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    local vocationId = player:getVocation():getId()

    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)

            if player:getStorageValue(testMission.needstorage) then
            npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("You have to finish previous missions first!", cid)
        end
    else
            return false
        end
    end
so as you can see trying to add getstoragevalue if he doesnt have that storage it sends npcHandler:say("You have to finish previous missions first!", cid) but if he does have it sends
npcHandler:say("Hello, " .. player:getName() .. ". test mission: " .. getRanksString() .. ".", cid)
npcHandler.topic[cid] = 0
but my shit doesnt work :D
You have
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
and other functions define in script?
 
Is the npc saying anything?

Give us screenshots or something.
I don't want to sit here and guess.
Yes it says
npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
 
Yes it says
npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
Then your character has that storage above 0.

Reset the storage, or create a new character to test.
Lua:
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)
            print("Player storage value = " .. player:getStorageValue(rankMission[1].needstorage))
            if player:getStorageValue(rankMission[1].needstorage) > 0 then
                npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You have to finish Angel missions first!", cid)
                -- probably want to release focus here
            end
        else
            return false
        end
    end
 
Then your character has that storage above 0.

Reset the storage, or create a new character to test.
Lua:
    if not npcHandler:isFocused(cid) then
        if msg == "hi" or msg == "hello" then
            npcHandler:addFocus(cid)
            print("Player storage value = " .. player:getStorageValue(rankMission[1].needstorage))
            if player:getStorageValue(rankMission[1].needstorage) > 0 then
                npcHandler:say("Welcome, " .. player:getName() .. ". Choose mission by rank: " .. getRanksString() .. ".", cid)
                npcHandler.topic[cid] = 0
            else
                npcHandler:say("You have to finish Angel missions first!", cid)
                -- probably want to release focus here
            end
        else
            return false
        end
    end
Yea you right somehow it got that storage. How no idea how. But it works now thanks
 
Back
Top