• 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 randomize items on specific area of map on loop

sharpy

New Member
Joined
Jan 4, 2010
Messages
77
Reaction score
0
i know this sounds kind of strange but i was wondering if there is a way to have a specific area of the map make a random set of items constantly change in a loop like say a 3x3 area of the map that constantly makes 4 or 5 items randomly change constantly on a loop all the time or when you activate a script
 
like say you walk into a quest room and there is a room with 6 tiles out of reach and in those 6 tiles there are items that are randomly changing into other items this would need to start when the server starts as well
 
Try this:
Lua:
local items = {xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx}

for x = 100, 103 do
		for y = 100, 103 do
			doCleanTile({x=x, y=y, z=7})
			for i = 1, #items do
			    doCreateItem(items[i] ,1, {x=x, y=y, z=7})
       		end
 		end
end
Credits to Cyko for basis
 
example? Hey, i'm learning here =D

i put this line above first for x = line
function onThink()

then all i need to do is put it in the global scripts folder and put this line in globalevents.lua
<globalevent name="blah" type="??????" event="script" value="blah.lua"/>

do not know what type needs to be
 
example? Hey, i'm learning here =D

Ye Im busy tahts why ehh, something like this:
data/globalevents/scripts/randomization.lua
Lua:
local items = {xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx, xxxx}
function onThink(cid, interval)
for x = 100, 103 do
		for y = 100, 103 do
			doCleanTile({x=x, y=y, z=7})
			for i = 1, #items do
			    doCreateItem(items[i] ,1, {x=x, y=y, z=7})
       		end
 		end
end
return true
end

globalevents.xml
XML:
<globalevent name="Randomization" interval="10" event="script" value="randomization.lua"/>
Interval is in secs btw
 
alright i got this working to some degree how ever im getting random client crashes ect im gonna keep messing with it and see what i can get it to do TY AGAIN!!!! you dont know how much you've helped me learn already!! (i did notice it causes the client crashes every time it runs the script at the intervals however it still changes the items any idea there?)
 
alright i got this working to some degree how ever im getting random client crashes ect im gonna keep messing with it and see what i can get it to do TY AGAIN!!!! you dont know how much you've helped me learn already!! (i did notice it causes the client crashes every time it runs the script at the intervals however it still changes the items any idea there?)

But items do not clean? Probably you do not have doCleanTile function.
I never heard bout it actually, but Cyko used it so :p
Try to change
Lua:
doCleanTile({x=x, y=y, z=7})
To
Lua:
doRemoveItem(getThingfromPos({x=x, y=y, z=7}.uid, 1)
 
that line just removed the tile under the items still doesnt remove the items ive also tried moving the cleanTile command around so that it uses it at different times only time i got it to actually clean the tile it never put an item on it

(update)
i give up ive tried everything i can think of with the same results from everything
client either crashes
tile doesnt clean
LUA error in console says tile not found
or just deletes the tile

i figured adding some random math in there might fix the problem so it cleans more often than creates items but same problems as above
here is what my final try at the script lookes like
Lua:
function onThink(cid, interval)
local rand = math.random(1, 10)
	if(rand >= 9) then
		for x = 128, 129 do
			for y = 127, 128 do
				for i = 1, #items do
					doCreateItem(items[i] ,1, {x=x, y=y, z=7})
				end
			end
		end
	elseif(rand < 9) then
		doCleanTile({x=128, y=127, z=7})
	end
	return true 
end

i do have the local items line in there i just left it out since im not having problems with it obviously :p
and the clean tile i tried on just one tile to see if it would clean it and it doesnt still just getting a client crash
 
Last edited:
Haha, it removed tile cause I forgot about stackpos
Just change:
Lua:
doRemoveItem(getThingfromPos({x=x, y=y, z=7}.uid, 1)
To
Lua:
doRemoveItem(getThingfromPos({x=x, y=y, z=7, stackpos = 1}.uid, 1)
 
lol just ran into a stackpos problem on another script I wrote pull a lever and make one stone dissapear and another reappear im still having a problem with it putting the stone ontop of players, creatures, and splashes (lol) instead of breaking the script

(update)
script works now with some random math put in :p
was just making an item and removing it at the same time so nothing appeared

YOU ARE AWSOME!!!!!!!
anything i have ran into problems with you have helped me fix
i cant thank you enough!!
 
Last edited:
Back
Top