• 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 Translate to 1.x please

Athenuz

Owlz!
Joined
Oct 1, 2015
Messages
234
Reaction score
27
Location
México
Hello,

I've found this script but doesn't works for TFS 1.x

Can please someone translate? :(

Code:
local config = {
summonName = "Orc",
cost = 10000 -- in gp, put 0 to disable
remove = "yes" -- should egg by removed after use?
}

config.remove = getBooleanFromString(config.remove)
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = getCreaturePosition(cid)
if(pos.x == CONTAINER_POSITION) then
doPlayerSendCancel(cid, "Put item on the floor first.")
return TRUE
end

if(config.cost > 0 and getPlayerMoney(cid) < config.cost) then
doPlayerSendCancel(cid, "Not enought money, trainer cost " .. config.cost .. " gp's.")
return TRUE
end

local ret, effect = doSummonMonster(cid, config.summonName), CONST_ME_MAGIC_RED
if(ret ~= RETURNVALUE_NOERROR) then
effect = CONST_ME_POFF
doPlayerSendDefaultCancel(cid, ret)
else
if(config.cost > 0) then
doPlayerRemoveMoney(cid, config.cost)
end
if(config.remove == TRUE) then
doRemoveItem(item.uid)
end
end

doSendMagicEffect(pos, effect)
return TRUE
end
 
ret is nil in your script razor
in otherwords it hasn't been defined
I understand what nil means. I removed ret because I thought it was supposed to be a wild monster, just forgot to remove the setMaster portion.
Code:
local config = {
    summonName = "Orc",
    cost = 10000, -- in gp, put 0 to disable
    remove = "yes" -- should egg by removed after use?
}

config.remove = (config.remove == "yes" and true or false)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = player:getPosition()
    if(not item:getTile()) then
        player:sendCancelMessage("Put item on the floor first.")
        return true
    end

    if(config.cost > 0 and player:getMoney() < config.cost) then
        player:sendCancelMessage("Not enought money, trainer cost " .. config.cost .. " gp's.")
        return true
    end

    effect = CONST_ME_MAGIC_RED
   
    local ret = Game.createMonster(config.summonName, item:getPosition())
    ret:setMaster(player)
    if(config.cost > 0) then
        player:removeMoney(config.cost)
    end
    if(config.remove == true) then
        item:remove(1)
    end
   
    Position(pos):sendMagicEffect(effect)
    return true
end
 
I don't know why everyone likes to use the metamethods soo much they are soo error prone especially when its extra coding involved, this is why the compat.lua exists to minimize those errors.

Anyway I will continue to write code with the compat.lua and you do your method razor :p

Here was the simple way, yes & i messed up too :p
Code:
creature = doSummonCreature(name, pos)
if creature then
  doConvinceCreature(cid, creature)
end
 
compat.lua exists for compatibility as the name suggests, so that legacy scripts will still work, not to promote continued use of legacy code.
my error had nothing to do with metatables being more or less prone to errors, I simply forgot to remove a line that called a variable I had removed. metatables, once you get used to them, are much cleaner and easier and actually less prone to errors. I used to code with legacy functions in 0.4 and this is much easier now.
 
compat.lua exists for compatibility as the name suggests, so that legacy scripts will still work, not to promote continued use of legacy code.
my error had nothing to do with metatables being more or less prone to errors, I simply forgot to remove a line that called a variable I had removed. metatables, once you get used to them, are much cleaner and easier and actually less prone to errors. I used to code with legacy functions in 0.4 and this is much easier now.
Their not legacy functions, they are a library and aren't there for compatibility, its for convenience. the compat file is like a header file in c or a class file in php, these 'legacy functions' as you call them are created to be reusable code for varying circumstances.
 
I understand what nil means. I removed ret because I thought it was supposed to be a wild monster, just forgot to remove the setMaster portion.
Code:
local config = {
    summonName = "Orc",
    cost = 10000, -- in gp, put 0 to disable
    remove = "yes" -- should egg by removed after use?
}

config.remove = (config.remove == "yes" and true or false)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = player:getPosition()
    if(not item:getTile()) then
        player:sendCancelMessage("Put item on the floor first.")
        return true
    end

    if(config.cost > 0 and player:getMoney() < config.cost) then
        player:sendCancelMessage("Not enought money, trainer cost " .. config.cost .. " gp's.")
        return true
    end

    effect = CONST_ME_MAGIC_RED
  
    local ret = Game.createMonster(config.summonName, item:getPosition())
    ret:setMaster(player)
    if(config.cost > 0) then
        player:removeMoney(config.cost)
    end
    if(config.remove == true) then
        item:remove(1)
    end
  
    Position(pos):sendMagicEffect(effect)
    return true
end

Works

There's 2 minor errors:
Egg still can be used on equipment slots or backpack
Player is able to use egg many time as he wishes so if he uses x4 eggs, he will have 4 summons >< (And no summon shield on them, maybe cuz of tfs 1.x or otcient)


I don't mind if the egg works on slots or backpack, that's ok for me but there's a way to set its limit to 1 or 2 summons? (if the summon dies he gets able to summon again) as the normal summon system
If not, simply set a cooldown/exhaust, 1 hour or something like that xD
 
I don't know why everyone likes to use the metamethods soo much they are soo error prone especially when its extra coding involved, this is why the compat.lua exists to minimize those errors.

Anyway I will continue to write code with the compat.lua and you do your method razor :p

Here was the simple way, yes & i messed up too :p
Code:
creature = doSummonCreature(name, pos)
if creature then
  doConvinceCreature(cid, creature)
end
Their not legacy functions, they are a library and aren't there for compatibility, its for convenience. the compat file is like a header file in c or a class file in php, these 'legacy functions' as you call them are created to be reusable code for varying circumstances.

Damn, I'm going to learn .lua asap and be like you both when i grow up :p
 
We are not testing the script (well atleast I am not) I am just writing it from the functions given so its a hit or miss with me, maybe for razor as well.. but that is what makes it fun :)
 
We are not testing the script (well atleast I am not) I am just writing it from the functions given so its a hit or miss with me, maybe for razor as well.. but that is what makes it fun :)

I really like the "lua world" :p

I'll read lots my entire vacations (1 week) about lua, trying to learn something... It's really attractive xD
 
Their not legacy functions, they are a library and aren't there for compatibility, its for convenience. the compat file is like a header file in c or a class file in php, these 'legacy functions' as you call them are created to be reusable code for varying circumstances.
They are old functions from old versions (legacy) and exist for COMPATibility. that's why the file is called compat. That's literally the reason it exists. a header file contains attributes and functions, a cpp file then contains the constructors for those functions. compat.lua contains functions with old names that basically just use the new functions within its scope in order to achieve the same effect while using old code.
Works

There's 2 minor errors:
Egg still can be used on equipment slots or backpack
Player is able to use egg many time as he wishes so if he uses x4 eggs, he will have 4 summons >< (And no summon shield on them, maybe cuz of tfs 1.x or otcient)


I don't mind if the egg works on slots or backpack, that's ok for me but there's a way to set its limit to 1 or 2 summons? (if the summon dies he gets able to summon again) as the normal summon system
If not, simply set a cooldown/exhaust, 1 hour or something like that xD
Code:
local config = {
    summonName = "Orc",
    cost = 10000, -- in gp, put 0 to disable
    remove = "yes" -- should egg by removed after use?
}

config.remove = (config.remove == "yes" and true or false)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = player:getPosition()
    if(not Tile(item:getParent())) then
        player:sendCancelMessage("Put item on the floor first.")
        return true
    end

    if(config.cost > 0 and player:getMoney() < config.cost) then
        player:sendCancelMessage("Not enought money, trainer cost " .. config.cost .. " gp's.")
        return true
    end
  
    effect = CONST_ME_MAGIC_RED
    if #player:getSummons() < 2 then
        local ret = Game.createMonster(config.summonName, item:getPosition())
        ret:setMaster(player)
    else
        player:sendCancelMessage("You already have two summons.")
        return true
    end
    if(config.cost > 0) then
        player:removeMoney(config.cost)
    end
    if(config.remove == true) then
        item:remove(1)
    end
  
    Position(pos):sendMagicEffect(effect)
    return true
end

And yes, as he says, I'm not testing this xD it's important to not only learn how to code but learn how to understand the ridiculous errors it spits at you. If you show me an error, I can often determine the cause of the problem without even seeing the code involved. It's valuable for bugfixing.
 
They are old functions from old versions (legacy) and exist for COMPATibility. that's why the file is called compat. That's literally the reason it exists. a header file contains attributes and functions, a cpp file then contains the constructors for those functions. compat.lua contains functions with old names that basically just use the new functions within its scope in order to achieve the same effect while using old code.
I've seen the way you code, you don't know how to write reusable code at all, so I am not surprised you don't see the value or the real meaning behind the compat file.

But that's ok, you keep writing stuff the long way and I'll write it the short way..

Happy Coding :)
 
Hello, i translated the script to swedish! Enjoy!

Code:
lokal konfig = {
kallaNamn = "Orc",
kostar = 10000 -- I gp, lägg 0 för att inaktivera
ta bort = "ja" -- borde ägg tas bort efter någon har använt det?
}

konfig.tabort= fåBooleanFrånTråd(konfig.tabort)
funktion:påAnvände(cid, grej, frånPosition, grejEx, tillPosition)
lokal pos = fåVarelsePosition(cid)
om(pos.x == CONTAINER_POSITION) då
görSpelareSkickaAvbryt(cid, "Lägg grejen på golvet först.")
tillbaka SANT
sluta

om(konfig.kostar > 0 och FåSpelarensPengar(cid) < konfig.cost) då
görSpelareSkickaAvbryt(cid, "Inte tillräckligt med pengar, tränare kostnad " .. konfig.cost .. " gp's.")
return TRUE
end

lokal ret, effekt = GörTillkallaMonster(cid, konfig.summonName), CONST_MIG_MAGIC_RÖD
om(ret ~= AVKASTAVÄRDET_INGENERROR) då
effekt = CONST_MIG_POFF
görSpelareSkickaStandardAvbryt(cid, ret)
annars
om(konfig.cost > 0) then
görSpelareTabortPengar(cid, config.cost)
sluta
om(konfig.remove == SANT) då
görTabortGrej(Grej.uid)
sluta
sluta

görSkickaMagiskEffekt(pos, effekt)
tillbaka SANT
slut
 
I know how to make reusable code. I choose not to. I know exactly what the functions are and how to use them, and it's faster for me to just type them out in awkward places rather than try to figure out what variables do what and belong where and exist in what scopes. I code in a straight line and I don't look back unless there's an error. And if you look backwards to 0.3, 0.4, you'll see that all your functions exist there. Compat contains those functions and uses the metatables to tell those functions what they're supposed to do. The entire purpose of the file is so that if I bring an old script in, it will still work without having to go through heavy conversion. You think I'm coding the long way but you're coding the old way. Stuck in the past. Everything that exists in compat can be done with metatables which is why metatables are used within those functions. They aren't some magic that was created for ease of access. Compat is the magic used to make the access exist at all
 
I know how to make reusable code. I choose not to. I know exactly what the functions are and how to use them, and it's faster for me to just type them out in awkward places rather than try to figure out what variables do what and belong where and exist in what scopes. I code in a straight line and I don't look back unless there's an error. And if you look backwards to 0.3, 0.4, you'll see that all your functions exist there. Compat contains those functions and uses the metatables to tell those functions what they're supposed to do. The entire purpose of the file is so that if I bring an old script in, it will still work without having to go through heavy conversion. You think I'm coding the long way but you're coding the old way. Stuck in the past. Everything that exists in compat can be done with metatables which is why metatables are used within those functions. They aren't some magic that was created for ease of access. Compat is the magic used to make the access exist at all
If you say so, but I've only been programming longer than you've been alive but oki doki :)
 
They are old functions from old versions (legacy) and exist for COMPATibility. that's why the file is called compat. That's literally the reason it exists. a header file contains attributes and functions, a cpp file then contains the constructors for those functions. compat.lua contains functions with old names that basically just use the new functions within its scope in order to achieve the same effect while using old code.

Code:
local config = {
    summonName = "Orc",
    cost = 10000, -- in gp, put 0 to disable
    remove = "yes" -- should egg by removed after use?
}

config.remove = (config.remove == "yes" and true or false)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = player:getPosition()
    if(not Tile(item:getParent())) then
        player:sendCancelMessage("Put item on the floor first.")
        return true
    end

    if(config.cost > 0 and player:getMoney() < config.cost) then
        player:sendCancelMessage("Not enought money, trainer cost " .. config.cost .. " gp's.")
        return true
    end

    effect = CONST_ME_MAGIC_RED
    if #player:getSummons() < 2 then
        local ret = Game.createMonster(config.summonName, item:getPosition())
        ret:setMaster(player)
    else
        player:sendCancelMessage("You already have two summons.")
        return true
    end
    if(config.cost > 0) then
        player:removeMoney(config.cost)
    end
    if(config.remove == true) then
        item:remove(1)
    end

    Position(pos):sendMagicEffect(effect)
    return true
end

And yes, as he says, I'm not testing this xD it's important to not only learn how to code but learn how to understand the ridiculous errors it spits at you. If you show me an error, I can often determine the cause of the problem without even seeing the code involved. It's valuable for bugfixing.

Almost works xD
Still telling "Put item on the floor first" even if the item is on the floor :x

Edit:

Removed the tile checking files and works perfect (don't worry about fixin that problem :p )
I'd declare this as solved.

Thank you so much for you help guys <3
 
Hello, i translated the script to swedish! Enjoy!

Code:
lokal konfig = {
kallaNamn = "Orc",
kostar = 10000 -- I gp, lägg 0 för att inaktivera
ta bort = "ja" -- borde ägg tas bort efter någon har använt det?
}

konfig.tabort= fåBooleanFrånTråd(konfig.tabort)
funktion:påAnvände(cid, grej, frånPosition, grejEx, tillPosition)
lokal pos = fåVarelsePosition(cid)
om(pos.x == CONTAINER_POSITION) då
görSpelareSkickaAvbryt(cid, "Lägg grejen på golvet först.")
tillbaka SANT
sluta

om(konfig.kostar > 0 och FåSpelarensPengar(cid) < konfig.cost) då
görSpelareSkickaAvbryt(cid, "Inte tillräckligt med pengar, tränare kostnad " .. konfig.cost .. " gp's.")
return TRUE
end

lokal ret, effekt = GörTillkallaMonster(cid, konfig.summonName), CONST_MIG_MAGIC_RÖD
om(ret ~= AVKASTAVÄRDET_INGENERROR) då
effekt = CONST_MIG_POFF
görSpelareSkickaStandardAvbryt(cid, ret)
annars
om(konfig.cost > 0) then
görSpelareTabortPengar(cid, config.cost)
sluta
om(konfig.remove == SANT) då
görTabortGrej(Grej.uid)
sluta
sluta

görSkickaMagiskEffekt(pos, effekt)
tillbaka SANT
slut

roflmao. x'DD
 
If you say so, but I've only been programming longer than you've been alive but oki doki :)
I'm not sure it matters how long you've been coding if you can't understand that a compat file full of legacy functions remade using new functions is used for compatibility with old scripts. Not only that but you said the compat file is like a header file which is not even close to true because a header file contains function declarations that are constructed in a source file, which already tells me you don't know what you're talking about, nullifying your argument that age or length of time coding is a deciding factor on knowledge. My mom has been driving since longer than I've been alive, but I'm still a better driver. compat.lua is a method of porting one function into another similar to luascript.cpp, except instead of porting a c++ function to lua, it ports a legacy function into an environment that wouldn't natively support it. If those functions were intended to be used to create new content based on the new way TFS is coded in lua, they would exist in luascript.cpp as hardcoded functions. if you want new functions that simplify your life, you make them and throw them into a separate lib or directly into global.lua, or make them in c++ and port them. If you're still confused on what compat is for, ask Mark, but I'm not sure he'd waste his time explaining that compat = compatibility any further than I've already done.

Almost works xD
Still telling "Put item on the floor first" even if the item is on the floor :x

Edit:

Removed the tile checking files and works perfect (don't worry about fixin that problem :p )
I'd declare this as solved.

Thank you so much for you help guys <3
yeah the tile thing is a weird one. there's no direct way to check if an item is on the ground or on a player other than getParent, which didn't apparently work out in my favour :p glad it works otherwise xD
 
Back
Top