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

[TFS 1.0] Critical Hit % - Permanent

Eldin

Eldin Projects
Premium User
Joined
Jun 12, 2008
Messages
1,334
Reaction score
613
Location
Sweden
Greets!

Some servers have the Critical Hit Chance in Config, TFS 1.0 doesn't but its a great feature and should be possible via CreatureScripts if im not misstaken.

At this stage, im really glad for any Crit Hit script rather then none, the important thing wouls be that it affects Knights and not Magea, if the Physical damage includes Paladins, then its not a problem.

If you want the bigger challange, heres my real request:

A Critical Hit % from your Fist Skill. The idea is to make fist useable and make the people that take their time get something for it. You start out with 10 in all skills, 10 in fist fighting would mean a 1% crit chance while 20 means 2%. I don't know where you count the actual damage but otherwise a random + dmg (20-100?) could be set if the crit chance take place.
This can also include paladins as they also would have to train for it. (If vocation knight and paladin?) onhit or? :)

I am happy in any way I get the critical script and anyway you can make it, the fist would be awesome, im open for suggestions if you could make it in any other way.

Kind Regards,
Eldin.

A well known and acceptable Bump ^^

Kind Regards,
Eldin.
 
Last edited by a moderator:
Yeah, I figured out a way to do this for TFS 0.4 but, i'm curious wouldn't this cause lagg to the server?
Since every time a player or a monster gets damaged, it will execute this script and I would imagine that could cause lagg with many players?

edit: I got my answer - thanks! :)

And really thanks @Evan, ur post is amazing and made me get a lot of ideas for my server! :)
 
Last edited:
Shouldn't. Unless there is an insane amount of attacks going on at the same time, like an uber fast attack server would cause some serious lag
 
You can create that skill through lua as you can see here. You can create the skill in the source (through c++) as well. Both ways would require one of two options, either using an event (like say a talkaction) to have that skill shown to the player, or you will have to use otclient or another client and write it in there as well, I'm not entirely sure (since I haven't even used Otclient) but I believe in Otclient you can easily add new skills.
you know how? as "LUA" or c ++? I really need it, if you know I can pay :S
 
This is actually really cool.
Not sure if its the optimal way of going about adding crit chance, but it seems to work quite well:

5gocfEu.gif

crit multiplier set to 1000% damage for dramatic effect.

fyKz4S9.png
 
This is super awesome, just one small hiccup....So I added the critical system to monsters.xmls and login.lua like you said but now monsters can crit players as well xD I tried adding an if statement... if attacker:isMonster then end
but yeahhh that didn't work. Was wondering if someone knew the correct if statement so that if the attacker is a monster it ends the script and only allows players to attack. I'm using TFS 1.2
 
This is super awesome, just one small hiccup....So I added the critical system to monsters.xmls and login.lua like you said but now monsters can crit players as well xD I tried adding an if statement... if attacker:isMonster then end
but yeahhh that didn't work. Was wondering if someone knew the correct if statement so that if the attacker is a monster it ends the script and only allows players to attack. I'm using TFS 1.2
under function onHealthChange, add
Code:
if(Monster(attacker) ~= nil) then
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end
this way, your summons also can't crit targeted monsters/players
 
Last edited:
Guys im having a wierd situation ALL the monsters can crit but i can't what have i done wrong? Using TFS 1.2
this is the code on creaturescripts/scripts/shieldBlock.lua
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if math.random(100) <= 50 then
        if origin == ORIGIN_MELEE then
            creature:say("SKULLBASH!", TALKTYPE_MONSTER_SAY)
        elseif origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
        end
        return primaryDamage * 10, primaryType, secondaryDamage, secondaryType
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

this is the login.lua
Lua:
-- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("shieldBlock")
    return true
end

this is the creaturescripts.xml

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
    <event type="login" name="PlayerLogin" script="login.lua" />
    <event type="logout" name="PlayerLogout" script="logout.lua" />
    <event type="login" name="FirstItems" script="firstitems.lua" />
    <event type="login" name="OfflineTraining" script="offlinetraining.lua" />
    <event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
    <event type="death" name="PlayerDeath" script="playerdeath.lua" />
    <event type="death" name="DropLoot" script="droploot.lua" />
    <event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua" />
  <event type="HealthChange" name="shieldBlock" script="shieldBlock.lua" />
 
</creaturescripts>

18449417_1497156490359282_960539300186934890_o.jpg
 
Guys im having a wierd situation ALL the monsters can crit but i can't what have i done wrong? Using TFS 1.2
this is the code on creaturescripts/scripts/shieldBlock.lua
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if math.random(100) <= 50 then
        if origin == ORIGIN_MELEE then
            creature:say("SKULLBASH!", TALKTYPE_MONSTER_SAY)
        elseif origin == ORIGIN_RANGED then
            creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
        end
        return primaryDamage * 10, primaryType, secondaryDamage, secondaryType
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

this is the login.lua
Lua:
-- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("shieldBlock")
    return true
end

this is the creaturescripts.xml

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
    <event type="login" name="PlayerLogin" script="login.lua" />
    <event type="logout" name="PlayerLogout" script="logout.lua" />
    <event type="login" name="FirstItems" script="firstitems.lua" />
    <event type="login" name="OfflineTraining" script="offlinetraining.lua" />
    <event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
    <event type="death" name="PlayerDeath" script="playerdeath.lua" />
    <event type="death" name="DropLoot" script="droploot.lua" />
    <event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua" />
  <event type="HealthChange" name="shieldBlock" script="shieldBlock.lua" />
 
</creaturescripts>

18449417_1497156490359282_960539300186934890_o.jpg

Since you register it to player, it will only work on player (the onHealthChange event is executed for player only here). Check this post [TFS 1.0] Critical Hit % - Permanent for explanation
 
I added a .lua script and then added the script to creaturescripts.xml
Afterwards I added <script><event name=".."></script> thing to every monster..

My server prints this out:
[Error - CreatureEvent::configureEvent] Invalid type for creature event: AdvancedDamage
[Warning - BaseEvents::loadFromXml] Failed to configure event
And then a lot of (one for every monster I guess)
[Warning - Monster::Monster] Unknown event name: AdvancedDamage

The way I see it, when I add a script to a monster and does not look for the script in /creaturescripts/, but somewhere else, where else do I have to add the event?
 
Thanks a lot for that, was indeed very educational! I'm using for my Rage System in my custom Project.
I've got here a very simple script that makes part of the damage return as mana (rage) for my knights, but the healing was also filling my bar, so I created a condition to check out the COMBAT_HEALING, but its not working.
Someone can give me a hint of what I'm doing wrong?

Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if getPlayerVocation(creature) == 4 then
        if primaryType ~= COMBAT_HEALING or secondaryType ~= COMBAT_HEALING then
                if getPlayerMana(creature) < 100 then
                    doPlayerAddMana(creature, primaryDamage + secondaryDamage / getPlayerMaxMana(creature))
                end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Edit: Well, I was such a noob, solved by doing this:
Lua:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

    if getPlayerVocation(creature) == 4 then
        if isCreature(attacker) then
                if getPlayerMana(creature) < 100 then
                    doPlayerAddMana(creature, primaryDamage + secondaryDamage / getPlayerMaxMana(creature))
                end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Last edited:
Back
Top