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

Lua needs clarification on Scripts

Sekin

New Member
Joined
Sep 10, 2009
Messages
20
Reaction score
0
Hello im Newbie on script lua but i try to translate my scripts on tfs 0.3.6pl to tfs 1.2 and i have problem

this is my scripts on tfs 0.3.6pl

Lua:
local config = 
{
[1] = {efe= 12,hp= 0.02,mn= 0.01, time= 2,efesum= 12}
}

function onThink(cid, interval)
    if(isCreature(cid)) and (not exhaustion.get (cid,21410)) then
    doSendMagicEffect(cid,config[1].efe)
    doSendMagicEffect(getThingPos(getCreatureSummons(cid)[1]), config[1].efesum)
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid) *config[1].hp)
    doCreatureAddMana(cid, getCreatureMaxMana(cid) *config[1].mn)
    exhaustion.set(cid, 21410, config[1].time)
    end
end

and this is my attempt to translate please dont laugh im newbie :(

Lua:
local config = 
{
[1] = {efe= 12,hp= 300,mn= 200, time= 2,efesum= 12}
}

}

function onThink(cid, interval)
    if(exhaust(cid, 21410, config[1].time) == 0) and Player:getStorageValue(config[1][1]) == 2 then
    player:getPosition():sendMagicEffect(config[1].efe)
    player:getThingPos(getCreatureSummons(cid)[1]:sendMagicEffect(config[1].efe)
    creature:addHealth(config[1].hp)
    creature:addMana(config[1].mn)
    exhaust(cid, 21410, config[1].time)
    end
end

Could someone explain to me straight? :/
 
Code:
local config = {
[1] = {magicEffect = 12 , hp= 300, mn= 200, time= 2, storage = 10000}
}

function onThink(player, interval)
    if(exhaust(player, 21410, config[1].time) == 0) and player:getStorageValue(config[1].storage) == 2 then
    player:getPosition():sendMagicEffect(config[1].magicEffect)
   
    SUMMONS = player:getSummons()
        for i, v in ipairs(SUMMONS) do
            summon = SUMMONS[v]
            summon:getPosition():sendMagicEffect(config[1].magicEffect)
        end
   
    player:addHealth(config[1].hp)
    player:addMana(config[1].mn)
    exhaust(player, 21410, config[1].time)
    end
end
 
Lua:
 for i, v in ipairs(SUMMONS) do
this is loop
and
Lua:
function onThink(player, interval)
this is loop
why use 2x ?
It is necessary? :)
 
Code:
local config = {
[1] = {magicEffect = 12 , hp= 300, mn= 200, time= 2, storage = 10000}
}

function onThink(player, interval)
    if(exhaust(player, 21410, config[1].time) == 0) and player:getStorageValue(config[1].storage) == 2 then
    player:getPosition():sendMagicEffect(config[1].magicEffect)
   
    SUMMONS = player:getSummons()
    summon = SUMMONS[1]
    summon:getPosition():sendMagicEffect(config[1].magicEffect)
   
    player:addHealth(config[1].hp)
    player:addMana(config[1].mn)
    exhaust(player, 21410, config[1].time)
    end
end
 
Lua:
local config = {
    storage = 12, -- ????
    effect = CONST_ME_ENERGYHIT,
    healthToAdd = 300,
    manaToAdd = 200,
    time = 2,
}

function onThink(creature, interval)
    if creature:isPlayer() and exhaust(player:getId(), 21410, config.time) == 0 and creature:getStorageValue(config.storage) == 2 then
        creature:getPosition():sendMagicEffect(config.effect)
        creature:addHealth(config.healthToAdd)
        creature:addMana(config.manaToAdd)
        exhaust(player:getId(), 21410, config.time)

        local summons = creature:getSummons()
        for i = 1, #summons do
            summons[i]:getPosition():sendMagicEffect(config.effect)
        end
    end
    return true
end

Just set the correct storage value in the config, it was set to 12 before, same as the effect since the effect was the first index in the table.

Lua:
 for i, v in ipairs(SUMMONS) do
this is loop
and
Lua:
function onThink(player, interval)
this is loop
why use 2x ?
It is necessary? :)

Because the code you had was bugged, you can't use multiple positions to send out one effect, you have to loop the positions and send out one effect for each position.
Lua:
for i = 1, #summons do
     summons[i]:getPosition():sendMagicEffect(config.effect)
end

And
Lua:
function onThink(creature, interval)
Is a function, not a loop.

The loops we use are these;
Lua:
for
while
repeat
 
Lua:
function onThink(creature, interval)
when i said loop i mean repeat again 0.5sec
I'm wrong?

And i use efe and efesum because "effect nr: 12" it's only for test :)

Lua:
local config = {
    storage = 12, -- ????

i try to explain
1 Item but different atributes and when we equip item "Sword + Fire(Attribute)" then we getstorage "203012" and this run tabel:

Lua:
[1] = {efe= 12,hp= 300,mn= 200, time= 2,efesum= 12}
or if we equip "Sword +Water(Attribute)" then we get storage "203130" and run read tabele:
Lua:
[2] = {efe= 32,hp= 200,mn= 100, time= 2,efesum= 22}
etc :)
Therefore my table looks like that :)


I'm very sorry for my English :/

This "scripts" is only beginning how do I want this expand
Although So far TFS 1.2 scares me hahaha :D
 
Wibb so nice doing it all for you ;) I just gave hints slowly.

Yeah main reason why I posted it was to clean it up, use a loop insted aswell as tabbing it.
I normally do the same, but IMO when we help people we should tab them in case there is a bug someone else can find it by just quickly looking at it.
Another thing is to teach users to use the enum names insted of integers (ex the effect, in the next version that effect might have changed it's number and you would then have to modify x amount of scripts insted of changing it in 1 place) :p

Lua:
function onThink(creature, interval)
when i said loop i mean repeat again 0.5sec
I'm wrong?

And i use efe and efesum because "effect nr: 12" it's only for test :)

Lua:
local config = {
    storage = 12, -- ????

i try to explain
1 Item but different atributes and when we equip item "Sword + Fire(Attribute)" then we getstorage "203012" and this run tabel:

Lua:
[1] = {efe= 12,hp= 300,mn= 200, time= 2,efesum= 12}
or if we equip "Sword +Water(Attribute)" then we get storage "203130" and run read tabele:
Lua:
[2] = {efe= 32,hp= 200,mn= 100, time= 2,efesum= 22}
etc :)
Therefore my table looks like that :)


I'm very sorry for my English :/

This "scripts" is only beginning how do I want this expand
Although So far TFS 1.2 scares me hahaha :D

Well onThink is a function that you can execute every 0.5 seconds, but it isen't a loop.
No problems, but always use the enum names when it comes to effects aswell as readable and easy to understand variable names.

You shouldn't be afraid of using the 1.x series, it's 1000 times better than 0.2 when it comes to the Lua API even if we are missing some things at the moment.
 
Back
Top