• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

getWorldMonsters

Dominik ms

Member
Joined
Jan 20, 2010
Messages
424
Reaction score
6
I am looking for script like this
PHP:
	for i, v in ipairs(getPlayersOnline()) do
		doCreatureSay(v,"blabla")
	end
getPlayersOnline, how to change for all monsters??

getWorldCreatures(1)
not work, beacuse if i use
PHP:
doCreatureSay(cid,"" .. getWorldCreatures(1) .. "")
result 'Dominikms: 67'
 
Last edited:
:pOtLand - View Profile: The Forgotten Server

try globalevent
LUA:
local message = {
    text = 'here it goes bla bla bla',
    class = TALKTYPE_MONSTER,
}

local theArea = {
    fromX = 1029,
    fromY = 1147,
    fromZ = 7,
    toX = 1031,
    toY = 1149,
    toZ = 7
}

function onThink(cid, interval, lastExecution)
    for x = theArea.fromX, theArea.toX do
        for y = theArea.fromY, theArea.toY do
            for z = theArea.fromZ, theArea.toZ do
                local thing = getThingFromPos({x=x, y=y, z=z, stackpos = 253})
                if thing.itemid > 0 then
                    if isMonster(thing.uid) then
                        doCreatureSay(thing.uid, message.text, message.class)
                    end
                end
            end
        end
    end
    return true
end
less monsters tho
 
I try script for check all monster in arrea, from x 1 To x 99999 but crushing server :[

Hmm, is possible registerCreatureEvent for all monster??
 
Last edited:
huahushash maybe too much area but idk
but do you really need that for all monsters??
if it were just for some monsters, you can use an onThink creaturescript just for them
 
well for all monsters..unless there is a shorter way at lua..it's easier a c double p, at the part when the monsters say their "voices", the ones that are at their .xml files..that's all can i say..in that case you should request that at c++ requests and support section
 
You can either write a small programm or a lua code or do it manually and add this to every monster you want:
Code:
<script> 
<event name="CREATURESCRIPT_NAME"/> 
</script>
or you need to do a source edit so that certain creatureevent is auto registered to all monsters..
 
refresh
I found this in sorce monsters.cpp:
PHP:
		else if(!xmlStrcmp(p->name, (const xmlChar*)"script"))
		{
			xmlNodePtr tmpNode = p->children;
			while(tmpNode)
			{
				if(!xmlStrcmp(tmpNode->name, (const xmlChar*)"event"))
				{
					if(readXMLString(tmpNode, "name", strValue))
						mType->scriptList.push_back(strValue);
					else
						SHOW_XML_WARNING("Missing name for script event");
				}

				tmpNode = tmpNode->next;
			}
		}
		else
			SHOW_XML_WARNING("Unknown attribute type - " << p->name);

		p = p->next;
	}

i mind this is for register events, but i dont know how to use, so who can help me??
 
LUA:
function getMonstersInRange(fromPos, toPos)

local tmp = {}
 
	if not type(fromPos) == "table" or not type(toPos) == "table" then return error("[Warning - Function::getMonstersInRange] Invalid position.") end
 
	local thing = nil
	for x = fromPos.x, toPos.x do
		for y = fromPos.y, toPos.y do
			for z = fromPos.z, toPos.z do
				for s = 1, 253 do
					local position = {x = x, y = y, z = z, stackpos = s}
					thing = getTileThingByPos(position)
					if isMonster(thing.uid) then
						table.insert(tmp, thing.uid)
					end
				end
			end
		end
	end
	return tmp
end

use it like
LUA:
doPlayerSendTextMessage(cid, 2, "There are " .. table.maxn(getMonstersInRange(fromPos, toPos)) .. " monsters.")
 
Thx, but if i use this script from pos 0 To 999 (all pos in map) then crushing server.
So i need To use this script for all monster on screen (Creaturescript, onThing), but if i have 300 players online then may crush server, so this is stupid code.
 
LUA:
function getMonstersInRange(fromPos, toPos)

local tmp = {}
 
	if not type(fromPos) == "table" or not type(toPos) == "table" then return error("[Warning - Function::getMonstersInRange] Invalid position.") end
 
	local thing = nil
	for x = fromPos.x, toPos.x do
		for y = fromPos.y, toPos.y do
			for z = fromPos.z, toPos.z do
				for s = 1, 253 do
					local position = {x = x, y = y, z = z, stackpos = s}
					thing = getTileThingByPos(position)
					if isMonster(thing.uid) then
						table.insert(tmp, thing.uid)
					end
				end
			end
		end
	end
	return tmp
end

use it like
LUA:
doPlayerSendTextMessage(cid, 2, "There are " .. table.maxn(getMonstersInRange(fromPos, toPos)) .. " monsters.")

it's not smart to loop every tile 253 times
 
Back
Top