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

a bug in my script creature.lua (OnTargetCombat)

jededias

Member
Joined
Jan 21, 2019
Messages
66
Solutions
1
Reaction score
12
When I attack a monster if I have the outfit 100, it change to 101 for 3 seconds and it back to the normal outfit 100.
This script is working only 1 time, to work again I need attack the monster again, how fix it?

Lua:
local attackOutfit = Condition(CONDITION_OUTFIT, CONDITIONID_COMBAT)
local outfitTable = {
    --Looktype/newLooktype/Seconds until newOutfit removes
    [100] = {newOutfit = 101, outfitInterval = 3}
}

function Creature:onTargetCombat(target)
    if self:isPlayer() then
        local table = outfitTable[self:getOutfit().lookType]
        if table then
            attackOutfit:setOutfit({lookType = table.newOutfit})
            attackOutfit:setTicks(table.outfitInterval * 1000)
            self:addCondition(attackOutfit)
            print("Its Working ?")
        end
    end
    return true
end
 
Solution
E
that is really weird, at least the first check should be print, if it is not printing it, it means there is an error on registering the script, re-check your .xml and login.lua files
something like this I think:
Lua:
local attackOutfit = Condition(CONDITION_OUTFIT, CONDITIONID_COMBAT)
local outfitTable = {
    --Looktype/newLooktype/Seconds until newOutfit removes
    [100] = {newOutfit = 101, outfitInterval = 3}
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
print("first check")
    if primaryType ~= COMBAT_HEALING or secondaryType ~= COMBAT_HEALING then
print("second check")
        local player = attacker:getPlayer()
        if player and creature ~= attacker then
print("third check")
            local table = outfitTable[player:getOutfit().lookType]
            if table then
print("fourth check")
                attackOutfit:setOutfit({lookType = table.newOutfit})
                attackOutfit:setTicks(table.outfitInterval * 1000)
                player:addCondition(attackOutfit)
            end
        end
    end
print("fifth check")
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

don't forget to register it properly on creatureevents.xml and login.lua (idk if last one is necessary but I think so)
 
Last edited by a moderator:
@Evil Puncker
I tried add in creaturescripts: <event type="healthchange" name="damage" script="changeoutfit.lua" />
inside login.lua > player:registerEvent("damage")
And I create the changeoutfit.lua but nothing happens
Lua:
local attackOutfit = Condition(CONDITION_OUTFIT, CONDITIONID_COMBAT)
local outfitTable = {
    --Looktype/newLooktype/Seconds until newOutfit removes
    [100] = {newOutfit = 101, outfitInterval = 3}
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if primaryType ~= COMBAT_HEALING or secondaryType ~= COMBAT_HEALING then
        local player = creature:getPlayer()
        if player and creature ~= attacker then
            local table = outfitTable[player:getOutfit().lookType]
            if table then
                attackOutfit:setOutfit({lookType = table.newOutfit})
                attackOutfit:setTicks(table.outfitInterval * 1000)
                player:addCondition(attackOutfit)
                print("Its Working ?")
            end
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Last edited:
don't think so, I've added a few checks on the script, try it again and see what your console prints
no-prints.png


Dont working
 
that is really weird, at least the first check should be print, if it is not printing it, it means there is an error on registering the script, re-check your .xml and login.lua files
 
Solution
you have to register the creaturescript to each monster for it to register
Thanks! I add the script to the monster.xml and it's working now <3


that is really weird, at least the first check should be print, if it is not printing it, it means there is an error on registering the script, re-check your .xml and login.lua files
Thanks you for the codes bro, its working now, I add the script to monsters xml
 
Back
Top