• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action My first lever script!

legolas23

New Member
Joined
Jan 8, 2009
Messages
537
Reaction score
3
Hello
I just started to learn lua and I'm realsing my leverscript.
So just a small explaination how does it work.

If the player pull the lever he will be teleported to the room where some monsters spawn and he won't be able to use this lever anymore.

Here's the code:

Add it to ots directory/data/actions/scripts and save as lever.lua

Code:
---Lever Script by Legolas23---
function onUse(cid, item, fromPosition, itemEx, toPosition)
local creature1 = {x = 527, y = 310, z = 11, stackpos = 1} 	--- write your positions for creature1 to spawn
local creature2 = {x = 527, y = 310, z = 11, stackpos = 1}	--- write your positions for creature2 to spawn
local creature3 = {x = 527, y = 310, z = 11, stackpos = 1}	--- write your positions for creature3 to spawn
local creature4 = {x = 527, y = 310, z = 11, stackpos = 1}	--- write your positions for creature4  to spawn
 
local creature1name = Demon  ---- name of creatures to spawn
local creature2name = Demon
local creature3name = Demon
local creature4name = Demon

local tpPos = {x = 527, y = 310, z = 11, stackpos = 1} --- position where the player will be teleported

if item.itemid == 1945 then
if getPlayerLevel(cid) >= 800 then
queststatus = getPlayerStorageValue(cid,33933)
if queststatus == -1 then
doCreateMonster(creature1name,creature1)
doCreateMonster(creature2name,creature2)
doCreateMonster(creature3name,creature3)
doCreateMonster(creature4name,creature4)
doTeleportThing(cid,tpPos)
setPlayerStorageValue(cid,33933,1)
doPlayerSendTextMessage(cid,22,"Welcome to the hell!!") ---- message when you pull the lever
else
doPlayerSendTextMessage(cid,22,"You have already pulled this lever!") --- message when you have already pulled it
end
end
elseif item.itemid == 1946 then
if getPlayerLevel(cid) >= 800 then
queststatus = getPlayerStorageValue(cid,33933)
if queststatus == -1 then
doCreateMonster(creature1name,creature1)
doCreateMonster(creature2name,creature2)
doCreateMonster(creature3name,creature3)
doCreateMonster(creature4name,creature4)
doTeleportThing(cid,tpPos)
setPlayerStorageValue(cid,33933,1)
doPlayerSendTextMessage(cid,22,"Welcome to the hell!!") ---- message when you pull the lever
doTransformItem(item.uid, 1945)
else
doPlayerSendTextMessage(cid,22,"You have already pulled this lever!") --- message when you have already pulled it
end
end
return TRUE
end
end

And paste this somewhere in
ots directory/data/actions/actions.xml

Code:
<action uniqueid="33933" event="script" value="lever.lua"/>

Enjoy! :)
 
Little edit:
Code:
---Lever Script by Legolas23---
function onUse(cid, item, fromPosition, itemEx, toPosition)

 
local pos = {
	{x = 527, y = 310, z = 11, stackpos = 1},
	{x = 527, y = 310, z = 11, stackpos = 1},
	{x = 527, y = 310, z = 11, stackpos = 1},
	{x = 527, y = 310, z = 11, stackpos = 1}
}

local names = {"Demon", "Demon", "Demon", "Demon"}

local tpPos = {x = 527, y = 310, z = 11, stackpos = 1}
local queststatus = getPlayerStorageValue(cid, 33933)

if item.itemid == 1945 then
	if getPlayerLevel(cid) >= 800 then
		if queststatus == -1 then
			for i = 1, 4 do
				doCreateMonster(names[i], pos[i])
			end
			doTeleportThing(cid, tpPos)
			setPlayerStorageValue(cid, 33933, 1)
			doPlayerSendTextMessage(cid, 22, "Welcome to the hell!!")
		else
			doPlayerSendTextMessage(cid, 22, "You have already pulled this lever!")
		end
	end
elseif item.itemid == 1946 then
	if getPlayerLevel(cid) >= 800 then
		if queststatus == -1 then
			for i = 1, 4 do
				doCreateMonster(names[i], pos[i])
			end
			doTeleportThing(cid, tpPos)
			setPlayerStorageValue(cid, 33933, 1)
			doPlayerSendTextMessage(cid, 22, "Welcome to the hell!!")
			doTransformItem(item.uid, 1945)
		else
			doPlayerSendTextMessage(cid, 22, "You have already pulled this lever!")
		end
	end
end

return true
end
 
Back
Top