• 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 Emulation - Pure lua for 0.3 - 0.4 & 1.x

Codex NG

Recurrent Flamer
Joined
Jul 24, 2015
Messages
2,994
Solutions
12
Reaction score
1,657
If you are a developer like myself who doesn't want to launch an entire server just to test a script you are writing that contains storage values, theses functions and metamethods like emulation will help you test scripts in a lua interpreter.

Although I know there is no real difference in the distros when it comes to writing the code, these code fragments have been labeled accordingly per distro for your convenience :p

These functions behave almost exactly like the real functions or metamethods of the corresponding distro, just place them at the top of your script so you may call them as needed.

0.3 - 0.4
Code:
-- tables of the storages
local pStorage, gStorage = {}, {}

--- functions just for testing the script locally
function getPlayerStorageValue(cid, storage)
    return pStorage[storage] or -1
end

function setPlayerStorageValue(cid, storage, value)
    pStorage[storage] = value
end

function setGlobalStorageValue(storage, value)
    gStorage[storage] = value
end

function getGlobalStorageValue(storage)
    return gStorage[storage] or -1
end

1.x
Code:
-- player table of the storages
local player = {}

--- functions just for testing the script locally
function player:getStorageValue(storage)
    return self[storage] or -1
end

function player:setStorageValue(storage, value)
    self[storage] = value
end

-- global table of the storages
globalStorageTable = {}

Game = {}

function Game.getStorageValue(key)
    return globalStorageTable[key] or -1
end

function Game.setStorageValue(key, value)
    globalStorageTable[key] = value
end
 
Back
Top