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

Someone just check this row and tell me if u see any error.

Ezzam

New Member
Joined
Jan 16, 2008
Messages
213
Reaction score
2
Code:
local monsters = {
	--name = storage
	["orc spearman"] = 35003,
}
local name = getCreatureName(target)
local monster = monsters[string.lower(name)]

ERROR vvvvvvvvvv
Code:
if getPlayerStorageValue(cid, orc spearman) == -1 then

THS 0.3.4 :::::::::: ERROR =
Code:
....lua:38 ')' expected near 'spearman'
 
if you want get a storageString the use this function (Credits to Remere - OtFans)

An example:
Lua:
setPlayerStorageString(cid, 230, "OMG HE COMPLETD QUESTZ")
if getPlayerStorageString(cid, 230) == "OMG HE COMPLETD QUESTZ" then
    -- something?
end

Note 1: Maximum length for a string is 3096 characters, but that should be enough to go around.
Note 2: Saved strings are NOT binary compatible, if there is a \0 in the string, it won't work properly.
Note 3: You can no longer use storage values greater than 2147483648. This is somewhat mitigated by the fact that you hardly need those values anyways.
Note 4: PlayerStorageString & PlayerStorageValue does not use the same keys, so you can store an integer at index 430 and a string at the same index.
Note 5: Also added getPlayerStorageInteger/setPlayerStorageInteger for coherency.

To use it, simply put this in data/lib/function.lua:

Lua:
_warpzone = 2147483648 -- start storing strings here (THIS IS THE ABSOLUTE MAXIMUM VALUE FOR THIS)
_maxlength = 1024 -- multiply by 3 to get the true length.

setPlayerStorageInteger = setPlayerStorageValue
getPlayerStorageInteger = getPlayerStorageValue

function setPlayerStorageString(cid, key, value)
    if #value > (_maxlength-1) * 3 - 1 then -- Last word is reserved for 0 termination of the string.
        error("Storage string is too long")
    end
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
    
    local word = 0
    local wordwrap = 0
    local wordcount = 0
    local i = 1
    while i <= #value do
        local byte = string.byte(string.sub(value, i, i))
        word = bit.bor(word, bit.lshift(byte, wordwrap))
        wordwrap = wordwrap + 8
        if wordwrap == 24 then
            --[[
                In the ideal world we would be able to store 4 characters per word,
                however, as the default return value for getPlayerStorageValue is
                -1, we can't use the last bit.
            ]]--
            setPlayerStorageInteger(cid, key + wordcount, word)
            word = 0
            wordwrap = 0
            wordcount = wordcount + 1
        end
        i = i + 1
    end
    -- store the last word
    setPlayerStorageInteger(cid, key + wordcount, word)
end

function getPlayerStorageString(cid, key)
    if key > _warpzone / _maxlength then
        error("Storage string key is too large (" .. key .. ")")
    end
    key = _warpzone + key * _maxlength
    
    local wordcount = 0
    local str = ""
    while true do
        if wordcount >= _maxlength then
            break
        end
        local word = getPlayerStorageInteger(cid, key + wordcount)
        if word == -1 then
            -- end of string
            break
        else 
            -- Extract the 3 characters from the value
            byte = bit.band(word, 255)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 65280), 8)
            if byte == 0 then break else str = str .. string.char(byte) end
            byte = bit.rshift(bit.band(word, 16711680), 16)
            if byte == 0 then break else str = str .. string.char(byte) end
        end
        wordcount = wordcount + 1
    end
    return str
end
 
##################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#~~####~~~#~~~#~~~#~~~#~~~####~~~#
#~~#~~~#~~#~~~#~~#~#~#~#~~#~~~#~~#
#~~####~~~#~~~#~~#~~#~~#~~####~~~#
#~~#~~~#~~#~~~#~~#~~~~~#~~#~~~~~~#
#~~####~~~~###~~~#~~~~~#~~#~~~~~~#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
##################################
 
Last edited:
##################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#~~####~~~#~~~#~~~#~~~#~~~####~~~#
#~~#~~~#~~#~~~#~~#~#~#~#~~#~~~#~~#
#~~####~~~#~~~#~~#~~#~~#~~####~~~#
#~~#~~~#~~#~~~#~~#~~~~~#~~#~~~~~~#
#~~####~~~~###~~~#~~~~~#~~#~~~~~~#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
##################################
 
Back
Top