• 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 Script Problem TFS 0.4 (8.6)

Zombiegod

Active Member
Joined
Oct 22, 2009
Messages
198
Solutions
1
Reaction score
25
Okay so i wanted to make a monster fishing script a lot nicer.

So the idea for the changes was to make it so that fishing had luck, was based on fishing level and prestige, and was easy to add additional prestiges and monster per prestige

Granted i know little scripting so a lot of this is pieced together from other scripts in a way that i hope it works.

However its not working i am having issues and i am atm tired of making it work, so i want fresh experienced eyes to check it over

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local config = {
        waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625},
        rateSkill = getConfigValue("rateSkill"),
        allowFromPz = false,
        useWorms = true
}

    local MIN_RAND = 1 -- The minimum amount of mana to be given (random)
    local MAX_RAND = 100 -- The maximum amount of mana to be given (random)
    local ACCEPT_LUCK = true -- Should it be possible to get lucky and receive extra mana? true, false
    local FISH_LEVEL_MULTI = 2 -- How many times should Magic Level be multiplied, to be added to the mana formula? 1 = same, 0 = nothing etc
    local LEVEL_MULTI = 2 -- How many times should Level be multiplied, to be added to the mana formula? 1 = same, 0 = nothing etc
    local MAGIC_EFFECT = CONST_ME_LOSEENERGY -- Magic effect that will be casted on the player each time it heals the mana.
    local prestige = getCreatureStorage(cid, 85987)
    
    local FISHING_MONSTER = {
        [One] = {prestige = 1, chance = 30,
                    Monsters = {"Monk",
                                "Deer"
        }
    },
        [Two] = {prestige = 2, chance = 30,
                    Monsters = {"Demon",
                                "Rabbit"
        }
    }
}
    
    local random = math.random(MIN_RAND, MAX_RAND)
        if ACCEPT_LUCK == true then
    local luck = math.random(1, 100)
        if luck >= 90 then
            random = random * 2
        elseif luck == 50 then
            random = random * 3
        end
    end
        local formula = (getPlayerLevel(cid) * LEVEL_MULTI) + (getPlayerSkill(cid, SKILL_FISHING) * FISH_LEVEL_MULTI) + random
        
        
        if(not isInArray(config.waterIds, itemEx.itemid)) then
            return false
        end
        
        
    if((config.allowFromPz
        or not getTileInfo(getCreaturePosition(cid)).protection)
            and itemEx.itemid ~= 493
                and math.random(1, formula)
                    and (not config.useWorms or (getPlayerItemCount(cid, ITEM_WORM) > 0
                        and doPlayerRemoveItem(cid, ITEM_WORM, 1))))
    then       
        
        
        if math.random(100) <= FISHING_MONSTER.chance then
                    doSendMagicEffect(toPosition, MAGIC_EFFECT)
                    doCreateMonster(monsters[math.random], getCreaturePosition(cid))
                    doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
                else
                    doPlayerAddSkillTry(cid, SKILL_FISHING, config.rateSkill)
                    end
        
        
        
    return true
end
end

It loads up with no issues
 
lua-users.org/wiki/LuaStyleGuide
see: formatting

learn lua here: https://www.lua.org/manual/5.2/

the first thing i see is you are putting empty variable names into a table
[One] [Two] both are nil, since you never assigned them (lua will assume these are variables)
if you want to put values into a table you put a string or number
[1] = {prestige = 1, ...}

anything that isnt calling a function parameter should be outside of the function, talking about this:
Code:
   local config = {
        waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625},
        rateSkill = getConfigValue("rateSkill"),
        allowFromPz = false,
        useWorms = true
}

    local MIN_RAND = 1 -- The minimum amount of mana to be given (random)
    local MAX_RAND = 100 -- The maximum amount of mana to be given (random)
    local ACCEPT_LUCK = true -- Should it be possible to get lucky and receive extra mana? true, false
    local FISH_LEVEL_MULTI = 2 -- How many times should Magic Level be multiplied, to be added to the mana formula? 1 = same, 0 = nothing etc
    local LEVEL_MULTI = 2 -- How many times should Level be multiplied, to be added to the mana formula? 1 = same, 0 = nothing etc
    local MAGIC_EFFECT = CONST_ME_LOSEENERGY -- Magic effect that will be casted on the player each time it heals the mana.
you should also put all of those locals inside of your config (i don't see why you made them seperate since you can configure them)

Code:
if math.random(100) <= FISHING_MONSTER.chance then
here you aren't doing anything, you can't put .chance since FISHING_MONSTER isn't a valid table to get chance from
chance is a key value
you would need something like this:
FISHING_MONSTER[prestige].chance (this will get the table for the player's prestige and THEN get the chance from that table)
 

Ah i see, thanks, yea i pieced it together from parts of scripts that had certain aspects i wanted>

For the last one, the script i pulled it from that is how it was setup.

Also would you be willing to help me on this script, and some others ? i have a server i want to put together, and i want it to be bug free and fun, but it would be nice having someone experienced helping me with some scripts, and/or script ideas.
 
Ah i see, thanks, yea i pieced it together from parts of scripts that had certain aspects i wanted>

For the last one, the script i pulled it from that is how it was setup.

Also would you be willing to help me on this script, and some others ? i have a server i want to put together, and i want it to be bug free and fun, but it would be nice having someone experienced helping me with some scripts, and/or script ideas.
no
 
you should also put all of those locals inside of your config (i don't see why you made them seperate since you can configure them)

Just would like to reply this real quick, for some reason not all the locals get read properly in the config, don't ask me why, but i tried out adding some of them too the config and the script came up with nil value errors.

On a side note this thread can be closed, i scraped this script and rebuilt it from scratch, i currently have it i would say about 50-75% to what i want it to be(maybe less)(not including for the like additional 290 prestiges or so)
 
Just would like to reply this real quick, for some reason not all the locals get read properly in the config, don't ask me why, but i tried out adding some of them too the config and the script came up with nil value errors.

On a side note this thread can be closed, i scraped this script and rebuilt it from scratch, i currently have it i would say about 50-75% to what i want it to be(maybe less)(not including for the like additional 290 prestiges or so)
http://lua-users.org/wiki/TablesTutorial
they return nil cause you probably dont know how tables work
 
Back
Top