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

[Action] Pull Lever Spawn Monster

xx Kami xx

Retired.
Joined
Dec 29, 2012
Messages
509
Reaction score
20
Hello and im looking for a simple script so when you use a lever it spawn's a monster outside the pz area where the lever is pulled i found a script but it isnt the 1 i need maybe someone can mix it around and make it like the script i need?

I made something similar to what you want, I only used a blackboard instead of a lever, because you can't write on/talk to a lever. So maybe this is usefull too.
creaturescripts.xml
XML:
<event type="textedit" name="Demons" event="script" value="demons.lua"/>

Add this to login.lua
Lua:
registerCreatureEvent(cid, "Demons")

demons.lua
Lua:
local config = {
	["1"] = {n = 1},
	["2"] = {n = 2},
	["3"] = {n = 3},
	["4"] = {n = 4},
	["5"] = {n = 5},
	["6"] = {n = 6},
	["7"] = {n = 7},
	["8"] = {n = 8},
	["9"] = {n = 9},
	["10"] = {n = 10}
}

function onTextEdit(cid, item, newText)

	if item.uid == 15000 and item.itemid == 1811 then -- add the unique id in the blackboard
	local x = config[newText]
		if x then
			for i = 1, x.n do
			local pos = {x= math.random(94, 100), y= math.random(114, 120), z=7} -- edit here the locations from the area they spawn in
				doSummonCreature("Demon", pos)
			end
			doPlayerSendTextMessage(cid, 22, ""..newText.." demons spawned.")
		else 
			doPlayerSendTextMessage(cid, 22, "You can only choose between 1 and 10.")
		end
	end
	return true
end

You can write the number of demons you want on the blackboard and they will spawn in the area from local pos.
Btw, if you only want to use a lever, tell me the idea you had about how a player can choose a number while using a lever.


Will Rep++ :cool:
 
Code:
doSummonCreature("Ferumbras", {x = toPosition.x - 1, y = toPosition.y + 1, z = toPosition.z})
Just change position, if you want more monsters to spawn at the same time you can repeat the function.
Example with loop.
Code:
local pos = {
   {x = 100, y = 100, z = 7},
   {x = 101, y = 100, z = 7},
   {x = 102, y = 100, z = 7}
}

for x = 1, #pos do
   doSummonCreature("Demon", pos[x])
end

With different monsters.
Code:
local m = {
   {monster = "Demon", pos = {x = 100, y = 100, z = 7}},
   {monster = "Dragon", pos = {x = 101, y = 100, z = 7}},
   {monster = "Hydra", pos = {x = 102, y = 100, z = 7}}
}

for x = 1, #m do
   doSummonCreature(m[x].monster, m[x].pos)
end
 
Only thing you have to do is replace this line
Code:
doSummonCreature("Ferumbras", {x = toPosition.x - 1, y = toPosition.y + 1, z = toPosition.z})
With what 1 of the things I posted. If you want the same monsters then you can use the first one, for different monsters the second one.
 
@Limos
So would it be like this? and also how do i set it to a switch? the switch id i use is
18:33 You see a lever.
ItemID: [9825], and where would i put the Unique id?


function onUse(cid, item, fromPosition, itemEx, toPosition)

local fromPos = {x = toPosition.x - 10, y = toPosition.y - 10, z = toPosition.z}
local toPos = {x = toPosition.x + 10, y = toPosition.y + 10, z = toPosition.z}

local amount = 0
for x = fromPos.x, toPos.x do
for y = fromPos.y, toPos.y do
for z = fromPos.z, toPos.z do
local m = {
{monster = "Demon", pos = {x = 31635, y = 32327, z = 7}},
{monster = "Dragon", pos = {x = 31647, y = 32328, z = 7}},
{monster = "Hydra", pos = {x = 31649, y = 32336, z = 7}}
}

for x = 1, #m do
doSummonCreature(m[x].monster, m[x].pos)
end
end
end
end
end

if amount >= 1 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "You need to kill Ferumbras first before you can summen one again.")
return true
else
doSummonCreature("Ferumbras", {x = toPosition.x - 1, y = toPosition.y + 1, z = toPosition.z})
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have summened Ferumbras.")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
end
return true
end
 
[25/03/2014 18:08:12] [Error - LuaScriptInterface::loadFile] data/actions/scripts/privatespawnone/lever1.lua:15: '}' expected (to close '{' at line 10) near 'for'
[25/03/2014 18:08:12] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/privatespawnone/lever1.lua)
[25/03/2014 18:08:13] data/actions/scripts/privatespawnone/lever1.lua:15: '}' expected (to close '{' at line 10) near 'for'
 
@Limos

Ok i removed that now i get this error


[26/03/2014 13:26:38] [Error - LuaScriptInterface::loadFile] data/actions/scripts/Privatespawnone/spawnleverone.lua:33: '<eof>' expected near 'end'
[26/03/2014 13:26:38] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/Privatespawnone/spawnleverone.lua)
[26/03/2014 13:26:38] data/actions/scripts/Privatespawnone/spawnleverone.lua:33: '<eof>' expected near 'end'
 
@Limos i get these errors after i added the scripts


[28/03/2014 21:55:16] [Error - CreatureScript Interface]
[28/03/2014 21:55:16] buffer:eek:nAdvance
[28/03/2014 21:55:16] Description:
[28/03/2014 21:55:16] [string "dateToStart = {..."]:60: attempt to index field 'monstersPositions' (a nil value)
[28/03/2014 21:55:16] stack traceback:
[28/03/2014 21:55:16] [string "dateToStart = {..."]:60: in function 'getArea'
[28/03/2014 21:55:16] [string "loadBuffer"]:10: in function <[string "loadBuffer"]:8>



but it dont seem like anything is wrong they spawn
 
Use a rune instead of a lever, add it with the itemid of the rune in actions.xml or you can also make it into a spell by replacing the actions main function (onUse) with the one from spells (onCastSpell) so you can use the xml options for spells.
 
Last edited:
Hey guys I am kind of confused with all these different codes and add that,remove that thingy. I am making annihilator and I got the anni lever teleport thing working. How can I make it though to when this lever is switched to also spawn the monsters on anni? I don't want to do it via Remeres Map Editor to prevent abuse.


Coordinates for the demons are:
a) 1146, 1217, 8
b) 1148, 1217, 8
c) 1147, 1221, 8
d) 1149, 1221, 8
e) 1150, 1219, 8
f) 1150, 1219, 8

Action id of lever is 7000

I am using tfs 0.4

Thank you in advance!
 
Code:
local positions = {
   {x = 1146, y = 1217, z = 8},
   {x = 1148, y = 1217, z = 8},
   {x = 1147, y = 1221, z = 8},
   {x = 1149, y = 1221, z = 8},
   {x = 1150, y = 1219, z = 8},
   {x = 1151, y = 1219, z = 8}
}

for p = 1, #positions do
    if not isCreature(getTopCreature(positions[p]).uid) then
         doSummonCreature("Demon", positions[p])
    end
end
 
Back
Top