As topic goes, using otservbr, how do i register for example creaturescripts in monster files?
Here's a monster file: (without any errors, still it won't execute the called event/script)
Here's the creaturescript:
Here's a monster file: (without any errors, still it won't execute the called event/script)
Lua:
local mType = Game.createMonsterType("Zombie_Event")
local monster = {}
monster.description = "a zombie"
monster.experience = 0
monster.outfit = {
lookType = 311,
lookHead = 0,
lookBody = 0,
lookLegs = 0,
lookFeet = 0,
lookAddons = 0,
lookMount = 0
}
monster.raceId = 512
monster.Bestiary = {
class = "Undead",
race = BESTY_RACE_UNDEAD,
toKill = 1000,
FirstUnlock = 50,
SecondUnlock = 500,
CharmsPoints = 25,
Stars = 3,
Occurrence = 0,
Locations = "Zombie event."
}
monster.health = 15000
monster.maxHealth = 15000
monster.race = "undead"
monster.corpse = 9875
monster.speed = 160
monster.manaCost = 0
monster.maxSummons = 0
monster.changeTarget = {
interval = 4000,
chance = 10
}
monster.strategiesTarget = {
nearest = 80,
health = 10,
damage = 10,
}
monster.flags = {
summonable = false,
attackable = true,
hostile = true,
convinceable = false,
pushable = false,
rewardBoss = false,
illusionable = false,
canPushItems = true,
canPushCreatures = true,
staticAttackChance = 90,
targetDistance = 1,
runHealth = 0,
healthHidden = false,
isBlockable = false,
canWalkOnEnergy = true,
canWalkOnFire = false,
canWalkOnPoison = true,
pet = false
}
monster.light = {
level = 0,
color = 0
}
monster.voices = {
interval = 5000,
chance = 10,
{text = "Mst.... klll....", yell = false},
{text = "Whrrrr... ssss.... mmm.... grrrrl", yell = false},
{text = "Dnnnt... cmmm... clsrrr....", yell = false},
{text = "Httt.... hmnnsss...", yell = false}
}
monster.defenses = {
defense = 15,
armor = 15
}
monster.attacks = {
{name ="melee", interval = 500, chance = 100, minDamage = -100000, maxDamage = -100000},
}
monster.immunities = {
{type = "paralyze", condition = true},
{type = "outfit", condition = false},
{type = "invisible", condition = false},
{type = "bleed", condition = false}
}
mType:register("ZombieOnDeath")
mType:register(monster)
Here's the creaturescript:
Lua:
local ZombieOnDeath = CreatureEvent("ZombieOnDeath")
function ZombieOnDeath.onDeath(monster, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
-- Send text and effect
monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
-- Remove zombie count, when it dies
Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() - 1)
-- Store player kills
local killerId = killer:getId()
if zombieKillCount[killerId] ~= nil then
zombieKillCount[killerId] = zombieKillCount[killerId] + 1
else
zombieKillCount[killerId] = 1
end
return true
end
local ZombieOnPrepareDeath = CreatureEvent("ZombieOnPrepareDeath")
function ZombieOnPrepareDeath.onPrepareDeath(player, killer)
-- Remove player from count
local count = ze_joinCountGlobalStorage()
Game.setStorageValue(ze_joinCountGlobalStorage, count - 1)
-- Reset player after death
player:teleportTo(player:getTown():getTemplePosition())
player:addHealth(player:getMaxHealth())
player:addMana(player:getMaxMana())
player:unregisterEvent("ZombieOnPrepareDeath")
-- Let's reward the 1 last player
if count <= 1 then
local playerName = player:getName()
local item = player:addItem(24850, 15)
-- Store kill count and remove from table to avoid memory leak
local playerId, killCount = player:getId(), 0
if zombieKillCount[playerId] ~= nil then
killCount = zombieKillCount[playerId]
zombieKillCount[playerId] = nil
end
-- Broadcast
Game.broadcastMessage(string.format("Place number %d goes to %s of Zombie Event versus %d Zombies slaining %d Zombies.", count, playerName, getZombieEventZombieCount(), killCount))
-- The last player died, let's reset the event
if count <= 1 then
resetZombieEvent()
end
end
return false
end