magdy capone
Tibia-Egypt.com
- Joined
- Jan 12, 2014
- Messages
- 34
- Reaction score
- 0
i have Error Last man standing creature
Please help me
and my script lastman.lua
local t = {
tmp = {
{x = 878, y = 996, z = 7}, -- northwest corner of area where players must stand in order to join the event
{x = 881, y = 999, z = 7} -- south east corner
},
arena = {
{x = 870, y = 978, z = 7}, -- nw corner of arena
{x = 888, y = 994, z = 7}, -- se corner of arena
{x = 879, y = 986, z = 7} -- center of arena
},
from = {x = 870, y = 978, z = 7}, -- top left cornor of the playground (random players teleportation)
to = {x = 888, y = 994, z = 7}, -- bottom right cornor of the playground (random players teleportation)
minPlayers = 4, -- min players required to start the battle
noPlayers = 1, -- no players
prize = {10141, 10140, 10137, 11261} -- rewards
}
local kick = 0
local starting= {x = 867, y = 975, z = 7}
local ending= {x = 891, y = 995, z = 7}
function CheckMonster(PosLeft, PosRight)
local floor = PosLeft.z
for x = PosLeft.x, PosRight.x do
for y = PosLeft.y, PosRight.y do
local monster = getTopCreature({x=x, y=y, z=floor}).uid
if monster ~= 0 and isMonster(monster) then
doRemoveCreature(monster)
end
end
end
return true
end
local pos = {
{x=874, y=976, z=7},
{x=882, y=975, z=7},
{x=887, y=977, z=7},
{x=890, y=985, z=7},
{x=891, y=991, z=7},
{x=887, y=995, z=7},
{x=871, y=995, z=7},
{x=867, y=988, z=7},
{x=868, y=982, z=7},
{x=876, y=988, z=7},
{x=882, y=982, z=7}
}
function Summon()
local p = pos[math.random(#pos)]
if doCreateMonster('Battle Mage', p, true, false, false) == RETURNVALUE_NOERROR then
doSendMagicEffect(p, 10)
end
end
function DeleteMonsters()
CheckMonster(starting, ending)
end
local lastSpawn = 0
function onThink()
local arenaPlayers = {}
for x = t.arena[1].x, t.arena[2].x do
for y = t.arena[1].y, t.arena[2].y do
for z = t.arena[1].z, t.arena[2].z do
local pos = {x = x, y = y, z = z}
local n = getTileInfo(pos).creatures
if n ~= 0 then
pos.stackpos = 1
local c = getThingfromPos(pos)
while c.uid ~= 0 do
if c.itemid == 1 and c.type == 1 and getPlayerAccess(c.uid) < 3 then
table.insert(arenaPlayers, c.uid)
if #arenaPlayers == n then
break
end
end
pos.stackpos = pos.stackpos + 1
c = getThingfromPos(pos)
end
end
end
end
end
if #arenaPlayers == 1 then
doCreatureAddHealth(arenaPlayers[1], -getCreatureHealth(arenaPlayers[1]))
doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You won a battle and received your reward.")
doBroadcastMessage(getCreatureName(arenaPlayers[1]) .." won a Last Man Standing battle.")
doPlayerAddItem(arenaPlayers[1], t.prize[math.random(#t.prize)], 1)
DeleteMonsters()
kick = 0
elseif (#arenaPlayers >= 2 and #arenaPlayers <= 4) then
if lastSpawn == 0 then
lastSpawn = os.clock()
else
local max = 50
lastSpawn = 0
if os.clock() - lastSpawn >= 3 then
local total, arch = 0, 0
for x = starting.x, ending.x do
for y = starting.x, ending.y do
local monster = getTopCreature({x=x, y=y, z=7}).uid
if monster ~= 0 and isMonster(monster) then
local name = getCreatureName(monster)
if name == 'Battle Mage' then
total = total + 1
elseif name == 'Archangel' then
arch = arch + 1
end
--if total == max then
-- return true
--end
end
end
end
if total < max then
for i = 1, max - total - #arenaPlayers do
Summon()
end
end
if arch == 0 and #arenaPlayers == 2 then
local m = doCreateMonster('Archangel', {x=879, y=986, z=7}, true, false, false)
if m == true then
m = doCreateMonster('Archangel', {x=879, y=986, z=7}, true, true, false)
end
doCreatureSetDropLoot(m, false)
end
end
end
--[[elseif (#arenaPlayers >= 2 and #arenaPlayers < 5) then
if kick == 0 then
kick = os.time()
else
if os.time() - kick >= 120 then
kick = 0
for i = 1, #arenaPlayers do
doCreatureAddHealth(arenaPlayers, -getCreatureHealth(arenaPlayers))
doPlayerSendTextMessage(arenaPlayers, MESSAGE_STATUS_WARNING, "Too even, try harder next time.")
end
end
end]]
elseif #arenaPlayers == 0 then
kick = 0
local players = {}
for x = t.tmp[1].x, t.tmp[2].x do
for y = t.tmp[1].y, t.tmp[2].y do
for z = t.tmp[1].z, t.tmp[2].z do
local c = getTopCreature({x = x, y = y, z = z})
if c.type == 1 then
table.insert(players, c.uid)
end
end
end
end
if #players >= t.minPlayers then
for i = 1, #players do
local p = {x = math.random(t.from.x, t.to.x), y = math.random(t.from.y, t.to.y), z = math.random(t.from.z, t.to.z)}
while hasItemProperty(getThingfromPos(p).uid, CONST_PROP_BLOCKSOLID) do
p = {x = math.random(t.from.x, t.to.x), y = math.random(t.from.y, t.to.y), z = math.random(t.from.z, t.to.z)}
end
doTeleportThing(players, p)
doSendMagicEffect(p, CONST_ME_TELEPORT)
doPlayerSendTextMessage(players, MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
end
--[[else
for i = 1, #players do
doTeleportThing(players, {x=32369, y=32240, z=7})
doPlayerSendTextMessage(players, MESSAGE_STATUS_WARNING, "The event didn't start because there isn't enough players in area!")
end]]
end
end
for _, cid in ipairs(getPlayersOnline()) do
local o = getCreatureOutfit(cid)
if o.lookType == 0 and o.lookTypeEx == 0 then
o.lookType = getPlayerSex(cid) == 0 and 136 or 128
doCreatureChangeOutfit(cid, o)
end
end
--[[local p = getPlayerByName('Acer')
local p2 = getPlayerByName('Pancake')
if p and p2 then
p = getThingPos(p)
p2 = getThingPos(p2)
if getDistanceBetween(p, p2) < 10 then
doSendDistanceShoot(p, p2, CONST_ANI_CAKE)
doSendMagicEffect(p2, CONST_ME_CAKE)
for _, v in ipairs(getArea(p2, 1, 1)) do
if table.find({0,1,2,3}, getDirectionTo(p2, v)) then
doSendDistanceShoot(p, v, CONST_ANI_CAKE)
doSendMagicEffect(v, CONST_ME_CAKE)
end
end
end
end]]
--doCreateMonster('Bog Raider Private', {x=1045, y=904, z=7}, false, false)
--doCreateMonster('Bog Raider Private', {x=1047, y=904, z=7}, false, false)
return true
end
Please help me
and my script lastman.lua
local t = {
tmp = {
{x = 878, y = 996, z = 7}, -- northwest corner of area where players must stand in order to join the event
{x = 881, y = 999, z = 7} -- south east corner
},
arena = {
{x = 870, y = 978, z = 7}, -- nw corner of arena
{x = 888, y = 994, z = 7}, -- se corner of arena
{x = 879, y = 986, z = 7} -- center of arena
},
from = {x = 870, y = 978, z = 7}, -- top left cornor of the playground (random players teleportation)
to = {x = 888, y = 994, z = 7}, -- bottom right cornor of the playground (random players teleportation)
minPlayers = 4, -- min players required to start the battle
noPlayers = 1, -- no players
prize = {10141, 10140, 10137, 11261} -- rewards
}
local kick = 0
local starting= {x = 867, y = 975, z = 7}
local ending= {x = 891, y = 995, z = 7}
function CheckMonster(PosLeft, PosRight)
local floor = PosLeft.z
for x = PosLeft.x, PosRight.x do
for y = PosLeft.y, PosRight.y do
local monster = getTopCreature({x=x, y=y, z=floor}).uid
if monster ~= 0 and isMonster(monster) then
doRemoveCreature(monster)
end
end
end
return true
end
local pos = {
{x=874, y=976, z=7},
{x=882, y=975, z=7},
{x=887, y=977, z=7},
{x=890, y=985, z=7},
{x=891, y=991, z=7},
{x=887, y=995, z=7},
{x=871, y=995, z=7},
{x=867, y=988, z=7},
{x=868, y=982, z=7},
{x=876, y=988, z=7},
{x=882, y=982, z=7}
}
function Summon()
local p = pos[math.random(#pos)]
if doCreateMonster('Battle Mage', p, true, false, false) == RETURNVALUE_NOERROR then
doSendMagicEffect(p, 10)
end
end
function DeleteMonsters()
CheckMonster(starting, ending)
end
local lastSpawn = 0
function onThink()
local arenaPlayers = {}
for x = t.arena[1].x, t.arena[2].x do
for y = t.arena[1].y, t.arena[2].y do
for z = t.arena[1].z, t.arena[2].z do
local pos = {x = x, y = y, z = z}
local n = getTileInfo(pos).creatures
if n ~= 0 then
pos.stackpos = 1
local c = getThingfromPos(pos)
while c.uid ~= 0 do
if c.itemid == 1 and c.type == 1 and getPlayerAccess(c.uid) < 3 then
table.insert(arenaPlayers, c.uid)
if #arenaPlayers == n then
break
end
end
pos.stackpos = pos.stackpos + 1
c = getThingfromPos(pos)
end
end
end
end
end
if #arenaPlayers == 1 then
doCreatureAddHealth(arenaPlayers[1], -getCreatureHealth(arenaPlayers[1]))
doPlayerSendTextMessage(arenaPlayers[1], MESSAGE_STATUS_CONSOLE_BLUE, "You won a battle and received your reward.")
doBroadcastMessage(getCreatureName(arenaPlayers[1]) .." won a Last Man Standing battle.")
doPlayerAddItem(arenaPlayers[1], t.prize[math.random(#t.prize)], 1)
DeleteMonsters()
kick = 0
elseif (#arenaPlayers >= 2 and #arenaPlayers <= 4) then
if lastSpawn == 0 then
lastSpawn = os.clock()
else
local max = 50
lastSpawn = 0
if os.clock() - lastSpawn >= 3 then
local total, arch = 0, 0
for x = starting.x, ending.x do
for y = starting.x, ending.y do
local monster = getTopCreature({x=x, y=y, z=7}).uid
if monster ~= 0 and isMonster(monster) then
local name = getCreatureName(monster)
if name == 'Battle Mage' then
total = total + 1
elseif name == 'Archangel' then
arch = arch + 1
end
--if total == max then
-- return true
--end
end
end
end
if total < max then
for i = 1, max - total - #arenaPlayers do
Summon()
end
end
if arch == 0 and #arenaPlayers == 2 then
local m = doCreateMonster('Archangel', {x=879, y=986, z=7}, true, false, false)
if m == true then
m = doCreateMonster('Archangel', {x=879, y=986, z=7}, true, true, false)
end
doCreatureSetDropLoot(m, false)
end
end
end
--[[elseif (#arenaPlayers >= 2 and #arenaPlayers < 5) then
if kick == 0 then
kick = os.time()
else
if os.time() - kick >= 120 then
kick = 0
for i = 1, #arenaPlayers do
doCreatureAddHealth(arenaPlayers, -getCreatureHealth(arenaPlayers))
doPlayerSendTextMessage(arenaPlayers, MESSAGE_STATUS_WARNING, "Too even, try harder next time.")
end
end
end]]
elseif #arenaPlayers == 0 then
kick = 0
local players = {}
for x = t.tmp[1].x, t.tmp[2].x do
for y = t.tmp[1].y, t.tmp[2].y do
for z = t.tmp[1].z, t.tmp[2].z do
local c = getTopCreature({x = x, y = y, z = z})
if c.type == 1 then
table.insert(players, c.uid)
end
end
end
end
if #players >= t.minPlayers then
for i = 1, #players do
local p = {x = math.random(t.from.x, t.to.x), y = math.random(t.from.y, t.to.y), z = math.random(t.from.z, t.to.z)}
while hasItemProperty(getThingfromPos(p).uid, CONST_PROP_BLOCKSOLID) do
p = {x = math.random(t.from.x, t.to.x), y = math.random(t.from.y, t.to.y), z = math.random(t.from.z, t.to.z)}
end
doTeleportThing(players, p)
doSendMagicEffect(p, CONST_ME_TELEPORT)
doPlayerSendTextMessage(players, MESSAGE_STATUS_WARNING, "The battle begins. Survive for glory!")
end
--[[else
for i = 1, #players do
doTeleportThing(players, {x=32369, y=32240, z=7})
doPlayerSendTextMessage(players, MESSAGE_STATUS_WARNING, "The event didn't start because there isn't enough players in area!")
end]]
end
end
for _, cid in ipairs(getPlayersOnline()) do
local o = getCreatureOutfit(cid)
if o.lookType == 0 and o.lookTypeEx == 0 then
o.lookType = getPlayerSex(cid) == 0 and 136 or 128
doCreatureChangeOutfit(cid, o)
end
end
--[[local p = getPlayerByName('Acer')
local p2 = getPlayerByName('Pancake')
if p and p2 then
p = getThingPos(p)
p2 = getThingPos(p2)
if getDistanceBetween(p, p2) < 10 then
doSendDistanceShoot(p, p2, CONST_ANI_CAKE)
doSendMagicEffect(p2, CONST_ME_CAKE)
for _, v in ipairs(getArea(p2, 1, 1)) do
if table.find({0,1,2,3}, getDirectionTo(p2, v)) then
doSendDistanceShoot(p, v, CONST_ANI_CAKE)
doSendMagicEffect(v, CONST_ME_CAKE)
end
end
end
end]]
--doCreateMonster('Bog Raider Private', {x=1045, y=904, z=7}, false, false)
--doCreateMonster('Bog Raider Private', {x=1047, y=904, z=7}, false, false)
return true
end