Codex NG
Recurrent Flamer
- Joined
- Jul 24, 2015
- Messages
- 2,994
- Solutions
- 12
- Reaction score
- 1,657
Code:
local c = {
["Demon"] = {level = 25, storage = 19000, value = 1, maxSummons = 2}
}
function getSummonsCount(cid)
local count = {}
local player = Player(cid)
if player then
for _, summon in ipairs(player:getSummons()) do
local name = summon:getName()
if not count[name] then
count[name] = 1
else
count[name] = count[name] + 1
end
end
end
return count
end
local msg = {
[0] = function(name) return "You have summoned a(n) " .. name .. "." end,
[1] = function(name) return name .. " does not exist or can't be summmoned." end,
[2] = "You are unable to summon this creature.", -- has to do with storage value
[3] = function(name) return "You can not summon " .. name .. ", you need to be level " .. c[name].level .. "." end,
[4] = function(name) return "You may only summon a total of ".. c[name].maxSummons .." " .. name .. "(s)." end
}
function onSay(player, words, name)
local x = 2
if c[name] then
local summons = getSummonsCount(player:getId())
if summons[name] then
x = summons[name] >= c[name].maxSummons and 4 or x
end
if x ~= 4 then
if c[name].level >= player:getLevel() then
if c[name].value == player:getStorageValue(c[name].storage) then
local monster = Game.createMonster(name, player:getPoisition())
if monster then
monster:setMaster(player)
x = 0
else
x = 1
end
end
else
x = 3
end
end
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, type(msg[x]) == 'function' and msg[x](name) or msg[x])
position:sendMagicEffect( x == 0 and CONST_ME_MAGIC_RED or CONST_ME_POFF)
return true
end
Last edited: