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

Decrese IQ of monsters

Lyky

Well-Known Member
Joined
May 27, 2014
Messages
291
Solutions
8
Reaction score
89
Hi,
So my players have been sending complains for dragons on my server having over 200 IQ; Its running on [TFS 1.2];

I was wondering if its possible - through lua - make monsters having a chance turn towards player 20% per 2sec turn.

As it stands now, all of my monsters automatically from a get-go turn to player position, and when running away they move in a way so that player is going to be hit by a wave attack, and dodge their attacks.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="dragon" nameDescription="a dragon" race="blood" experience="700" speed="150" manacost="0">
   <health now="1000" max="1000"/>
   <look type="34" corpse="3104"/>
   <targetchange interval="1000" chance="5"/>
   <targetstrategies nearest="70" health="10" damage="10" random="10"/>
   <flags>
       <flag attackable="1"/>
       <flag hostile="1"/>
       <flag summonable="0"/>
       <flag convinceable="0"/>
       <flag illusionable="1"/>
       <flag pushable="0"/>
       <flag canpushitems="1"/>
       <flag canpushcreatures="1"/>
       <flag targetdistance="1"/>
       <flag staticattack="80"/>
       <flag runonhealth="300"/>
   </flags>
   <attacks>
       <attack name="melee" skill="55" attack="42"/>
       <attack name="fire" chance="15" range="7" radius="4" target="1" min="-55" max="-105">
           <attribute key="shootEffect" value="fire"/>
           <attribute key="areaEffect" value="firearea"/>
       </attack>
       <attack name="fire" chance="12" length="8" spread="3" min="-100" max="-160">
           <attribute key="areaEffect" value="firearea"/>
       </attack>
   </attacks>
   <defenses armor="25" defense="38">
       <defense name="healing" chance="13" min="34" max="56">
           <attribute key="areaEffect" value="blueshimmer"/>
       </defense>
   </defenses>
   <elements>
       <element firePercent="100"/>
       <element earthPercent="100"/>
   </elements>
   <immunities>
       <immunity paralyze="1"/>
       <immunity invisible="1"/>
   </immunities>
   <voices interval="1000" chance="5">
       <voice sentence="GROOAAARRR" yell="1"/>
       <voice sentence="FCHHHHH" yell="1"/>
   </voices>
   <loot>
       <item id="2672" chance="45000" countmax="3"/><!-- 3 45% dragon ham -->
       <item id="2148" chance="80000" countmax="45"/><!-- 45 80% gold coin -->
       <item id="2148" chance="50000" countmax="60"/><!-- 60 50% gold coin -->
       <item id="2145" chance="400"/><!-- 0.4% small diamond -->
       <item id="2546" chance="16000" countmax="10"/><!-- 10 16% burst arrow -->
       <item id="2177" chance="100"/><!-- 0.1% life crystal -->
       <item id="2457" chance="3000"/><!-- 3% steel helmet -->
       <item id="2647" chance="2000"/><!-- 2% plate legs -->
       <item id="5877" chance="1005"/><!-- green dragon leather -->
       <item id="5920" chance="1000"/><!-- green dragon scale -->
   
       <item id="1987" chance="100000"><!-- bag -->
       
               <item id="2455" chance="10000"/><!-- 10% crossbow -->
               <item id="2397" chance="4000"/><!-- 4% longsword -->
               <item id="2413" chance="2000"/><!-- 2% broadsword -->
               <item id="2387" chance="1000"/><!-- 1% double axe -->
               <item id="2434" chance="500"/><!-- 0.5% dragon hammer -->
               <item id="2409" chance="500"/><!-- 0.5% serpent sword -->
               <item id="2406" chance="25000"/><!-- 25% short sword -->
               <item id="2398" chance="20000"/><!-- 20% mace -->
               <item id="2187" chance="1000"/><!-- 1% wand of inferno -->
               <item id="2509" chance="15000"/><!-- 15% steel shield -->
               <item id="2516" chance="300"/><!-- 0.3% dragon shield -->
               <item id="7430" chance="10"/><!-- dragonbone staff -->
       
       </item>
   </loot>
</monster>


The issue has been described here:

Monster AI Revamp [$100] · Issue #922 · otland/forgottenserver · GitHub [2014 couple years back]
Turning/Facing - if a creature changes directions while while moving there is no delay before or after the turn, they turn and take their next step in a fluid motion. During dancestep if the creature turns away from the target when it moves, it will adjust the direction to face the target again during it's next attack interval (turn and attack in fluid motion)

later stated it has been implemented; thus how to control that turning/facing direction switch chance?


@edit
After thinking a little bit about it; it should be scriptable in creaturescripts; but i have no idea how to start - can anyone point me to example that modifies how certain creatures behave.
 
Last edited:
I was wondering if its possible - through lua - make monsters having a chance turn towards player 20% per 2sec turn.

You can always make a spell that just has 20% chance to turn in the direction of the target (if it has one) and put it in the defenses of the monster.


later stated it has been implemented; thus how to control that turning/facing direction switch chance?
Most of the programmers of otland suck so hard when it comes to Lua, they prefer do hardcode everything in the source to create easily configurable systems, so what I would say is for you to create a sketch of how do you think the monster configuration in XML should be, then we can descend one step into source and make it understand our new design.
 
You can always make a spell that just has 20% chance to turn in the direction of the target (if it has one) and put it in the defenses of the monster.



Most of the programmers of otland suck so hard when it comes to Lua, they prefer do hardcode everything in the source to create easily configurable systems, so what I would say is for you to create a sketch of how do you think the monster configuration in XML should be, then we can descend one step into source and make it understand our new design.

I don't think this is true.

I think more people in OTLand are good at LUA than the source.

As for your "Dragon with 200 IQ problem."
When you give a wave-attack to a dragon, it will always "shoot" that wave attack towards the player (it can't make a mistake).

If you want to program "wave mistakes" into the game, where they shoot the wave the wrong way, or they might not turn towards the player before shooting the wave, you can program this in LUA with a long and complicated script, or easily do it in the sources.

For example, you could add a new XML value called "updateLookChance" then in the Monster::doAttacking function you just add:

Code:
    if (updateLookChance < static_cast<uint32_t>(uniform_random(1, 100)))
        updateLook = false;


It would look like:

Code:
void Monster::doAttacking(uint32_t interval)
{
    if (!attackedCreature || (isSummon() && attackedCreature == this)) {
        return;
    }

    bool updateLook = true;
    bool resetTicks = interval != 0;
    attackTicks += interval;
  
    if (updateLookChance < static_cast<uint32_t>(uniform_random(1, 100)))
        updateLook = false;
  
    const Position& myPos = getPosition();
    const Position& targetPos = attackedCreature->getPosition();

    for (const spellBlock_t& spellBlock : mType->info.attackSpells) {
        bool inRange = false;

        if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) {
            if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) {
                if (updateLook) {
                    updateLookDirection();
                    updateLook = false;
                }

(This basically would allow you to give a % chance on each doAttacking interval for the creature to turn and look at their target)
 
I don't know why I wrote Lua in my reply, I was at work and tried to type fast. What I meant is that people here lack design thinking. This is something that only comes with study and experience and there aren't many experienced programmers here (truth be told).

I'm not trying to decrease anyone, everyone is capable of doing their magic in their way. But when you start to make a huge project such as tfs and don't sketch things before go coding, it becomes a total frankestein. It's more like a tip than a critic: always think in the future and seriously, if you want to make something that doesn't become a headache in the future: stop 5 minutes to think about it before doing it, otherwise you'll lose many hours later.

As for the solution provided: I would only reinforce that you should pass the variable updatelookchance to the xml.
But remember this only will change the chance of moving when going to attack using spells. This will not change the behavior nor the strategy the monsters has;
Besides that: pattern behaviors should be on source and be able to be modified by script in a simple way, this isn't what we have today.

This is just a bunch of things to consider.
 
Most of the programmers of otland suck so hard when it comes to Lua, they prefer do hardcode everything in the source to create easily configurable systems
Given yes some suck at programming but to say source editing is wrong is to be completely ignorant. Some times its better to edit the sources for a given task because it is cleaner and faster to modify the sources... not everything can be easily accomplished in a script.
 
ok, great thanks for the input; i'll test the lua approach first and test it out how it plays with my players.

i'm more keen on editing lua, as its much faster development&testing time than recompiling the code every single time i make change/adjustment. The more power i have in lua, the more happy, powerful, and fast - i am.
Feel free to post any other ideas on how you would accomplish it. This feels very constructive for me.
 
ok, great thanks for the input; i'll test the lua approach first and test it out how it plays with my players.

i'm more keen on editing lua, as its much faster development&testing time than recompiling the code every single time i make change/adjustment. The more power i have in lua, the more happy, powerful, and fast - i am.
Feel free to post any other ideas on how you would accomplish it. This feels very constructive for me.
If you are more comfortable using a script then do that, if you have 0 knowledge about c++ then yes I agree you should not touch the sources because you can break the server or just mess it up.
 
ok, great thanks for the input; i'll test the lua approach first and test it out how it plays with my players.

i'm more keen on editing lua, as its much faster development&testing time than recompiling the code every single time i make change/adjustment. The more power i have in lua, the more happy, powerful, and fast - i am.
Feel free to post any other ideas on how you would accomplish it. This feels very constructive for me.

There's just a problem in this history my friend, they already made the monsters turn when they are about to cast a wave and there's no way of undoing that just by using Lua.
You'll have to do at least 1 edit in source:
changing this to false
bool updateLook = true;

Then you can work on making the creature turn using the defense method I've mentioned earlier, but if you do it for all the creatures then we reach the case I was pointing out earlier: the standard behaviour should be handled by source (but be capable of be overwritten, emphasis on this part);

So let's start with the basics: What do you really want? It's just making the creature not turn in every wave they cast? It's to do so just while you're not fleeing? Or are you looking for a more advanced strategy in monsters combat?

If it's the first option, his modification will serve you well, you just have to pass this variable to XML and make it start with 100 if not given any value or not declared.(100% of chance of updating it)
then you have to fix the if he made because it's on the wrong order:

Code:
if (updateLookChance < static_cast<uint32_t>(uniform_random(1, 100)))

should be

Code:
if (updateLookChance > static_cast<uint32_t>(uniform_random(1, 100)))

now you just put updatelookchance = "35" in the XML of the monsters you want to customize and you won't ruin every other monster by making it obligatory.


Given yes some suck at programming but to say source editing is wrong is to be completely ignorant. Some times its better to edit the sources for a given task because it is cleaner and faster to modify the sources... not everything can be easily accomplished in a script.
I don't like to assume things but you're probably saying this because you didn't understood what I said or you have 0 experience in making applications outside the world of tibia.
It's completely unhealthy having to compile your code everytime you need to make a simple change, that's why most applications have scripts and that's even more why script languages should be the biggest part of your program. Usually you have just a very fair amount of code in your source, just to control the scripts and the rest of very basic functionalities.
Unfortunately for this community, people realized that too late and most of the recent commits are trying to bring source codes that should never have been written in source in the first place to Lua.

Again, it could be avoided from the start if programmers tried to think before coding, but damn, thinking is way too hard and people way too lazy xD
Lastly: I have to disagree with you, if you have no knowledge in C++ or in the structure of the source you should TOTALLY edit it and try to learn something, but remember to keep a backup or at least trace of the changes you make.
 
I don't like to assume things but you're probably saying this because you didn't understood what I said or you have 0 experience in making applications outside the world of tibia.
Actually I do have lots of experience building things outside of the world of tibia, this community does not teach or encourage people to learn, so sadly
i didn't learn any of the coding skills I have today from this community.
It's completely unhealthy having to compile your code everytime you need to make a simple change
I agree
Usually you have just a very fair amount of code in your source, just to control the scripts and the rest of very basic functionalities.
Unfortunately for this community, people realized that too late and most of the recent commits are trying to bring source codes that should never have been written in source in the first place to Lua.
Actually that isn't a 100% accurate.
Again, it could be avoided from the start if programmers tried to think before coding, but damn, thinking is way too hard and people way too lazy xD
You sound like you are completely inexperienced with this statement.
Lastly: I have to disagree with you, if you have no knowledge in C++ or in the structure of the source you should TOTALLY edit it and try to learn something
Again, you sound completely inexperienced, there is a HUGE difference in editing a script and editing the sources.
but remember to keep a backup or at least trace of the changes you make.
I agree, no matter what you do, always backup before you edit anything, map, scripts, source etc.
 
Ok, so here's what I really want to accomplish.

Mobs automatically from a get-go turn to the direction player is located at. ~ I think the running away works just fine.
But the whole encounter forces player to always be on their toes. When mobs move, they need to move right away or face firewave, or something as mob will always turn in their direction right from the start.
In my idea, mobs shouldn't turn to player direction from a get-go (when they are on melee already, like dragons) ie. Pref, I want it in monster xml file, to be defined as % chance that monster will turn to player directions.

It used to be like that in RL tibia here's a movie on how dragons behaved in engagement with a player on melee.

As you can see they didn't turn right away to player direction.
 
To me I see the dragon turning in your direction initially so really i have no idea what you are wanting to do.. sorry what does turning have to do?
 
Actually that isn't a 100% accurate.
This is the ideal world, not what we currently have :(

You sound like you are completely inexperienced with this statement.
Within time you'll learn that most people just code without thinking. The very thought of "everyone should program because it teaches us to think" is wrong. If you have a B.S in CS you probably already know that most of your colleagues at university don't think at all when programming.

Again, you sound completely inexperienced, there is a HUGE difference in editing a script and editing the sources.
I agree in parts, they are different but it all comes down to structured languages. People are familiar to Lua because they edit it more often and it's a simple language (both to edit and see the results and to understanding), it was designed to be. But ignoring the source just because you don't know, that's not the purpose of having a game. You'll never know if you don't try a little. That's what I tried to say in that comment.

@Lyky: the mobs just turn to player if they send a spell (at least in that code), when they keep in melee they should keep the direction (unless there's other functions controlling the direction while basic attacking, maybe? You'll have to explore a little in the source to confirm this because I have little experience in monsters functions. The only edit that I have ever made in this to my server was to add a few more strategies besides attacking the closest one or random
 
I haven't read all posts but just wanted to argue against xml.
I prefer pure Lua, although Flatander is correct, it is long and complicated.
So making it from scratch without any previous knowledge you gonna rewrite that at least 3 times over months.

I am against xml because it most of the time annoys you a lot when you are making a lot of customizations.

EDIT:
There's just a problem in this history my friend, they already made the monsters turn when they are about to cast a wave and there's no way of undoing that just by using Lua.
You'll have to do at least 1 edit in source:
Ehm? Yes, you can do it without source edits.
 
Last edited:
You sure it's related to spell cast? At 7:13, the dragon cast a wave east while facing south.

Ehm? Yes, you can do it without source edits.
You would need to create a whole new system of spell casting through lua, though. Unless you are going to do tons of customization, the best bet would be to make use of current features.
 
I haven't read all posts but just wanted to argue against xml.
I prefer pure Lua, although Flatander is correct, it is long and complicated.
So making it from scratch without any previous knowledge you gonna rewrite that at least 3 times over months.

I am against xml because it most of the time annoys you a lot when you are making a lot of customizations.

EDIT:

Ehm? Yes, you can do it without source edits.
How the hell do you gonna overcome something that is written deep in the base code of attacking of a monster? Will you store the last direction and then make an even that activates everytime the monster turn: if it's (100-x)% then go back to the previous lookdir? Oh nvm, that would also require source editing since events are only available for players. So perhaps using an onThink event that checks every 200ms and stores all creatures lookdir and then checks if it's changed and then go back as it was if fits this percentage?
Anyway, you're free to prove me wrong but I don't think you can do it even by doing the worst sabotage ever to your server.
 
Even without events I could make a Wave Attack Spell that monsters use that doesn't automatically shoot towards their target in about 9 seconds.

**EDIT**
This is of-course, doing it in a ghetto way I do not recommend, but it's easily possible
 
How the hell do you gonna overcome something that is written deep in the base code of attacking of a monster?
Well, I have written monster behavior in onThink creaturescript, because I think its the most appropriate place to put such a feature.


Even without events I could make a Wave Attack Spell that monsters use that doesn't automatically shoot towards their target in about 9 seconds.
dang you fast brah
 
Well, I have written monster behavior in onThink creaturescript, because I think its the most appropriate place to put such a feature.

dang you fast brah

Could you give small example how the script should be structured, to affect creature and how to call Turn direction behavior of it?





btw. here's another example of how dragons didn't turn look to player direction right away.
1min 30 mark


it may be affected by spell cast / melee attack. I'll test it out on the server by reducing melee attack speed.

TESTED - Its not affected by spell cast or attack. It does it in immediate mode turn to player direction after each move.
Twitch
 
Last edited:
Back
Top