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

Lua Damage Attribute

empasor123

New Member
Joined
Jul 17, 2024
Messages
12
Reaction score
1
GitHub
empasor123
I have implemented % damage increase when consuming certain items, and it works on regular TFS 1.4.2. We then moved everything to TFS Optimized and there I saw that there is no onSpawn function for monsters.

Is there any other workarounds? Or other ideas? :D
 
Possible work-around..

You could make a pseudo onSpawn event, by using an onThink event.

Basically you'd have to go through every monster manually, adding the onThink event, so it's registered.. and then anytime you want to register stuff to every monster, like you normally would with onSpawn, you'd throw it into the onThink event.

xml monster
XML:
<script>
    <event name="registerOnSpawnEvents_onThink"/>
</script>
lua monster
LUA:
monster.events = {
    "registerOnSpawnEvents_onThink"
}
onThink event
LUA:
local creatureevent = CreatureEvent("registerOnSpawnEvents_onThink")

function creatureevent.onThink(creature, interval)
    -- register all your other stuff here.

    if creature:getName():lower() ~= "rat" then
        -- register to every monster, except rat
    end

    creature:registerEvent("onHealthChange_damageIncrease") -- example

    creature:unregisterEvent("registerOnSpawnEvents_onThink") -- so that it only runs once
    return true
end

creatureevent:register()
 
Last edited:
Possible work-around..

You could make a pseudo onSpawn event, by using an onThink event.

Basically you'd have to go through every monster manually, adding the onThink event, so it's registered.. and then anytime you want to register stuff to every monster, like you normally would with onSpawn, you'd throw it into the onThink event.

xml monster
XML:
<script>
    <event name="registerOnSpawnEvents_onThink"/>
</script>
lua monster
LUA:
monster.events = {
    "registerOnSpawnEvents_onThink"
}
onThink event
LUA:
local creatureevent = CreatureEvent("registerOnSpawnEvents_onThink")

function creatureevent.onThink(creature, interval)
    -- register all your other stuff here.

    if creature:getName():lower() ~= "rat" then
        -- register to every monster, except rat
    end

    creature:registerEvent("onHealthChange_damageIncrease") -- example

    creature:unregisterEvent("registerOnSpawnEvents_onThink") -- so that it only runs once
    return true
end

creatureevent:register()
I will give this a shot. Thx brother
Post automatically merged:

Seems to work :) Thank you!
 
Last edited:
Back
Top