• 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!

Request simplified monster spawn script

Playfal

New Member
Joined
Feb 25, 2010
Messages
7
Reaction score
0
Hi

This script spawns 3 random monsters in 3 different spawn positions when you step on a certain tile with the actionid 43030
The area where those monsters are appearing is from x=306, y=475, z=13 till x=308, y=481, z=13.
I made this script the best way i can and it is working but it is very extensive like you can see.
I would appreciate it if someone could make this script more simple.
I am using TFS 0.3.6, Tibia 8.54

LUA:
function onStepIn(cid, item, pos)

local  monster1 = math.random(1, 3)
local  x1 = math.random(306, 308)
local  y1 = math.random(475, 481)
local  posstat1 = {x=x1, y=y1, z=13} -- Location of spawn 1

local  monster2 = math.random(1, 3)
local  x2 = math.random(306, 308)
local  y2 = math.random(475, 481)
local  posstat2 = {x=x2, y=y2, z=13} -- Location of spawn 2

local  monster3 = math.random(1, 3)
local  x3 = math.random(306, 308)
local  y3 = math.random(475, 481)
local  posstat3 = {x=x3, y=y3, z=13} -- Location of spawn 3

	
     if isPlayer(cid) == TRUE and item.actionid == 43030 and monster1 == 1 then
		 doCreateMonster("Skeleton", posstat1)
      elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster1 == 2 then
      doCreateMonster("Ghoul", posstat1)
        elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster1 == 3 then
        doCreateMonster("Rat", posstat1)      
     end
     
     if isPlayer(cid) == TRUE and item.actionid == 43030 and monster2 == 1 then
		 doCreateMonster("Skeleton", posstat2)
      elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster2 == 2 then
      doCreateMonster("Ghoul", posstat2)
        elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster2 == 3 then
        doCreateMonster("Rat", posstat2)      
     end
     
     if isPlayer(cid) == TRUE and item.actionid == 43030 and monster3 == 1 then
		 doCreateMonster("Skeleton", posstat3)
      elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster3 == 2 then
      doCreateMonster("Ghoul", posstat3)
        elseif isPlayer(cid) == TRUE and item.actionid == 43030 and monster3 == 3 then
        doCreateMonster("Rat", posstat3)             
     end
     
  return TRUE
  
end

Edit:
LUA:
 doesn't work on this forum :)
 
Last edited:
LUA:
? you might mean [.lua][./lua] without the dots? we dont have not the new vBulletin yet

;$ that script is pretty weird, i see many repetitions
isn't is this what you want?

[code=lua]
local i =   { 
    posstat1 = {x= math.random(306, 308), y= math.random(475, 481), z=13}, -- Location of spawn 1
    posstat2 = {x= math.random(306, 308), y= math.random(475, 481), z=13}, -- Location of spawn 2
    posstat3 = {x= math.random(306, 308), y= math.random(475, 481), z=13} -- Location of spawn 3
    }

local j = {
    [1] = {'Skeleton',i.posstat1},
    [2] = {'Ghoul',i.posstat2},
    [3] = {'Rat',i.posstat3},
    }

local k = math.random(3)  

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
    if isPlayer(cid) and item.actionid == 43030 and j[k] then
        doCreateMonster(j[k][1], j[k][2])
    end
    return true
end
 
Last edited:
Fixed the lua, thanks.

I did indeed ment that I wanted to minimize those "repetitions", now each monster and each spawn has its own group of lines.
I just tried your script and it spawns only 1 monster at 1 location.
This monster and location is always the same until I restart the server, so it does the random calculation only once.

Basicly what I want is that each time you step on that tile 3 monsters will spawn in 3 random positions in the area x=306, y=475, z=13 till x=308, y=481, z=13 and each time the kind of monsters can be different (1 rat, 2 ghouls or 2 skeletons, 1 rat or 3 ghouls, etc. )
Also the location from each monster should be different and also different from the previous time you stepped on that tile.
 
Last edited:
You can try this.
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local m = {"Skeleton","Ghoul","Rat"} -- You can add how many monster you want in here and they are outomatily added (make 2 Rat if you want the chanse to get a rat higher. 
    if isPlayer(cid) and item.actionid == 43030 then
      for i = 1,3 do -- 3 stands for how many monsters
	    local k = math.random(#m)
		local pos = {x= math.random(306, 308), y= math.random(475, 481), z=13} -- Random Location for each monster
		doCreateMonster(m[k], pos)
	  end
    end
    return true
end

it's not tested but i hope it should work:)

Changed the script
 
Last edited:
@ Hakeee

I removed the last " , " in line 10 behind z=13).
Now the script gives me an error when stepping on the tile that gives me the message "monster with name '' not found".
This error shows up 3 times, so at least he wants to create 3 monsters.
When I replace, just to test, line 11 "doCreateMonster(m[k], pos)" with my own line "doCreateMonster("Rat", pos)" it does spawn 3 rats on a random spot.
So I think the mistake is at line 9 or 11 where it is picking the monsters.
I tried to change a few things in those lines without success.
 
Last edited:
I have now tested the script and its working good.
LUA:
<movevent type="StepIn" actionid="43030" event="script" value="FILENAME.lua"/>
LUA:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local m = {"Skeleton","Ghoul","Rat"} -- If you want to add a monster it's just to do ,"monstername" after the other 3 monsters.
    if isPlayer(cid) then
      for i = 1,3 do -- 3 stands for how many monsters.
		local k = math.random(#m)
		local pos = {x= math.random(503, 507), y= math.random(1186, 1189), z=7} -- you change the position square there the mobs should be spawned 
		doCreateMonster(m[k], pos)
	  end
    end
end
You may need to change the position
 
Back
Top