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

Function at tfs 1.2

Abutre

New Member
Joined
Jun 5, 2017
Messages
15
Reaction score
0
Hello!

Can anyone give me a light? I am creating a system, and in this system, monsters defined by a table would give 2x more loot (configurable) and 3x more damage (configurable). However, that is, it would occur if more than 3 players were found within the area. Anyone have any idea how I can get 2x more loot and 3x more damage? The rest I know how to do, just what to do and do the damage I have no idea! I'm use TFS 1.2

Thanks in advance!
 
loot is easy, seems that you're talking about prey system haha, well, the loot can be handled by c++ or lua
in lua will be something like:
Code:
local BONUS_RATE = 2 -- 1 normal loot, 2 double loot etc
function onKill(player, target, lastHit)
    if target:isMonster() then
        target:registerEvent('bonusloot')
    end
    return true
end

function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    if not creature or creature:getMaster() then
        return true
    end
    if not creature:getType():getLoot() then
        return true
    end
    local tc = 0
    for i, k in pairs(creature:getType():getLoot()) do
        tc = tc + k.chance
    end
    for i = 1, BONUS_RATE - 1 do
        for i, k in pairs(creature:getType():getLoot()) do
            if math.random() < k.chance / tc then
                if corpse:isContainer() then
                    local item = corpse:addItem(k.itemId,math.random(k.maxCount) or k.subType)
                    if item then
                        creature:say(item:getName():upper().. '!', TALKTYPE_MONSTER_SAY)
                    end
                end
            end
        end
    end
    return true
end
then you need create a tag in creaturescript.xml
Code:
<event type="kill" name="bonuslootkill" script="bonusloot.lua"/>
 <event type="death" name="bonusloot" script="bonusloot.lua"/>
need to register the "bonuslootkill" in login.lua
about the damage, as I said about the loot, can be possible in c++ or lua
in lua:
healthchange script
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and attacker ~= creature then
        local attackerMonster = attacker:getMonster()
        local damagedPlayer = creature:getPlayer()
   
        -- checking if attacker is monster and if damaged is player
        if attackerMonster and damagedPlayer then
            -- lopp for looking active prey(s) in columns
            if attackerMonster:getName():lower() == 'rat' then
                -- blocked damage formula - modified damage
                primaryDamage = primaryDamage - (50 / 100. * primaryDamage) -- I'm not good with math formulas
                return primaryDamage, primaryType, secondaryDamage, secondaryType
            end
        end
    end
    -- normal damage
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
need register the tag in creaturescript too...
that is all.
 
Good man! You are a best! Ahhh, i'm sorry for the time which i don't answered.
Can you help me with one more question?
I need to create a loop that repeats every 2 seconds and adds it to a +1 variable. Example:
Every 2 seconds, I add another 1 in the HP variable.
I tried this way, but without success:
Code:
                    addEvent(function()
                        local var = 0
                for var=0, 100, 1 do
                        local healthRemove = math.ceil(stats.healthP/100)*var
                    if P:addHealth(-healthRemove) then
                        P:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You lost "..var.."% health!")
                        creature:say("-"..var.."%", TALKTYPE_MONSTER_SAY)
                        doSendMagicEffect(stats.poz, 12)
                        electrify()
                    end  
                end
                        end, 2 * 1000)
I already tried it with for, with while, with repeat and even with it, however it does not respect the addEvent of 2 seconds and removes 100% at one time ...
and sorry my english, but i'm brazilian
 
Good man! You are a best! Ahhh, i'm sorry for the time which i don't answered.
Can you help me with one more question?
I need to create a loop that repeats every 2 seconds and adds it to a +1 variable. Example:
Every 2 seconds, I add another 1 in the HP variable.
I tried this way, but without success:
Code:
                    addEvent(function()
                        local var = 0
                for var=0, 100, 1 do
                        local healthRemove = math.ceil(stats.healthP/100)*var
                    if P:addHealth(-healthRemove) then
                        P:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You lost "..var.."% health!")
                        creature:say("-"..var.."%", TALKTYPE_MONSTER_SAY)
                        doSendMagicEffect(stats.poz, 12)
                        electrify()
                    end 
                end
                        end, 2 * 1000)
I already tried it with for, with while, with repeat and even with it, however it does not respect the addEvent of 2 seconds and removes 100% at one time ...
and sorry my english, but i'm brazilian
Lua:
local function electrify(cid, i, j)
    local player = Player(cid)
    if not player then
        return
    end
    if (i > j) then
        return
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You lost ".. i .."% health!")
    player:say("-".. i .."%", TALKTYPE_MONSTER_SAY)
    stats.poz:sendMagicEffect(CONST_ME_ENERGYHIT)
    return addEvent(electrify, 2000, cid, i+1, j)
end

then call it with electrify(player:getId(), 1, 100)
 
Lua:
local function electrify(cid, i, j)
    local player = Player(cid)
    if not player then
        return
    end
    if (i > j) then
        return
    end
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You lost ".. i .."% health!")
    player:say("-".. i .."%", TALKTYPE_MONSTER_SAY)
    stats.poz:sendMagicEffect(CONST_ME_ENERGYHIT)
    return addEvent(electrify, 2000, cid, i+1, j)
end

then call it with electrify(player:getId(), 1, 100)
Good!

You can help me in this? StopEvent
 
Back
Top