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

script need help. optimize + correction

HGL

WelingtaO
Joined
Mar 11, 2010
Messages
19
Reaction score
0
someone can help me ...

i'm just getting started with this language .
and don't know much .

i need help to fix this script and optimize it, thx for now.
----------------------------------------------------------------


local configg = {
waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
}
local pokemons = {} -- i want initialize this one nully,

local grupo1 = { 'Magikarp' } -- what kind of data is this ? array ? matrix ? table ?

local grupo2 = { grupo1, {'Goldeen'}, {'Krabby'}, {'Poliwag'}, {'Horsea'} }

local grupo3 = { grupo2, {'Tentacool'} }

local grupo4 = { grupo3, {'Seaking'}, {'Poliwhril'} }

local grupo5 = { grupo4, {'Seadra'}, {'Kingler'} }

local grupo6 = { grupo5, {'Gyarados'}, {'Tentacruel'} }


local qtdpokes = 12 -- numero de monstros que você colocou /\
local dificuldade = 10 -- < quanto maior, mais dificil de pescar um monstro
local config = {
rateSkill = getConfigValue("rateSkill"),
allowFromPz = false
}
function onUse(cid, item, frompos, item2, topos)

local skill = getPlayerSkill(cid, SKILL_FISHING)

if ((skill >= 10) and (skill < 20)) then
pokemons = grupo1
end

if (skill >= 20) then
pokemons = grupo2
end

if (skill >= 40) then
pokemons = grupo3
end

if (skill >= 60) then
pokemons = grupo4
end

if (skill >= 80) then
pokemons = grupo5
end

if (skill >= 100) then
pokemons = grupo6
end
if(not isInArray(configg.waterIds, item2.itemid)) then
return false
end
local chance = math.random(1,qtdpokes+dificuldade) --
if chance >= 1 and chance <= dificuldade then
create = pokemons[chance][1] -- this is indexing nully, cant do it
doSummonCreature(create, getCreaturePosition(cid))
doSendMagicEffect(topos, 11)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
if((config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection) and item2.itemid ~= 2580 and
math.random(1, (100 + (skill / 10))) < skill) then
doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
return true
end
 
he is trying to say use code tags

Lua:
local configg = {
waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
}
local pokemons = {} -- i want initialize this one nully,

local grupo1 = { 'Magikarp' } -- what kind of data is this ? array ? matrix ? table ?

local grupo2 = { grupo1, {'Goldeen'}, {'Krabby'}, {'Poliwag'}, {'Horsea'} }

local grupo3 = { grupo2, {'Tentacool'} }

local grupo4 = { grupo3, {'Seaking'}, {'Poliwhril'} }

local grupo5 = { grupo4, {'Seadra'}, {'Kingler'} }

local grupo6 = { grupo5, {'Gyarados'}, {'Tentacruel'} }


local qtdpokes = 12 -- numero de monstros que você colocou /\
local dificuldade = 10 -- < quanto maior, mais dificil de pescar um monstro
local config = {
rateSkill = getConfigValue("rateSkill"),
allowFromPz = false
}
function onUse(cid, item, frompos, item2, topos)

local skill = getPlayerSkill(cid, SKILL_FISHING)

if ((skill >= 10) and (skill < 20)) then
pokemons = grupo1
end

if (skill >= 20) then
pokemons = grupo2
end

if (skill >= 40) then
pokemons = grupo3
end

if (skill >= 60) then
pokemons = grupo4
end

if (skill >= 80) then
pokemons = grupo5
end

if (skill >= 100) then
pokemons = grupo6
end
if(not isInArray(configg.waterIds, item2.itemid)) then
return false
end
local chance = math.random(1,qtdpokes+dificuldade) --
if chance >= 1 and chance <= dificuldade then
create = pokemons[chance][1] -- this is indexing nully, cant do it
doSummonCreature(create, getCreaturePosition(cid))
doSendMagicEffect(topos, 11)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
if((config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection) and item2.itemid ~= 2580 and
math.random(1, (100 + (skill / 10))) < skill) then
doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
return true
end
 
Lua:
local waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}

local groups =
    {
        {'Magikarp'},
        {'Goldeen', 'Krabby', 'Poliwag', 'Horsea'},
        {'Tentacool'},
        {'Seaking', 'Poliwhril'},
        {'Seadra', 'Kingler'},
        {'Gyarados', 'Tentacruel'}
    }
    
for i, k in ipairs(groups) do
    if i > 1 then
        for _, v in ipairs(groups[i - 1]) do
            table.insert(k, v)
        end
    end
end
    
local dificuldade = 10

local config = 
        {
            rateSkill = getConfigValue("rateSkill"),
            allowFromPz = false
        }
        
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local skill = getPlayerSkill(cid, SKILL_FISHING)
    
    local tmp = nil
    
    local myTable = {{10, 20}, {20, 40}, {40, 60}, {60, 80}, {80, 100}}
    
    if (skill >= 100) then
        tmp = groups[6]
    else
        for k, i in ipairs(myTable) do
            if skill >= i[1] and skill < i[2] then
                tmp = groups[k]
                break
            end
        end
    end

    if not isInArray(waterIds, itemEx.itemid) then
        return false
    end
    
    local chance = math.random(1, dificuldade + #tmp)
    
    if chance >= 1 and chance <= dificuldade then
        -- this part is kinda confuse, what about if chance is 10 (difi~) + 1 (size of array in first group) 
        -- it will attemp to summon group 1 with index 11 = nil = error
        -- so make you sure what you want :x
        doSummonCreature(tmp[chance], getCreaturePosition(cid))
        doSendMagicEffect(toPosition, 11)
    end
        
    if config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection and itemEx.itemid ~= 2580 and    (math.random(1, (100 + (skill / 10))) < skill) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
    end
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)

    return true
end
 
thx, i'll try and post here later.

but the code's a little confuse for me, i'm not able to understood it. :p

anyway, thanks for now.

btw: sorry for don't use the "code" tags. i'm just starting here and learning . :)
 
Last edited:
Lua:
local waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}

local groups =
    {
        {'Magikarp'},
        {'Goldeen', 'Krabby', 'Poliwag', 'Horsea'},
        {'Tentacool'},
        {'Seaking', 'Poliwhril'},
        {'Seadra', 'Kingler'},
        {'Gyarados', 'Tentacruel'}
    }
    
for i, k in ipairs(groups) do
    if i > 1 then
        for _, v in ipairs(groups[i - 1]) do
            table.insert(k, v)
        end
    end
end
    
local dificuldade = 10

local config = 
        {
            rateSkill = getConfigValue("rateSkill"),
            allowFromPz = false
        }
        
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local skill = getPlayerSkill(cid, SKILL_FISHING)
    
    local tmp = nil
    
    local myTable = {{10, 20}, {20, 40}, {40, 60}, {60, 80}, {80, 100}}
    
    if (skill >= 100) then
        tmp = groups[6]
    else
        for k, i in ipairs(myTable) do
            if skill >= i[1] and skill < i[2] then
                tmp = groups[k]
                break
            end
        end
    end

    if not isInArray(waterIds, itemEx.itemid) then
        return false
    end
    
    local chance = math.random(1, dificuldade + #tmp)
    
    if chance >= 1 and chance <= dificuldade then
        -- this part is kinda confuse, what about if chance is 10 (difi~) + 1 (size of array in first group) 
        -- it will attemp to summon group 1 with index 11 = nil = error
        -- so make you sure what you want :x
        doSummonCreature(tmp[chance], getCreaturePosition(cid))
        doSendMagicEffect(toPosition, 11)
    end
        
    if config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection and itemEx.itemid ~= 2580 and    (math.random(1, (100 + (skill / 10))) < skill) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
    end
    doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)

    return true
end

i don't understand much about scripts, i'm just starting, so i need your help.

this script that you modified crash my server :p

i want do a script that i can fish monsters by my skill in according of groups .
 
thx, but i want to make a simple and effective code . and undertandable to a "begginer".

if someone can help me based in my first code, i'll be happy.

thanks for now.

local configg = {
waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
}
local pokemons = {} -- i want initialize this one nully,

local grupo1 = { 'Magikarp' } -- what kind of data is this ? array ? matrix ? table ?

local grupo2 = { grupo1, {'Goldeen'}, {'Krabby'}, {'Poliwag'}, {'Horsea'} }

local grupo3 = { grupo2, {'Tentacool'} }

local grupo4 = { grupo3, {'Seaking'}, {'Poliwhril'} }

local grupo5 = { grupo4, {'Seadra'}, {'Kingler'} }

local grupo6 = { grupo5, {'Gyarados'}, {'Tentacruel'} }


local qtdpokes = 12 -- numero de monstros que você colocou /\
local dificuldade = 10 -- < quanto maior, mais dificil de pescar um monstro
local config = {
rateSkill = getConfigValue("rateSkill"),
allowFromPz = false
}
function onUse(cid, item, frompos, item2, topos)

local skill = getPlayerSkill(cid, SKILL_FISHING)

if ((skill >= 10) and (skill < 20)) then
pokemons = grupo1
end

if (skill >= 20) then
pokemons = grupo2
end

if (skill >= 40) then
pokemons = grupo3
end

if (skill >= 60) then
pokemons = grupo4
end

if (skill >= 80) then
pokemons = grupo5
end

if (skill >= 100) then
pokemons = grupo6
end
if(not isInArray(configg.waterIds, item2.itemid)) then
return false
end
local chance = math.random(1,qtdpokes+dificuldade) --
if chance >= 1 and chance <= dificuldade then
create = pokemons[chance][1] -- this is indexing nully, cant do it
doSummonCreature(create, getCreaturePosition(cid))
doSendMagicEffect(topos, 11)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
if((config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection) and item2.itemid ~= 2580 and
math.random(1, (100 + (skill / 10))) < skill) then
doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
else
doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
end
return true
end

as i said,
i'm trying to make a logical that can i fish monsters based on a group per skill lvl.

thanks.
 
what language have you used before? i meant if you used any scripting language before those loops / arrays shouldnt be hard to understand. and as you said in the first post "i'm just getting started with this language ."
 
i used c, c++, c#, java ... but long time ago.
i'm just backing to programming now ...

so i need little help, hehe

thanks anyway.
 
so, is something like this what i want to do .

help me to fix and optimize it please.

Code:
local configg = {
    waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825}
    }
local pokemons = {}

local grupo1 = { {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'}, {'Magikarp'} }

local grupo2 = { {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'}, {'Magikarp'}, {'Goldeen'}, {'Krabby'}, {'Poliwag'}, {'Horsea'}, {'Magikarp'}, {'Goldeen'} }

local grupo3 = { {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'},  {'Tentacool'}, {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'},  {'Tentacool'} }

local grupo4 = {  {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'},  {'Tentacool'}, {'Seaking'}, {'Poliwhril'},{'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'} }

local grupo5 = { {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'},  {'Tentacool'}, {'Seaking'}, {'Poliwhril'}, {'Seadra'}, {'Kingler'}, {'Magikarp'}, {'Goldeen'} }

local grupo6 = {  {'Magikarp'}, {'Goldeen'},  {'Krabby'}, {'Poliwag'}, {'Horsea'},  {'Tentacool'}, {'Seaking'}, {'Poliwhril'}, {'Seadra'}, {'Kingler'}, {'Gyarados'}, {'Tentacruel'} }


local qtdpokes = 12 -- numero de monstros que você colocou /\
local dificuldade = 10 -- < quanto maior, mais dificil de pescar um monstro
local config = {
    rateSkill = getConfigValue("rateSkill"),
    allowFromPz = false
}
function onUse(cid, item, frompos, item2, topos)

local skill = getPlayerSkill(cid, SKILL_FISHING)

if ((skill >= 10) and (skill < 20)) then
	pokemons = grupo1
end

if (skill >= 20) then
	pokemons = grupo2
end

if (skill >= 40) then
	pokemons = grupo3
end

if (skill >= 60) then
	pokemons = grupo4
end

if (skill >= 80) then
	pokemons = grupo5
end

if (skill >= 100) then
	pokemons = grupo6
end
    if(not isInArray(configg.waterIds, item2.itemid)) then
        return false
    end
    local chance = math.random(1,qtdpokes+dificuldade) --
    if chance >= 1 and chance <= dificuldade then
    create = pokemons[chance][1]
    doSummonCreature(create, getCreaturePosition(cid))
    doSendMagicEffect(topos, 11)
    else
    doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
    end
    if((config.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection) and item2.itemid ~= 2580 and
        math.random(1, skill) < (skill / 2)) then
        doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
        doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
    else
    doSendMagicEffect(topos, CONST_ME_LOSEENERGY)
    end
    return true
end

thanks for now.
 
Last edited:
Code:
local config = {
	rateSkill = getConfigValue("rateSkill"),
	waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4820, 4821, 4822, 4823, 4824, 4825},
	allowFromPz = false,
	grp = {
		[1] = { 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp', 'Magikarp' },
		[2] = { 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Magikarp', 'Goldeen' },

		[3] = { 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Tentacool', 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Tentacool' },

		[4] = { 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Tentacool', 'Seaking', 'Poliwhril','Magikarp', 'Goldeen', 'Krabby', 'Poliwag' },

		[5] = { 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Tentacool', 'Seaking', 'Poliwhril', 'Seadra', 'Kingler', 'Magikarp', 'Goldeen' },

		[6] = { 'Magikarp', 'Goldeen', 'Krabby', 'Poliwag', 'Horsea', 'Tentacool', 'Seaking', 'Poliwhril', 'Seadra', 'Kingler', 'Gyarados', 'Tentacruel' }
	},
	qtdpokes = 12, -- numero de monstros que você colocou /\
	dificuldade = 10 -- < quanto maior, mais dificil de pescar um monstro
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(not isInArray(t.waterIds, itemEx.itemid)) then
		return false
	end
	local skill, pokemons = getPlayerSkill(cid, SKILL_FISHING), {}
	if skill >= 100 then
		pokemons = t.grp[6]
	elseif skill >= 80 then
		pokemons = t.grp[5]
	elseif skill >= 60 then
		pokemons = t.grp[4]
	elseif skill >= 40 then
		pokemons = t.grp[3]
	elseif skill >= 20 then
		pokemons = t.grp[2]
	else
		pokemons = t.grp[1]
	end
	local chance = math.random(1, t.qtdpokes + t.dificuldade)
	if t.pokemons[chance] then
		doSummonCreature(t.pokemons[chance], getThingPos(cid))
		doSendMagicEffect(toPosition, 11)
	elseif (t.allowFromPz or not getTileInfo(getCreaturePosition(cid)).protection) and itemEx.itemid ~= 2580 and math.random(1, skill) < (skill / 2) then
		doPlayerAddSkillTry(cid, SKILL_FISHING, t.rateSkill)
	end
	doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
	return true
end
 
Back
Top