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

Bigger damage vs monsters

Hernest

New Member
Joined
Jul 26, 2010
Messages
152
Reaction score
3
Location
poland
Hi, is there any way to boost player damage vs monsters? For example
if storage==1 then damagevsmonsters = damagevsmonsters * 2

TFS version doesn't matter.

 
I'm not sure if this still exists in later versions but I used to use the onStatsChange creature script to do all kinds of crazy stuff.
Code:
function onStatsChange(cid, attacker, type, combat, value)

To put it simply the 'value' field here is the total damage done in any attack so you can easily manipulate it.
The instant you return true though the combat damage is done normally, so what I did was do the combat damage manually and return false instead.

The script would look something like this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
        if getPlayerStorageValue(attacker, 1234) == 1 then
            local multiplier = 2
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
        end
    end
return true
end
 
Last edited:
for TFS 1.x there is function called onHealthChange() for that
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and  attacker:isPlayer() and creature:isMonster() then
        local percent = attacker:getSV(SV.damagePercentAgainstMonsters)
        if percent > 0 then primaryDamage = percentage(primaryDamage, percent) end
    end
    return primaryDamage    -- not sure do you rly need to return anything
end
 
Last edited:
for TFS 1.x there is function called onHealthChange() for that
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if attacker and  attacker:isPlayer() and creature:isMonster() then
        local percent = attacker:getSV(SV.damagePercentAgainstMonsters)
        if percent > 0 then primaryDamage = percentage(primaryDamage, percent) end
    end
    return primaryDamage    -- not sure do you rly need to return anything
end
pls dont post code for someone that uses your custom functions
 
not sure if you understand what pseudocode means but ok
Wasn't too sure. checked google: simplified version of code.
And it is.
You can read code instead of some x's and y's and random numbers who knows where.
Well at least for me its easier to explain and understand code like that. Don't know about you.

besides this was just an example, the real question was answered: Where this change can be done
 
I'm not sure if this still exists in later versions but I used to use the onStatsChange creature script to do all kinds of crazy stuff.
Code:
function onStatsChange(cid, attacker, type, combat, value)

To put it simply the 'value' field here is the total damage done in any attack so you can easily manipulate it.
The instant you return true though the combat damage is done normally, so what I did was do the combat damage manually and return false instead.

The script would look something like this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
        if getPlayerStorageValue(attacker, 1234) == 1 then
            local multiplier = 2
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
        end
    end
return true
end

@496815 I took your code, changed a bit to this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
    print("x")
        if getPlayerStorageValue(attacker, 15600) == 1 then
        print("y")
            local multiplier = 500
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
        end
    end
    return true
end

Declarated as: <event type="statschange" name="dmg" event="script" value="damage.lua"/>
Added to login.lua: registerCreatureEvent(cid,'dmg')

There are no errors in terminal, also there isn't any printed x or y, moreover when this script is enabled server crashes after killing any monster.
 
TFS version?
Also make sure your player has storage value 15600 = 1.

add another print to check if it's running:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
    print("x")
        if getPlayerStorageValue(attacker, 15600) == 1 then
        print("y")
            local multiplier = 500
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
        end
    end
    print("z")
    return true
end
 
@496815 I took your code, changed a bit to this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
    print("x")
        if getPlayerStorageValue(attacker, 15600) == 1 then
        print("y")
            local multiplier = 500
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
        end
    end
    return true
end

Declarated as: <event type="statschange" name="dmg" event="script" value="damage.lua"/>
Added to login.lua: registerCreatureEvent(cid,'dmg')

There are no errors in terminal, also there isn't any printed x or y, moreover when this script is enabled server crashes after killing any monster.
You've created an infinite loop.

You attack monster for 1 damage.
Script enables, and deals 1 damage, and puts a new damage through the system for 500 damage.
Script enables, and deals 500 damage, and puts a new damage through the system for 250000 damage.
Script enables, and deals 250000 damage, and puts a new damage through the system for 125000000 damage.
Script enables,.....

You can do this many ways, but I'll do it simple, so you understand what you'll want to do.

Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and isMonster(cid) and type == STATSCHANGE_HEALTHLOSS then
        print("x")
        if getPlayerStorageValue(attacker, 15600) == 1 then
            print("y")
            setPlayerStorageValue(attacker, 15600, 2)
            local multiplier = 500
            doTargetCombatHealth(attacker, cid, type, -value*multiplier, -value*multiplier, -1)
            return false
        elseif getPlayerStorageValue(attacker, 15600) == 2 then
            print("z")
            setPlayerStorageValue(attacker, 15600, 1)
            return true
        end
    end
    return true
end

You attack monster for 1 damage.

Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 500 damage through the system, and returns the initial damage as false.

Script enables, and checks player storage.
Script detects you have storage value 2.
Script changes storage value to 1, deals 500 damage to target.

x
y
x
z


--------
The problem with the above method (1/10000 chance to happen) is if your system get's too many commands at once, it will sometimes flop the order of the issued damages, as it assumes all damage is true by default, and is not going to be modified, since within the script, it only checks true/false, as values cannot be returned as a different value.

In these cases some of your damages may get skewed to be stronger or weaker then they are supposed to be, as the damages will have been multiplied twice, or not multiplied at all.

Scenario

You attack monster(1) for 1 damage.
You attack monster(2) for 2 damage.

Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 500 damage through the system against monster(1), and returns the initial damage as false.


Script enables, and checks player storage.
Script detects you have storage value 2.
Script changes storage value to 1, deals 2 damage to monster(2).

-- This damage should never go through before monster(1)'s damage has fully finished, but it has flopped in front for reasons unknown.

Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 2, sends 250000 damage through the system against monster(1), and returns the initial damage as false.


Script enables, and checks player storage.
Script detects you have storage value 1.
Script changes storage value to 1, deals 250000 damage to monster(1).

-----

In this scenario, Monster(1) got multiplied twice, and Monster(2) did not receive any multiplier.
-----------
Instead of using storage flopping, you can use a global table to store the false/true damages for each creature in the world, however that's beyond my scripting capabilities.
I have an example on my home computer, but I'm not currently home, and could not explain it to you, even if I had the example with me to post.

That being said, if the multipliers aren't crazy amounts like 500x and instead something like 1.5-3x you'll likely never notice the scenario's above, even if you were looking for them.

Good luck!

Xikini
 
@Xikini oh right I forgot the return false, woops. Funny because I mentioned it on my first post and forgot to include it.
Even if you added return false after doing the damage manually, it will just continue to activate the statsChange in creaturescripts, as it is another 'statsChange'.
If you don't add an additional check, it will simply continue finding the same result, and continually place it through the system until it crashes.

Or, or or or..
I'm missing something in my quick glance over your posted code, and I'm just an idiot. :rolleyes:
That's never an impossibility. :p :D
 
Made this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) then
        if type == STATSCHANGE_HEALTHLOSS then
            doPlayerSendTextMessage(attacker, 19,"message")
        end
    end
    return true
end

But the server is still crashing when it's about to print message in terminal or send text message, meh.
 
Made this:
Code:
function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) then
        if type == STATSCHANGE_HEALTHLOSS then
            doPlayerSendTextMessage(attacker, 19,"message")
        end
    end
    return true
end

But the server is still crashing when it's about to print message in terminal or send text message, meh.
Are you sure it's this script that's crashing the server?
If so, try the most basic script possible and see if it still crashes.. and/or check if you have more onStatsChange scripts floating around in your folder that you've forgotten about?
If the below code crashes your server, it's either an issue with your source.. or another script.
If the below code does not crash your server, it may be linked to 'doPlayerSendTextMessage' .. I remember reading a few posts like 6 months ago having that issue on 1.x servers. (which was remedied by using the tfs 1.x coding style instead of 0.x.x)
Code:
function onStatsChange(cid, attacker, type, combat, value)
    print("StatsChange script is working.")
    return true
end
 
Back
Top