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

Lua Scripting question!

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
746
Solutions
9
Reaction score
125
So the question is: If i have this 3 conditions, and the 3 conditions are true, will the 3 be used, or only one? Or how will it exactly work? Thanks for your time!
 
Last edited:
I think I've figured what did he mean , and hope i'm right..

he got 3 conditions true
for example of tibia
level , vocation , storage
so if you put them true depend on how you script them

for example
if lvl = 10 true and you end your function
then the script will use this as first and only condition if player lvl= 10

but if you want to make it check all conditions at one time so you need to make something like this
if lvl10 then if voc =1234 then if storage =12345 do
and write your script .. then you type what if each condition isn't done

I will give simple example

If getPlayerLevel(cid) > 10 then
If getPlayerVocation(cid) = 4 then
If getPlayerStorageValue(12345) = 0 then

doPlayerAddItem(1234) - i don't remember functions and using phone xd

else doPlayerSendTextMessage ( you already got this item ) end
else xx ( you are not knight) end
else xx (you are low lvl ) end

Note this is example .. Not real script xd

But if you make it
If lvl 10 do xx end it will take the first function without checking other conditions

Hope i did good explain or even understood you xd
 
I think I've figured what did he mean , and hope i'm right..

he got 3 conditions true
for example of tibia
level , vocation , storage
so if you put them true depend on how you script them

for example
if lvl = 10 true and you end your function
then the script will use this as first and only condition if player lvl= 10

but if you want to make it check all conditions at one time so you need to make something like this
if lvl10 then if voc =1234 then if storage =12345 do
and write your script .. then you type what if each condition isn't done

I will give simple example

If getPlayerLevel(cid) > 10 then
If getPlayerVocation(cid) = 4 then
If getPlayerStorageValue(12345) = 0 then

doPlayerAddItem(1234) - i don't remember functions and using phone xd

else doPlayerSendTextMessage ( you already got this item ) end
else xx ( you are not knight) end
else xx (you are low lvl ) end

Note this is example .. Not real script xd

But if you make it
If lvl 10 do xx end it will take the first function without checking other conditions

Hope i did good explain or even understood you xd

Why not using "and"-Operator instead of three different if's? :p
If getPlayerLevel(cid) > 10 and getPlayerVocation(cid) == 4 and getPlayerStorageValue(12345) > 0 then
 
Just want to explain how it work .. If i type and he may will ask how they work xd
So i showed him the simple way . and i use phone atm .
Using phone too :p
But yeah, if you do not show a dog how to handshake, he will never learn it, just saying :p
So lets tell him, if he got questions he can still ask, thats how he can learn :)
 
Hello! Thanks for your answers, i did figure it out by myself, testing and testing.

The thing is:

I had something like this (more elaborated obviously):
Code:
If player:getStorageValue(xxx1) == 1 and origin == ORIGIN_MELEE then
dosomething1
return something1
end

If player:getStorageValue(xxx2) == 1 and origin == ORIGIN_MELEE then
dosomething2
return something2
end

If player:getStorageValue(xxx3) == 1 and origin == ORIGIN_MELEE then
dosomething3
return something3
end

If i did it like this, when the character had any of the storages it will work, but if for exemple 2 of them where true or even the 3 of them, only the first storage set would work.

So in order to have them work alone and together is having something like this:
Code:
if player:getStorageValue(xxx1) == 1 and player:getStorageValue(xxx2) == 1 and player:getStorageValue(xxx3) == 1 and origin == ORIGIN_MELEE then
dosomething1
dosomething2
dosomething3
return something4
end

if player:getStorageValue(xxx1) == 1 and player:getStorageValue(xxx2) == 1 and origin == ORIGIN_MELEE then
dosomething1
dosomething2
return something5
end

if player:getStorageValue(xxx1) == 1 and player:getStorageValue(xxx3) == 1 and origin == ORIGIN_MELEE then
dosomething1
dosomething3
return something6
end

if player:getStorageValue(xxx1) == 1 and origin == ORIGIN_MELEE then
dosomething1
return something1
end

if player:getStorageValue(xxx2) == 1 and origin == ORIGIN_MELEE then
dosomething2
return something2
end

if player:getStorageValue(xxx3) == 1 and origin == ORIGIN_MELEE then
dosomething3
return something3
end

This way if only 1 of the storages is in use it will work, and if 2 or 3 storages are used at same time, they would work together aswell.
If there's a easier way to do this, i'd love to know lol! Because im working with more than 20 storages and the combination of them are
too many. Storages "effects" should work alone but if more than one storage is in use, all those storage "effects" should work.

I wish i could explain myself better LoL
 
You can do that with tables + the way you do it atm doesn't work because you return inside all of the "if" that's why it doesn't go past once it found a "true" condition.
 
Code:
configTable = {
{
    sv = 1000,
    requiredValue = 3,
    origin = ORIGIN_MELEE,
    function = doSomething,
}
}

for _, configTable in pairs(configTable) do
    if getSV(player, configTable.sv) == configTable.requiredValue and configTable.origin == origin then
        configTable.function()
    end
end

obivously you need function loaded before global configTable or use a string and load it trough _G[configTable.functionString]()
 
here you go
Code:
local t = {
   [ORIGIN_MELEE] = {
     [storage1] = function(...) dosomething1(...) end,
     [storage2] = function(...) dosomething2(...) end,
     [storage3] = function(...) dosomething3(...) end
   }
}

function ...(...)
   for k,v in pairs(t[origin]) do
     if player:getStorageValue(k) >= 1 then
       v(player) -- will call the dosomething1/2/3 depending in which table index we are atm
     end
   end
   return true
end
 
Code:
configTable = {
{
    sv = 1000,
    requiredValue = 3,
    origin = ORIGIN_MELEE,
    function = doSomething,
}
}

for _, configTable in pairs(configTable) do
    if getSV(player, configTable.sv) == configTable.requiredValue and configTable.origin == origin then
        configTable.function()
    end
end

obivously you need function loaded before global configTable or use a string and load it trough _G[configTable.functionString]()
if you do it my way then you don't need to do it beforehand, I keep pushing the parameters forward so we don't need to load it first :)
 
Back
Top