• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Only one time quest

tarantonio

Old School Player
Joined
Jun 21, 2009
Messages
868
Solutions
1
Reaction score
286
I used site search but didn't found anything related.

I need to make a quest with item reward but it needs to be the only one on whole server, so the first to make the quest will be the only one to own that item.

How do you set a quest to be made only one time?
 
If you are using TFS 1.x,

All global storage is wiped when the server shuts down.

If you want people to be able to complete the quest every day (if you have a daily restart) you can use globalstorage.
If you want the quest to only be done once at all, you would need to use something else
 
Nice to see that there isn't a way to store a global persistent value.
Anyone have a workaround for this? (mule character, new table...)
 
IDOFYOURITEM = ID of reward item

put it on your actions.xml
<action itemid="15640" script="Archive/Reward.lua"/>
or you can use an action
<action actionid="15640" script="Archive/Reward.lua"/>

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)     
     
        local player = Player(cid)         
        if getGlobalStorageValue(77777) <= 0 then
            doPlayerAddItem(cid,IDOFYOURITEM,1)
            setGlobalStorageValue(77777, 1)
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Congratulations, you just got your reward.")     
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Sorry, someone already completed the quest and got the reward.")
        end
     
    return true
end
 
You can add new functions for global database storage. Taken from here

I'll post the working code here (tfs 1.2 tested) since the above link is confusing to implement.

Adding Database/permanent global storage:

The table stores strings up to 255 chars.
calling getStorageValue(key) where no value was set returns -1
otherwise it stores the string that is stored.

In data/lib/compat.lua add the functions:
LUA:
function getGlobalStorageValueDB(key)
    local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
    if resultId ~= false then
        local val = result.getString(resultId, "value")
        result.free(resultId)
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", '".. value .."') ON DUPLICATE KEY UPDATE `value` = '".. value.."'")
end

Run this on your database:
Code:
CREATE TABLE `global_storage`
(
    `key` INT UNSIGNED NOT NULL,
    `value` VARCHAR(255) NOT NULL DEFAULT '0',
    UNIQUE  (`key`)
) ENGINE = InnoDB;
 
IDOFYOURITEM = ID of reward item

put it on your actions.xml
<action itemid="15640" script="Archive/Reward.lua"/>
or you can use an action
<action actionid="15640" script="Archive/Reward.lua"/>

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)    
    
        local player = Player(cid)        
        if getGlobalStorageValue(77777) <= 0 then
            doPlayerAddItem(cid,IDOFYOURITEM,1)
            setGlobalStorageValue(77777, 1)
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Congratulations, you just got your reward.")    
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"Sorry, someone already completed the quest and got the reward.")
        end
    
    return true
end
On reset globalstorage is deleted, I need to set it to be permanent.
 
You can add new functions for global database storage. Taken from here

I'll post the working code here (tfs 1.2 tested) since the above link is confusing to implement.

Adding Database/permanent global storage:

The table stores strings up to 255 chars.
calling getStorageValue(key) where no value was set returns -1
otherwise it stores the string that is stored.

In data/lib/compat.lua add the functions:
LUA:
function getGlobalStorageValueDB(key)
    local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key)
    if resultId ~= false then
        local val = result.getString(resultId, "value")
        result.free(resultId)
        return val
    end
    return -1
end

function setGlobalStorageValueDB(key, value)
    db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (".. key ..", '".. value .."') ON DUPLICATE KEY UPDATE `value` = '".. value.."'")
end

Run this on your database:
Code:
CREATE TABLE `global_storage`
(
    `key` INT UNSIGNED NOT NULL,
    `value` VARCHAR(255) NOT NULL DEFAULT '0',
    UNIQUE  (`key`)
) ENGINE = InnoDB;
Thx I'll try
 
Back
Top