• 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 How many in arena?

Majeski20

New Member
Joined
Apr 21, 2008
Messages
602
Reaction score
4
Location
Sweden
Hello, I need a function for my zombie script that shows how many players that are left in the arena.
Like when somone dies this text will show (Player was killed. 10 players left.)

Code:
local temple = {x=1000, y=1000, z=7}
 
local t = {
	items = {2160,25, 2514, 2472, 2470, 7405, 7453},
	exp = 10000000
}
 
local from = {x = 1131, y = 913, z =7}
local to = {x = 1161, y = 930, z=7}
 
local function f(cid)
	doTeleportThing(cid, temple)
	doSendMagicEffect(temple, CONST_ME_TELEPORT)
	doCreatureAddHealth(cid, getCreatureMaxHealth(cid), CONST_ME_MAGIC_BLUE, TEXTCOLOR_BLUE, true)
end
 
function onPrepareDeath(cid, deathList)
	if isInRange(getThingPos(cid), from, to) then
		if isMonster(deathList[1]) and getCreatureName(deathList[1]):lower() == 'deadly zombie' then
			local n = 0
			for x = from.x, to.x do
				for y = from.y, to.y do
					local f = getTopCreature({x=x, y=y, z=from.z}).uid
					if f ~= 0 and isPlayer(f) then
						n = n + 1
					end
				end
			end
			if n == 1 then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Congratulations, you won! Enjoy your reward!')
				doBroadcastMessage('Congratulations! ' .. getCreatureName(cid) ..' won Deadly Zombie arena event! This event is over, next event in approximately 2 hours.', MESSAGE_EVENT_ADVANCE)
				if math.random(15) == 1 then
					doPlayerAddExp(cid, t.exp)
				else
					doPlayerAddItem(cid, t.items[math.random(#t.items)], 1)
				end
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You got owned!')
				doBroadcastMessage(getCreatureName(cid) .. ' got owned and was kicked from arena.', MESSAGE_EVENT_ADVANCE)
			end
		elseif isPlayer(deathList[1]) then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You got owned by playa!')
		end
		f(cid)
		return false
	end
	return true
end

Is that possible? :)

Thanks in advance!
 
Maybe this one:
isInRange(pos, fromPos, toPos) ?
or use getThingFromPos

or edit this one:
Code:
for nx = v.X_FROM, v.X_TO do
		for ny = v.Y_FROM, v.Y_TO do
			local creatureFound = getThingFromPos({x=nx, y=ny, z=15,stackpos=253})
			if creatureFound.uid > 0 then
				if isPlayer(creatureFound.uid) then
This part of script check if is player in area, with stackpos 253...
 
Maybe this one:
isInRange(pos, fromPos, toPos) ?
or use getThingFromPos

or edit this one:
Code:
for nx = v.X_FROM, v.X_TO do
		for ny = v.Y_FROM, v.Y_TO do
			local creatureFound = getThingFromPos({x=nx, y=ny, z=15,stackpos=253})
			if creatureFound.uid > 0 then
				if isPlayer(creatureFound.uid) then
This part of script check if is player in area, with stackpos 253...

Okay, well i dont know how to create the function, maybe u could do it?
 
Lua:
local areaposleftupp = {x= , y = ,z = } -- position left up corner of the arena, make sure you cover all levels of the arena
local areaposrightdown = {x= , y = ,z = } -- position right down corner of the arena, make sure you cover all levels of the arena

local amount = 0
for x = areaposleftupp.x, areaposrightdown.x do
	for y = areaposleftupp.y, areaposrightdown.y do
		for z = areaposleftupp.z, areaposrightdown.z do
		if isPlayer(getTopCreature({x=x,y=y,z=z}).uid) then
			amount = amount+1
		end	
	end
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'There are ' .. amount .. ' players left.')

if your gonna use isInRange you gotta check every player online..

really tired atm, but think it should work
 
Check the thread, it comes with another function getMonstersFromArea, might be helpful, you gotta change it for players though. isPlayer instead of isMonster

U mean this one u posted?

Code:
function getMonstersFromArea(toPositionX, fromPositionX, toPositionY, fromPositionY)
local monsters = {}
for x = fromPositionX, toPositionX do
    for y = fromPositionY, toPositionY do
        local pos = {x=x,y=y,z=7,stackpos=255}
        if isMonster(getThingfromPos(pos.uid)) then
           table.insert(monsters, pos)
        end
    end
end
return monsters
end
 
U mean this one u posted?

Code:
function getMonstersFromArea(toPositionX, fromPositionX, toPositionY, fromPositionY)
local monsters = {}
for x = fromPositionX, toPositionX do
    for y = fromPositionY, toPositionY do
        local pos = {x=x,y=y,z=7,stackpos=255}
        if isMonster(getThingfromPos(pos.uid)) then
           table.insert(monsters, pos)
        end
    end
end
return monsters
end
Yes, he meant that.
 
No I didn't mean that<3, I meant the one conde posted after mine, which has a bug fixed.

Oh, u mean this one
Code:
function getPlayersFromArea(toPositionX, fromPositionX, toPositionY, fromPositionY)
local monsters = {}
for x = fromPositionX, toPositionX do
    for y = fromPositionY, toPositionY do
        local pos = {x=x,y=y,z=7,stackpos=255}
        if isPlayer(getThingfromPos(pos).uid) then
           table.insert(monsters, getThingfromPos(pos).uid)
        end
    end
end
return monsters
end
, but i dont know how to put it in the script, i tried but made it wrong :S
 
Back
Top Bottom