• 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 Boss Kill Add Outfit

adrenysny

Member
Joined
Feb 17, 2021
Messages
140
Reaction score
14
Hello, help me with a script that when killing a boss gives outfit to all those who killed him?
 
Solution
@Xikini @Snavy thanks for the help, this is the script

Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
if not creature:hasOutfit(outfits[creature:getSex()]) and creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received Poltergeist outfit.') then
creature:addOutfit(outfits[creature:getSex()])
end
    end
    return true
end
cEvent:register()
Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")

function...
try
Lua:
local cEvent = CreatureEvent("killBoss")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature then
            player:addOutfit(128) -- change
        end
    end
    return true
end
cEvent:register()
 
try
Lua:
local cEvent = CreatureEvent("killBoss")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature then
            player:addOutfit(128) -- change
        end
    end
    return true
end
cEvent:register()
If I place this line like this it gives male and female?

Code:
player:addOutfit(1270, 1271) -- change
 
Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 128,
    [PLAYERSEX_FEMALE] = 136
}

Lua:
player:addOutfit(outfits[creature:getSex()])
Error Console
Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/creaturescripts/pale_worm_outfit.lua:callback
...server/data/scripts/creaturescripts/pale_worm_outfit.lua:11: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        ...server/data/scripts/creaturescripts/pale_worm_outfit.lua:11: in function <...server/data/scripts/creaturescripts/pale_worm_outfit.lua:7>

so put the script
Code:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature then
            player:addOutfit(outfits[creature:getSex()])
        end
    end
    return true
end
cEvent:register()
 
Error Console
Lua:
Lua Script Error: [Scripts Interface]
/home/forgottenserver/data/scripts/creaturescripts/pale_worm_outfit.lua:callback
...server/data/scripts/creaturescripts/pale_worm_outfit.lua:11: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        ...server/data/scripts/creaturescripts/pale_worm_outfit.lua:11: in function <...server/data/scripts/creaturescripts/pale_worm_outfit.lua:7>

so put the script
Code:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature then
            player:addOutfit(outfits[creature:getSex()])
        end
    end
    return true
end
cEvent:register()
change
Lua:
player:addOutfit(outfits[creature:getSex()])
to
Lua:
creature:addOutfit(outfits[creature:getSex()])
 
hey bro, can you place it only once when you kill him? since I put a message and says it every time they kill the boss
Lua:
local outfit = outfits[creature:getSex()]
if not creature:hasOutfit(outfit) then
    creature:addOutfit(outfit)
end
 
@Xikini @Snavy thanks for the help, this is the script

Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
if not creature:hasOutfit(outfits[creature:getSex()]) and creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received Poltergeist outfit.') then
creature:addOutfit(outfits[creature:getSex()])
end
    end
    return true
end
cEvent:register()
 
@Xikini @Snavy thanks for the help, this is the script

Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")
function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
if not creature:hasOutfit(outfits[creature:getSex()]) and creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have received Poltergeist outfit.') then
creature:addOutfit(outfits[creature:getSex()])
end
    end
    return true
end
cEvent:register()
Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")

function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature and creature:isPlayer() then
            local outfit = outfits[creature:getSex()]
            if not creature:hasOutfit(outfit) then
                creature:addOutfit(outfit)
                creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received Poltergeist outfit.")
            end
        end
    end
    return true
end

cEvent:register()
 
Solution
Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")

function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature and creature:isPlayer() then
            local outfit = outfits[creature:getSex()]
            if not creature:hasOutfit(outfit) then
                creature:addOutfit(outfit)
                creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received Poltergeist outfit.")
            end
        end
    end
    return true
end

cEvent:register()
^ ...server/data/scripts/creaturescripts/pale_worm_outfit.lua:11: unexpected symbol near '`'
 
Lua:
local outfits = {
    [PLAYERSEX_MALE]   = 1270,
    [PLAYERSEX_FEMALE] = 1271
}

local cEvent = CreatureEvent("killPaleWorm")

function cEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    for cid, _ in pairs(creature:getDamageMap()) do
        local creature = Player(cid)
        if creature and creature:isPlayer() then
            local outfit = outfits[creature:getSex()]
            if not creature:hasOutfit(outfit) then
                creature:addOutfit(outfit)
                creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have received Poltergeist outfit.")
            end
        end
    end
    return true
end

cEvent:register()
any idee why it dont work for me ? :D
i dont get a error in console and also no addon for killing the pale worm
i use the latest Canary ;D
Thanks in advance :)
 
any idee why it dont work for me ? :D
i dont get a error in console and also no addon for killing the pale worm
i use the latest Canary ;D
Thanks in advance :)
did you register it to the monster's xml?

XML:
<script>
    <event name="killPaleWorm"/>
</script>
 
Back
Top