• 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.X+ [TFS 1.3] Monster attack monster

Gicu

Well-Known Member
Joined
Feb 26, 2011
Messages
187
Reaction score
52
I am looking for help with a script like in the subject. I would like the monster to attack other monsters. Simple and so difficult. Maybe some hints. Thank you for your help.
 
Solution
Which monster would you like to attack which other monster?
Have you tried Creature:setTarget?
LUA:
local creature = Creature(...)
creature:setTarget(some_userdata)

Or adding creatures as targets?
LUA:
local monster = Monster(...)
monster:addTarget(some_userdata, false)

Perhaps the target your trying to attack is a friend?
LUA:
local monster = Monster(...)
if monster:isFriend(some_userdata) then
    monster:removeFriend(some_userdata)
end

Creature functions:

Monster functions:
Which monster would you like to attack which other monster?
Have you tried Creature:setTarget?
LUA:
local creature = Creature(...)
creature:setTarget(some_userdata)

Or adding creatures as targets?
LUA:
local monster = Monster(...)
monster:addTarget(some_userdata, false)

Perhaps the target your trying to attack is a friend?
LUA:
local monster = Monster(...)
if monster:isFriend(some_userdata) then
    monster:removeFriend(some_userdata)
end

Creature functions:

Monster functions:
 
Last edited:
Solution
Is there a lock on the server so that the monster can not attack another monster?

Example: Orc only attacks a troll, ignores the player.


Creaturescripts, login and add event on monster?
Or maybe event creature?
 
Can't confirm on TFS 1.3, but I have seen scripts where the monster.xml file contains event/creatureevent tags that reference names found in data/creaturescripts/creaturescripts.xml. This would be the place to add additional AI code to monsters.

Unfortunately the otland/forgottenserver repository doesn't seem to have a sample of this.

Edit:
This is the code from TFS 0.4 I was talking about, might be possible to adapt it to TFS 1.3:
data/creaturescripts/creaturescripts.xml
XML:
<event type="think" name="monsterdeath" event="script" value="monsterdeath.lua"/>

data/monsters/group/MonsterFile.xml (placed under </attacks>)
XML:
<script>
    <event name="monsterdeath"/>
</script>

data/creaturescripts/scripts/monsterdeath.lua
LUA:
-- How many seconds shall monster stay alive?
seconds = 4

-- Do you want people to be able to loot monster
-- after its dead? 0 = NO, 1 = YES.
loot = 0


function onThink(cid)
    addEvent(fuckmylife,1000*seconds, {cid=cid})
    return true
end
function fuckmylife(cid)
    local cid = cid.cid
    if isCreature(cid) then
        if loot > 0 then
            doCreatureAddHealth(cid, -getCreatureHealth(cid))
        else
            doRemoveCreature(cid)
        end
    end
    return true
end

The above script has an issue tho, its an onThink event, so it will trigger aprox 2 times each second (when a player is nearby), which in this case will result in many more addEvent timeouts than actually neccesary. (only the first one matter).

onThink might fit your case more, since you want to actively check who to potentially attack. (and not to attack).
 
Last edited:
I find this.
C++ - Enable Monster Friendly Fire [OTX3] (https://otland.net/threads/enable-monster-friendly-fire-otx3.250743/)

And i try this scripts but working only when monster is my summon.
My idea is like that.
Lua - Monsters Attacking Other Monsters (How to?) (https://otland.net/threads/monsters-attacking-other-monsters-how-to.236164/)

Code:
#1 Option - Make the monsters you want to be attacked summons of a player. Then add custom AI to the monster in the form of onThink creaturescripts or custom spells.

#2 Option - Make the monsters non-hostile (so they don't target anyone), then make custom AI scripts (onThink or Spells) that have them follow creatures, and then cast spells on them.

#3 Option - Actually edit the source, which is actually pretty easy, and maybe I'll make a tutorial of how I did it.
(My creatures attack each other and can be allied to certain players as you can see in the below video at around 1:30 seconds)


And this


GlobalEvent - Summon Auto Attacking Monster [1.0] (https://otland.net/threads/summon-auto-attacking-monster-1-0.211199/)
 
Last edited:
how do i add <event name="monsterdeath"/>, if i'm working on otbr?

 
Back
Top