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

Check function (not fully tested/report bugs)

Summ

(\/)(;,,;)(\/) Y not?
Staff member
Global Moderator
Joined
Oct 15, 2008
Messages
4,152
Solutions
12
Reaction score
1,107
Location
Germany :O
Hi

I wanted to release a (maybe) useful function.
For example if you have a spell and want to do it as a spell you will need many checks for example mana/soul/level and such..

Function:
Lua:
local functions = {  --predefined functions so you can use "mp" instead of getCreatureMana
    ["hp"] = {getCreatureHealth, "You need more health.", doCreatureAddHealth},
    ["mp"] = {getCreatureMana, "You need more mana.", doPlayerAddMana},
    ["maxhp"] = {getCreatureMaxHealth, "Your max health is too low."},
    ["maxmp"] = {getCreatureMaxMana, "Your max mana is too low."},
    ["soul"] = {getPlayerSoul, "You don't have enough soul points."},
    ["speed"] = {getCreatureSpeed, "You aren't fast enough."}
}

function verify(uid, effects, ...)
    local p, error = {...}, 0
    for c = 1, #p do
        local func = {type(p[c][1]) == "function" and p[c][1] or functions[p[c][1]][1], ((type(p[c][3]) == "string" and p[c][3]:gsub("|VAL|", (type(p[c][2]) == "table" and "between " .. p[c][2][1] .. " and " .. p[c][2][2]) or (p[c][2]))) or (not(p[c][3]) and functions[p[c][1]]) and functions[p[c][1]][2] or "")}
        
        local check
        if type(p[c][2]) == "table" then
            check = (func[1](uid) >= p[c][2][1] and func[1](uid) <= p[c][2][2])
        else
            check = (func[1](uid) >= p[c][2])
        end
        
        if not (check) then
            error = func[2]
            break
        end        
    end
    if isNumber(error) then
        for c = 1, #p do
            if not (type(p[c][2]) == "table") then
                local func_ = {(p[c][4] == "function" and p[c][4] or (p[c][4] and functions[p[c][1]]) and (functions[p[c][1]][3] == nil and nil or functions[p[c][1]][3])), ((p[c][5] or (functions[p[c][1]] and functions[p[c][1]][4])) and p[c][2] or -p[c][2])}
                if type(func_[1]) == "function" then
                    func_[1](uid, func_[2], true)
                end
            end
        end    
        return doSendMagicEffect(getThingPos(uid), effects[1])
    end

    return (doSendMagicEffect(getThingPos(uid), effects[2]) and doPlayerSendCancel(uid, error)) and false or false
end

example uses:
-verify(cid, {12, 2}, {"hp", 35, nil, true})
{12,2} are the effects shown. 12 if every check is true. 2 if a check is false
"hp" is defined in the "functions" array and it checks the players health
35 -> the health must be >= 35
nil -> says that the function should use the defined phrase if the condition is false: in this case "You need more health."
true -> the function shall remove health from the player

-verify(cid, {12, 2}, {"hp", {3, 10}, "Your health need to be |VAL|."})
The health of the player need to be between 3 and 10.
"Your health need to be |VAL|" -> is now the cancel message; |VAL| will be replaced with "between 3 and 10"

-verify(cid, {12, 2}, {"hp", 10, "Your health need to be |VAL|."})
same as up just that the players health must be >= 10

-verify(cid, {12, 2}, {"hp", 10, "Your health need to be |VAL|.", true})
same as up, but the function will remove the 10 health points

-verify(cid, {12, 2}, {getPlayerHealth, 100, true})
Instead of "hp" you can put a function like: getPlayerHealth
Health need to be >= 100 and there won't be a message if the condition is false

-verify(cid, {12, 2}, {getPlayerHealth, 100, "Your health need to be |VAL|"})
Same as up but with this it will show "Your health need to be 100" if the condition is false

USE:
if verify(uid, {effect1, effect2}, {functionToCheck, value/{value1, value2}, message, removeFunction}) then
--CASTSPELL--
end

ofc you can use more conditions like:
verify(cid, {12, 2}, {"hp", 35, nil, true}, {"mp", 100, "You need more then |VAL| mana.", true})

Since the function is hard to describe how you have to put every parameter and how it works, it could be hard for you to understand how to use it. But if you understand it the function can be useful if you have to check many values..
If you don't know how to write a certain condition with this function just ask here.
If you find bugs/malfunctions report them please..
 
Back
Top