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

Get your LUA Scripts improved!

Status
Not open for further replies.

Mark

Administrator
Staff member
Administrator
Joined
May 27, 2007
Messages
6,390
Solutions
21
Reaction score
1,470
I've seen alot of beginners to LUA, they get their script to work, but not in the most efficient way, therefor I'm posting this thread so that you can post scripts you want improved here, only one script at a time / user, once I've finished improving your script you can post a new one, this is to make it fair for everyone, and not just let someone make the first post with all scripts the user has, and I'm not going to write scripts from scratch to you, you post a script you've already written and I'll improve it if possible.
 
How do you have it registered in actions.xml?
EDIT: If it is as uniqueid 7007 then here is the script:
Code:
-- Script made by Empty
-- Optimized by Talaturen
-- Visit http://otland.net
-- 00:42 CET >> 2007-08-13
local tile = {x = 222, y = 334, z = 5, stackpos = 1}
local newId = 0
function onUse(cid, item, frompos, item2, topos)
	if item.itemid == 1945 then
		newId = 965
		doTransformItem(item.uid, item.itemid + 1)
	else
		newId = 100
		doTransformItem(item.uid, item.itemid - 1)
	end
	for i = 1, 3 do
		tile.y = tile.y - 1
		doCreateItem(newId, 1, tile)
		doRemoveItem(getThingfromPos(tile).uid, 1)
	end
	return TRUE
end
hmm, how would I add more tiles in this script then? Got a little confused by it
 
Code:
function onStepIn(cid, item, pos)

queststatus = getPlayerStorageValue(cid,item.actionid)

if item.actionid == 20001 then
	ghost1pos = {x=frompos.x, y=frompos.y, z=frompos.z}
	ghost2pos = {x=frompos.x, y=frompos.y, z=frompos.z}
	dspos = {x=frompos.x, y=frompos.y, z=frompos.z}
	if queststatus ~= 1 then
		setPlayerStorageValue(cid,item.actionid,1)
		doPlayerSendCancel(cid,"Seal Completed.")
		doSendMagicEffect(topos,12)
		doSummonCreature("Ghost",ghost1pos)
		doSummonCreature("Ghost",ghost2pos)
		doSummonCreature("Demon Skeleton",dspos)
	else
		return 0
	end		
elseif item.actionid == 20002 then
	lever1 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	lever2 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	lever3 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	lever4 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	lever5 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	lever6 = getThingfromPos{x=frompos.x, y=frompos.y, z=frompos.z, stackpos=1}
	if lever1.itemid == 1945 and lever2.itemid == 1945 and lever3.itemid == 1945 and lever4.itemid == 1945 and lever5.itemid == 1946 and lever6.itemid == 1946 then -- Last 2 switches need to be pulled edit this for your liking
		if queststatus ~= 1 then
			setPlayerStorageValue(cid,item.actionid,1)
			doPlayerSendCancel(cid,"Seal Completed.")
			doSendMagicEffect(topos,12)
		else
			return 0
		end
	end		
elseif item.actionid == 20003 then -- this is linked to a script furtherdown.
	if queststatus ~=1 then
		setPlayerStorageValue(cid,item.actionid,1)
		doPlayerSendCancel(cid,"Seal Completed.")
		doSendMagicEffect(topos,12)
	end
elseif item.actionid == 20004 then
	blood1 = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=2})
	blood2 = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=2})
	if blood1.itemid == 2006 and blood1.type == 2 and blood2.itemid == 2006 and blood2.type == 2 then
		if queststatus ~= 1 then
			setPlayerStorageValue(cid,item.actionid,1)
			doPlayerSendCancel(cid,"Seal Completed.")
			doSendMagicEffect(topos,12)
		end
	end
elseif item.actionid == 20005 then -- this script is linked to an external script
	if getGlobalStorageValue(20005) == 5 then
		if queststatus ~=1 then
			setPlayerStorageValue(cid,item.actionid,1)
			doPlayerSendCancel(cid,"Seal Completed.")
			doSendMagicEffect(topos,12)
		end
	end
elseif item.actionid == 20006 then
	wpearl = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=2})
	bpearl = getThingfromPos({x=pos.x, y=pos.y, z=pos.z, stackpos=2})
	if wpearl.itemid == 2143 and bpearl.itemid == 2144 then
		if queststatus ~= 1 then
			setPlayerStorageValue(cid,item.actionid,1)
			doPlayerSendCancel(cid,"Seal Completed.")
			doSendMagicEffect(topos,12)
			doRemoveItem(wpearl.uid,1)
			doRemoveItem(bpearl.uid,1)
		end
	end
--End of Seals--
elseif item.actionid == 20000 then -- This is for the third seal set this actionid to the tiles that they shouldnt step on.
	startpos = {x=pos.x, y=pos.y, z=pos.z}
	if isPlayer(cid) == 1 then
		doTeleportThing(cid,startpos)
	end
elseif item.actionid == 20007 or item.actionid == 20008 then
	warlock1pos = {x=frompos.x, y=frompos.y, z=frompos.z}
	warlock2pos = {x=frompos.x, y=frompos.y, z=frompos.z}
	if queststatus ~= 1 then
		setPlayerStorageValue(cid,item.actionid,1)
		doSummonCreature("Warlock",warlock1pos)
		doSummonCreature("Warlock",warlock1pos)
	end
end
end

Its the banshee quest, if it helps you understand what its meant to do, ignore the posistions of stuff not mapped where this will go yet
 
It's three tiles, it's like:
tile1 = {x=222, y=333, z=5, stackpos=1} --change tilepos
tile2 = {x=222, y=332, z=5, stackpos=1} --change tilepos
tile3 = {x=222, y=331, z=5, stackpos=1} --change tilepos

but made in a smaller way.
 
Grettings,
I have been working in a team battle script and made this as far with the help of helveg:

BloodCastleBool = false
Countdown = "enabled"
function onThink()
if BloodCastleBool == false then
BCTime = os.clock()
BloodCastleBool = true
end
LocalTime = os.clock ()
if (LocalTime - BCTime) >= (3*60*1000) and Countdown == "enabled" then
broadcast("Message")
OpenCountdown = os.clock ()
Countdown = "disabled"
setGlobalStorageValue(20000,1)
end
if( OpenCountdown ~= nil) then
if((LocalTime - OpenCountdown) >= (1*60*1000) and (Countdown == "disabled")) then
broadcast("Message")
setGlobalStorageValue(20000,-1)
Countdown = "enabled"
BloodCastleBool = false
bcposh = {446,124,5} -- Position where the team 1 get teleported to
bcposa = {377,111,5} -- Position where the team 2 get teleported to
for i = 1, table.getn(GLOBAL_BH_WAITINGLIST) do
for j = 1, table.getn(GLOBAL_BA_WAITINGLIST) do
doTeleportThing(GLOBAL_BH_WAITINGLIST, bcposh)
doTeleportThing(GLOBAL_BA_WAITINGLIST[j], bcposa)
setPlayerStorageValue(GLOBAL_BH_WAITINGLIST,20000,-1)
setPlayerStorageValue(GLOBAL_BA_WAITINGLIST[j],20000,-1)
table.remove(GLOBAL_BH_WAITINGLIST,i)
table.remove(GLOBAL_BA_WAITINGLIST,j)

end
end
end
end
end


this is a NPC who admin the pvp arena, but I don't know what is wrong, the npc load without errors but the only thing the f***er npc do is walk arround but doesn't open the arena...

PD: i have the others functions done just need help with this one.
 
@up: I optimize scripts, not fix errors in them.

Closing this thread now, I'll open it again when I have free time to optimize more scripts.
 
Status
Not open for further replies.
Back
Top