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

Code:
function onSay(cid,words,param)
---Jail command made by Dop---
---Version 2.0---
---Forgotten Server Version---
jailpos = {x=500, y=1441, z=4} --position of the jail--
unjailpos = {x=487, y=1445, z=4} --position where the player needs to get teleported out of jail, for example temple--
if words == '/jail' then	
	if getPlayerGroupId(cid) >= 4 and param ~= "" and getPlayerStorageValue(getPlayerByName(param), 1338) == -1 then 
			jailer = getPlayerName(cid)
				doPlayerSendTextMessage(getPlayerByName(param),25,'You got jailed by '..jailer..'')
				doTeleportThing(getPlayerByName(param),jailpos, 0)
				doPlayerSendTextMessage(cid,21,"You just jailed "..param..".")
				setPlayerStorageValue(getPlayerByName(param), 1338, 1)
				elseif getPlayerGroupId(cid) < 4 then
				doPlayerSendTextMessage(cid,21,"You cannot jail someone!")
				elseif getPlayerStorageValue(getPlayerByName(param), 1338) ~= -1 then
				doPlayerSendTextMessage(cid,21,"This Player is already jailed.")
				else
				doPlayerSendTextMessage(cid,21,"You need to fill in a playername!")
				end
			elseif words == '/unjail' then
	if getPlayerGroupId(cid) >= 4 and param ~= "" and getPlayerStorageValue(getPlayerByName(param), 1338) == 1 then 
			unjailer = getPlayerName(cid)
				doPlayerSendTextMessage(getPlayerByName(param),25,'You got unjailed by '..unjailer..'')
				doTeleportThing(getPlayerByName(param),unjailpos, 0)
				doPlayerSendTextMessage(cid,21,"You just unjailed "..param..".")
				setPlayerStorageValue(getPlayerByName(param), 1338, -1)
				elseif getPlayerGroupId(cid) < 4 then
				doPlayerSendTextMessage(cid,21,"You cannot unjail someone!")
				elseif getPlayerStorageValue(getPlayerByName(param), 1338) ~= 1 then
				doPlayerSendTextMessage(cid,21,"This Player is already unjailed.")
				else
				doPlayerSendTextMessage(cid,21,"You need to fill in a playername!")
				end
end			
end
 
Last edited:
Done, I recommend you to test it before using it in your server because I do not test scripts that I optimize.

Code:
-- Optimized by Talaturen
-- Visit http://otland.net
-- 21:20 CET >> 2007-08-07
local jailPosition = {x = 500, y = 1441, z = 4} -- Position of the Jail
local unjailPosition = {x = 487, y = 1445, z = 4} -- Position where the player will be teleported when being unjailed, for example: temple.

function onSay(cid, words, param)
	local target = getPlayerByName(param)
	if target == FALSE then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "A player with that name is not online")
	elseif getPlayerGroupId(cid) < 4 then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You cannot unjail someone!")
	elseif param == "" then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You need to fill in a playername!")
	elseif words == "/jail" then	
		if getPlayerStorageValue(target, 1338) == -1 then
			doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_RED, "You got jailed by " .. getPlayerName(cid))
			doTeleportThing(target, jailPosition, 1)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You just jailed " .. param .. ".")
			setPlayerStorageValue(target, 1338, 1)
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "A player with that name is already jailed.")
		end
	elseif getPlayerStorageValue(target, 1338) ~= -1 then
		doPlayerSendTextMessage(target, MESSAGE_STATUS_CONSOLE_RED, "You got unjailed by " .. getPlayerName(cid))
		doTeleportThing(target, unjailPosition, 1)
		doPlayerSendTextMessage(target, MESSAGE_STATUS_DEFAULT, "You just unjailed " .. getCreatureName(param) .. ".")
		setPlayerStorageValue(target, 1338, -1)
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "A player with that name is not jailed.")
	end
end
 
Code:
local ActiveValue = 666
local YesValue = 1000
local NoValue =  2000
local ExhaustTime = 600 --- Time (in minutes) that the player will have to wait 'till he can vote again Default = 10min
local AutoEnd = true ---Use Auto End (set true or false)
local ToEnd = 1000*60*10 -- Time to auto-end poll (in miliseconds) Default = 10min
local WriteBook = false --- Write a book with the results (true or false)

function onSay(cid, words, param)
	if words == '!makepoll' then	
		if getPlayerAccess(cid) >= 3 then
			if getGlobalStorageValue(ActiveValue) ~= 1 then
				if param ~= nil then
					doPlayerSay(cid,'Poll: '..param..'',9)
					setGlobalStorageValue(YesValue,0)
					setGlobalStorageValue(NoValue,0)
					setGlobalStorageValue(ActiveValue,1)
					if AutoEnd == true then
						addEvent(EndPoll,ToEnd,cid)
					end
				end
			else
				doPlayerSendTextMessage(cid,22,'A poll is already running.')
			end
		else
			doPlayerSendCancel(cid,'Only Gamemasters can make a poll')
		end
	elseif words == '!vote' and getGlobalStorageValue(ActiveValue) == 1 and exhaust(cid,500,ExhaustTime) == 1 then
		if param == 'yes' then
			setGlobalStorageValue(YesValue,getGlobalStorageValue(YesValue)+1)
			doPlayerSendTextMessage(cid,22,'Thanks for your vote.')
		elseif param == 'no' then
			setGlobalStorageValue(NoValue,getGlobalStorageValue(NoValue)+1)
			doPlayerSendTextMessage(cid,22,'Thanks for your vote.')
		else
			doPlayerSendTextMessage(cid,22,'Use only !vote "yes or !vote "no.')
		end			
	elseif words == '!endpoll' then
		if getPlayerAccess(cid) >= 3 then 
			if getGlobalStorageValue(ActiveValue) == 1 then
				setGlobalStorageValue(ActiveValue,2)
				doSetItemText(doPlayerAddItem(cid,1984,1),'The results are: Yes: '..getGlobalStorageValue(YesValue)..', No: '..getGlobalStorageValue(NoValue)..'')
				doPlayerSay(cid,'The poll has ended, thanks for your votes.',9)
			else
				doPlayerSendCancel(cid,'There is no poll running.')
			end
		else
			doPlayerSendCancel(cid,'Only Gamemasters can end polls')
		end
	end
end

function EndPoll(cid)
if getGlobalStorageValue(ActiveValue) == 1 then
setGlobalStorageValue(ActiveValue,2)
doPlayerSay(cid,'The poll has ended, thanks for your votes.',9)
if WriteBook == true then
doSetItemText(doPlayerAddItem(cid,1984,1),'The results are: Yes: '..getGlobalStorageValue(YesValue)..', No: '..getGlobalStorageValue(NoValue)..'')
end
print('The results are: Yes = '..getGlobalStorageValue(YesValue)..', No = '..getGlobalStorageValue(NoValue)..'')
else
print('No polls running')
end
end

i'd like to have this working with tfs :)
 
I'm not writing extra code, I only improve/optimize the LUA script.

Code:
-- Optimized by Talaturen
-- Visit http://otland.net
-- 22:25 CET >> 2007-08-07
local activeValue = 666 -- Storage value of active poll
local yesValue = 1000 -- Storage value of yes votes
local noValue =  2000 -- Storage value of no votes
local exhaustTime = 600 -- Time in minutes that the player will have to wait before gaining ability to vote again (Default: 10 minutes)
local autoEnd = TRUE -- Auto ending poll (TRUE or FALSE)
local toEnd = 1000 * 60 * 10 -- Time until poll will auto end in miliseconds (Default: 10 minutes)
local writeBook = FALSE -- Write a book with the results (TRUE or FALSE)
function onSay(cid, words, param)
	if words == "!makepoll" then
		if getPlayerGroupId(cid) > 3 then
			if getGlobalStorageValue(activeValue) ~= TRUE then
				if param ~= "" then
					broadcastMessage("Poll: " .. param)
					setGlobalStorageValue(yesValue, 0)
					setGlobalStorageValue(noValue, 0)
					setGlobalStorageValue(activeValue, 1)
					if autoEnd == TRUE then
						addEvent(endPoll, toEnd, cid)
					end
				end
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There is already a poll running.")
			end
		else
			doPlayerSendCancel(cid, "Only gamemasters may create a poll.")
		end
	elseif getGlobalStorageValue(activeValue) == TRUE then
		if words == "!vote" then
			if exhaust(cid, 500, exhaustTime) == TRUE then
				if param == "yes" then
					setGlobalStorageValue(yesValue, getGlobalStorageValue(yesValue) + 1)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Thanks for your vote.")
				elseif param == "no" then
					setGlobalStorageValue(noValue, getGlobalStorageValue(noValue) + 1)
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Thanks for your vote.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Invalid command parameter, use 'yes' or 'no'.")
				end
			end
		elseif getPlayerGroupId(cid) > 3 then
			setGlobalStorageValue(activeValue, 2)
			doSetItemText(doPlayerAddItem(cid, 1984, 1), "The results are...\n\nYes: " .. getGlobalStorageValue(yesValue) .. "\nNo: " .. getGlobalStorageValue(noValue))
			broadcastMessage("The poll has ended, thanks for your votes.")
		else
			doPlayerSendCancel(cid, "Only gamemasters may end running polls.")
		end
	else
		doPlayerSendCancel(cid, "There is no poll running.")
	end
end

function endPoll(cid)
	if getGlobalStorageValue(activeValue) == TRUE then
		setGlobalStorageValue(activeValue, 2)
		broadcastMessage("The poll has ended, thanks for your votes.")
		if writeBook == TRUE then
			doSetItemText(doPlayerAddItem(cid, 1984, 1), "The results are, yes: " .. getGlobalStorageValue(yesValue) .. ", no: " .. getGlobalStorageValue(noValue))
		end
		print("The results are, yes: " .. getGlobalStorageValue(yesValue) .. ", no: " .. getGlobalStorageValue(noValue))
	end
end
 
No script is to big your you?

Code:
function onUse(cid, item, frompos, item2, topos)

    if item.itemid == 2283 then
        access = getPlayerAccess(cid)
        targetis = topos
        targetis.stackpos = 253
        target = getThingfromPos(targetis)
        if access >= 3 then

            slots = {
        {y=64, z=0, time=900},
        {y=64, z=1, time=1800},
        {y=64, z=2, time=3600},
        {y=64, z=3, time=7200},
        {y=64, z=4, time=14400},
        {y=64, z=5, time=21600},
        {y=64, z=6, time=32400},
        {y=64, z=7, time=43200},
        {y=64, z=8, time=57600},
        {y=64, z=9, time=72000},
        {y=64, z=10, time=86400},
            {y=64, z=11, time=129600},
        {y=64, z=12, time=172800},
        {y=64, z=13, time=259200},
        {y=64, z=14, time=345600},
        {y=64, z=15, time=432000},
        {y=64, z=16, time=604800},
        {y=64, z=17, time=864000},
        {y=64, z=18, time=1209600},
        {y=64, z=19, time=1814400},

        {y=10, z=0, time=1}}
                    
        jailstatus = getPlayerStorageValue(target.uid,666)
            if jailstatus == 1 or jailstatus == -1 then
                        if getPlayerAccess(target.uid) <= 2 and getPlayerAccess(target.uid) >= 0 then
                            for i, a in ipairs(slots) do
                    
                                if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
                
                                    currenttime = os.time() + (3600 * 6)
                        outtime = currenttime + a.time
                        date = os.date("*t",outtime)
                        
                        name = getPlayerName(target.uid)
                        jailer = getPlayerName(cid)
                        doPlayerSendTextMessage(target.uid,22,"You were jailed by "..jailer.." and can leave jail "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.." (CET) by pulling the lever.")
                               
                        jail = {x=350, y=300, z=7}
                           
                        doTeleportThing(target.uid,jail)
                         doSendMagicEffect(topos,14)
                         doSendMagicEffect(topos,13)
                         doSendMagicEffect(topos,12)
                         doSendMagicEffect(topos,11)
                         doSendMagicEffect(topos,10)
                         doSendMagicEffect(topos,9)
                         doSendMagicEffect(topos,8)
                         doSendMagicEffect(topos,7)
                         doSendMagicEffect(topos,6)
                         doSendMagicEffect(topos,5)
                         doSendMagicEffect(topos,4)
                         doSendMagicEffect(topos,3)
                         doSendMagicEffect(topos,2)
                        doSendMagicEffect(topos,1)
                         doSendMagicEffect(topos,15)
                        doPlayerSetMasterPos(target.uid,jail)
                        setPlayerStorageValue(target.uid,666,2)
                        setPlayerStorageValue(target.uid,667,outtime)
                                            
                        doPlayerSendTextMessage(cid,22,"You jailed "..name.." and he/she can leave jail "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.." (CET).")

                        -- Start log
                        
                        jaillog = "./data/jaillog.txt"
                        
                        f = assert(io.open(jaillog,"a+"))
                        
                        datenow = os.date("*t")
                        newline = "\n"..datenow.day.."."..datenow.month.."."..datenow.year.." "..datenow.hour..":"..datenow.min..":"..datenow.sec.." : "..jailer.." jailed "..name.." and he can leave jail "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.."."
                        
                        f:write(newline)
                        f:close(jaillog)

                        -- End log
                        
                        end
                    end
                else
                    doPlayerSendCancel(cid,"You can't jail yourself or anyone else with a higher access.")
                end
            elseif jailstatus == 2 then
                for i, a in ipairs(slots) do

                            if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
                
                        currenttime = os.time() + (3600 * 6)
                        outtime = currenttime + a.time
                        date = os.date("*t",outtime)
                        
                        name = getPlayerName(target.uid)
                        jailer = getPlayerName(cid)
                        doPlayerSendTextMessage(target.uid,22,"Your jailtime was changed by "..jailer.." and you can now leave jail "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.." (CET) by pulling the lever.")

                        setPlayerStorageValue(target.uid,667,outtime)
                        
                        doPlayerSendTextMessage(cid,22,"You changed/resetted "..name.."'s unjailtime to "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.." (CET).")
                        
                        -- Start log
                        
                        jaillogupdate = "./data/jaillogupdate.txt"
                        
                        f = assert(io.open(jaillogupdate,"a+"))
                        
                        datenow = os.date("*t")
                        newline = "\n"..datenow.day.."."..datenow.month.."."..datenow.year.." "..datenow.hour..":"..datenow.min..":"..datenow.sec.." : "..jailer.." changed "..name.."'s jailtime and he can now leave jail "..date.day.."."..date.month.."."..date.year.." at "..date.hour..":"..date.min..":"..date.sec.."."
                        
                        f:write(newline)
                        f:close(jaillogupdate)

                        -- End log
                        
                    end
                end    
            end
        elseif access <= 2 then
            doPlayerSendTextMessage(cid,22,"This is a restricted rune.")
            doRemoveItem(item.uid,255)
            doSendMagicEffect(cid,2)
        end
    elseif item.uid == 7149 then
        jailstatus = getPlayerStorageValue(cid,666)
        if jailstatus == 2 then
            outdate = getPlayerStorageValue(cid,667)
            if outdate ~= nil then
                timeleft = outdate - (os.time() + (3600 * 6))
                                
                if timeleft < 0  then
                    home = {x=33, y=100, z=7}
                    doTeleportThing(cid,home)
                    doPlayerSendTextMessage(cid,22,"You left jail.")
                    setPlayerStorageValue(cid,666,1)
                    setPlayerStorageValue(cid,667,0)
                elseif timeleft > 0 then
                    time = os.date("*t",outdate)
                    doPlayerSendTextMessage(cid,22,"You can leave jail "..time.day.."."..time.month.."."..time.year.." at "..time.hour..":"..time.min..":"..time.sec.." (CET).")
                end
            
            else
                doPlayerSendTextMessage(cid,22,"Message a tutor or GM/God to set a jailtime on you.")
            end
        elseif jailstatus == 1 or jailstatus == -1 then
            doPlayerSendTextMessage(cid,22,"Havin' fun?")
        end
        if item.itemid == 1945 then
            doTransformItem(item.uid,item.itemid+1)
        elseif item.itemid == 1946 then
            doTransformItem(item.uid,item.itemid-1)
        end
    else
        return 0
    end
    return 1
end
Let me know if you think it is to much work.
 
Code:
-- Optimized by Talaturen
-- Visit http://otland.net
-- 19:22 CET >> 2007-08-08
slots = {
	{y = 64, z = 0, time = 900}, {y = 64, z = 1, time = 1800},
	{y = 64, z = 2, time = 3600}, {y = 64, z = 3, time = 7200},
	{y = 64, z = 4, time = 14400}, {y = 64, z = 5, time = 21600},
	{y = 64, z = 6, time = 32400}, {y = 64, z = 7, time = 43200},
	{y = 64, z = 8, time = 57600}, {y = 64, z = 9, time = 72000},
	{y = 64, z = 10, time = 86400}, {y = 64, z = 11, time = 129600},
	{y = 64, z = 12, time = 172800}, {y = 64, z = 13, time = 259200},
	{y = 64, z = 14, time = 345600}, {y = 64, z = 15, time = 432000},
	{y = 64, z = 16, time = 604800}, {y = 64, z = 17, time = 864000},
	{y = 64, z = 18, time = 1209600}, {y = 64, z = 19, time = 1814400},
	{y = 10, z = 0, time = 1}
}

function onUse(cid, item, frompos, item2, topos)
	if item.itemid == 2283 then
		topos.stackpos = 253
		target = getThingfromPos(topos)
		if getPlayerAccess(cid) > 2 then
			if getPlayerStorageValue(target.uid, 666) == 2 then
				for i, a in ipairs(slots) do
					if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
						outtime = os.time() + (3600 * 6) + a.time
						date = os.date("*t",outtime)
						name = getPlayerName(target.uid)
						jailer = getPlayerName(cid)
						doPlayerSendTextMessage(target.uid, 22, "Your jailtime was changed by " .. jailer .. " and you can now leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET) by pulling the lever.")
						setPlayerStorageValue(target.uid, 667, outtime)
						doPlayerSendTextMessage(cid, 22, "You changed/resetted " .. name .. "'s unjailtime to " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET).")
						-- Start log
						f = assert(io.open("./data/jaillogupdate.txt", "a+"))
						datenow = os.date("*t")
						newline = "\n" .. datenow.day .. "." .. datenow.month .. "." .. datenow.year .. " " .. datenow.hour .. ":" .. datenow.min .. ":" .. datenow.sec .. " : " .. jailer .. " changed " .. name .. "'s jailtime and he can now leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. "."
						f:write(newline)
						f:close("./data/jaillogupdate.txt")
						-- End log
					end
				end
			elseif getPlayerAccess(target.uid) < 3 then
				for i, a in ipairs(slots) do
					if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
						outtime = os.time() + (3600 * 6) + a.time
						date = os.date("*t", outtime)
						name = getPlayerName(target.uid)
						jailer = getPlayerName(cid)
						doPlayerSendTextMessage(target.uid, 22, "You were jailed by " .. jailer .. " and can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET) by pulling the lever.")
						doTeleportThing(target.uid, {x = 350, y = 300, z = 7})
						for i = 1, 15 do
							doSendMagicEffect(topos, i)
						end
						doPlayerSetMasterPos(target.uid, {x = 350, y = 300, z = 7})
						setPlayerStorageValue(target.uid, 666, 2)
						setPlayerStorageValue(target.uid, 667, outtime)
						doPlayerSendTextMessage(cid, 22, "You jailed " .. name .. " and he/she can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET).")
						-- Start log
						f = assert(io.open("./data/jaillog.txt" ,"a+"))
						datenow = os.date("*t")
						f:write("\n" .. datenow.day .. "." .. datenow.month .. "." .. datenow.year .. " " .. datenow.hour .. ":" .. datenow.min .. ":" .. datenow.sec .. " : " .. jailer .. " jailed " .. name .. " and he can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. ".")
						f:close("./data/jaillog.txt")
						-- End log
					end
				end
			else
				doPlayerSendCancel(cid, "You can't jail yourself or anyone else with a higher access.")
			end
		else
			doPlayerSendTextMessage(cid, 22, "This is a restricted rune.")
			doRemoveItem(item.uid, 255)
			doSendMagicEffect(cid, 2)
		end
	elseif item.uid == 7149 then
		if getPlayerStorageValue(target.uid, 666) == 2 then
			outdate = getPlayerStorageValue(cid, 667)
			if outdate ~= nil then
				if (outdate - (os.time() + (3600 * 6))) <= 0 then
					doTeleportThing(cid, {x = 33, y = 100, z = 7})
					doPlayerSendTextMessage(cid, 22, "You left jail.")
					setPlayerStorageValue(cid, 666, 1)
					setPlayerStorageValue(cid, 667, 0)
				else
					time = os.date("*t", outdate)
					doPlayerSendTextMessage(cid, 22, "You can leave jail " .. time.day .. "." .. time.month .. "." .. time.year .. " at " .. time.hour .. ":" .. time.min .. ":" .. time.sec .. " (CET).")
				end
			else
				doPlayerSendTextMessage(cid, 22, "Message a tutor or GM/God to set a jailtime on you.")
			end
		else
			doPlayerSendTextMessage(cid, 22, "Havin' fun?")
		end
		if item.itemid == 1945 then
			doTransformItem(item.uid, item.itemid + 1)
		elseif item.itemid == 1946 then
			doTransformItem(item.uid, item.itemid - 1)
		end
	else
		return 0
	end
	return 1
end

Remember to test it enough on a test server before you instantly add it into a real server.
 
Code:
-- Optimized by Talaturen
-- Visit http://otland.net
-- 19:22 CET >> 2007-08-08
slots = {
    {y = 64, z = 0, time = 900}, {y = 64, z = 1, time = 1800},
    {y = 64, z = 2, time = 3600}, {y = 64, z = 3, time = 7200},
    {y = 64, z = 4, time = 14400}, {y = 64, z = 5, time = 21600},
    {y = 64, z = 6, time = 32400}, {y = 64, z = 7, time = 43200},
    {y = 64, z = 8, time = 57600}, {y = 64, z = 9, time = 72000},
    {y = 64, z = 10, time = 86400}, {y = 64, z = 11, time = 129600},
    {y = 64, z = 12, time = 172800}, {y = 64, z = 13, time = 259200},
    {y = 64, z = 14, time = 345600}, {y = 64, z = 15, time = 432000},
    {y = 64, z = 16, time = 604800}, {y = 64, z = 17, time = 864000},
    {y = 64, z = 18, time = 1209600}, {y = 64, z = 19, time = 1814400},
    {y = 10, z = 0, time = 1}
}

function onUse(cid, item, frompos, item2, topos)
    if item.itemid == 2283 then
        topos.stackpos = 253
        target = getThingfromPos(topos)
        if getPlayerAccess(cid) > 2 then
            if getPlayerStorageValue(target.uid, 666) == 2 then
                for i, a in ipairs(slots) do
                    if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
                        outtime = os.time() + (3600 * 6) + a.time
                        date = os.date("*t",outtime)
                        name = getPlayerName(target.uid)
                        jailer = getPlayerName(cid)
                        doPlayerSendTextMessage(target.uid, 22, "Your jailtime was changed by " .. jailer .. " and you can now leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET) by pulling the lever.")
                        setPlayerStorageValue(target.uid, 667, outtime)
                        doPlayerSendTextMessage(cid, 22, "You changed/resetted " .. name .. "'s unjailtime to " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET).")
                        -- Start log
                        f = assert(io.open("./data/jaillogupdate.txt", "a+"))
                        datenow = os.date("*t")
                        newline = "\n" .. datenow.day .. "." .. datenow.month .. "." .. datenow.year .. " " .. datenow.hour .. ":" .. datenow.min .. ":" .. datenow.sec .. " : " .. jailer .. " changed " .. name .. "'s jailtime and he can now leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. "."
                        f:write(newline)
                        f:close("./data/jaillogupdate.txt")
                        -- End log
                    end
                end
            [B]elseif getPlayerAccess(target.uid) < 3 then[/B]
                [U]for i, a in ipairs(slots) do[/U]
                    if (frompos.y == a.y or frompos.y >= 64) and frompos.z == a.z and frompos.x == 65535 then
                        outtime = os.time() + (3600 * 6) + a.time
                        date = os.date("*t", outtime)
                        name = getPlayerName(target.uid)
                        jailer = getPlayerName(cid)
                        doPlayerSendTextMessage(target.uid, 22, "You were jailed by " .. jailer .. " and can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET) by pulling the lever.")
                        doTeleportThing(target.uid, {x = 350, y = 300, z = 7})
                        for i = 1, 15 do
                            doSendMagicEffect(topos, i)
                        end
                        doPlayerSetMasterPos(target.uid, {x = 350, y = 300, z = 7})
                        setPlayerStorageValue(target.uid, 666, 2)
                        setPlayerStorageValue(target.uid, 667, outtime)
                        doPlayerSendTextMessage(cid, 22, "You jailed " .. name .. " and he/she can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " (CET).")
                        -- Start log
                        f = assert(io.open("./data/jaillog.txt" ,"a+"))
                        datenow = os.date("*t")
                        f:write("\n" .. datenow.day .. "." .. datenow.month .. "." .. datenow.year .. " " .. datenow.hour .. ":" .. datenow.min .. ":" .. datenow.sec .. " : " .. jailer .. " jailed " .. name .. " and he can leave jail " .. date.day .. "." .. date.month .. "." .. date.year .. " at " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. ".")
                        f:close("./data/jaillog.txt")
                        -- End log
                    end
                [U]else[/U]
                    doPlayerSendCancel(cid, "You can't jail yourself or anyone else with a higher access.")
                end
            end
        else
            doPlayerSendTextMessage(cid, 22, "This is a restricted rune.")
            doRemoveItem(item.uid, 255)
            doSendMagicEffect(cid, 2)
        end
    elseif item.uid == 7149 then
        if getPlayerStorageValue(target.uid, 666) == 2 then
            outdate = getPlayerStorageValue(cid, 667)
            if outdate ~= nil then
                if (outdate - (os.time() + (3600 * 6))) <= 0 then
                    doTeleportThing(cid, {x = 33, y = 100, z = 7})
                    doPlayerSendTextMessage(cid, 22, "You left jail.")
                    setPlayerStorageValue(cid, 666, 1)
                    setPlayerStorageValue(cid, 667, 0)
                else
                    time = os.date("*t", outdate)
                    doPlayerSendTextMessage(cid, 22, "You can leave jail " .. time.day .. "." .. time.month .. "." .. time.year .. " at " .. time.hour .. ":" .. time.min .. ":" .. time.sec .. " (CET).")
                end
            else
                doPlayerSendTextMessage(cid, 22, "Message a tutor or GM/God to set a jailtime on you.")
            end
        else
            doPlayerSendTextMessage(cid, 22, "Havin' fun?")
        end
        if item.itemid == 1945 then
            doTransformItem(item.uid, item.itemid + 1)
        elseif item.itemid == 1946 then
            doTransformItem(item.uid, item.itemid - 1)
        end
    else
        return 0
    end
    return 1
end
Remember to test it enough on a test server before you instantly add it into a real server.
I didn't know you could use 'else' with a 'for' (Or did you mess up?)(underlined part)
And that bolded part, isn't it supposed to check the jail status? (2 is jailed and 1 is not jailed as you can see)
 
I didn't know you could use 'else' with a 'for' (Or did you mess up?)(underlined part)
And that bolded part, isn't it supposed to check the jail status? (2 is jailed and 1 is not jailed as you can see)

If it doesn't go inside the first if statement it means that the jailstatus is NOT 2, so we dont need to make another check to make sure it is not 2, we can just use the first check inside the else with 'elseif' instead.
 
Ok about the jail status, but you didn't answer the first thing I said.

Code:
error:48: 'end' expected (to close 'for' at line 26) near 'else'
 
Oh, the my bad, the else is for the if statement around the for loop, edited my post now.
 
Code:
--Script made by Empty
function onUse(cid, item, frompos, item2, topos)
	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
	gettile1 = getThingfromPos(tile1)
	gettile2 = getThingfromPos(tile2)
	gettile3 = getThingfromPos(tile3)

	if item.uid == 7007 and item.itemid == 1945 then
		doRemoveItem(gettile1.uid,1)
		doRemoveItem(gettile2.uid,1)
		doRemoveItem(gettile3.uid,1)
		doCreateItem(965,1,tile1)
		doCreateItem(965,1,tile2)
		doCreateItem(965,1,tile3)
		doTransformItem(item.uid,item.itemid+1)
	elseif item.uid == 7007 and item.itemid == 1946 then
		doCreateItem(100,1,tile1) --change itemID
		doCreateItem(100,1,tile2) --change itemID
		doCreateItem(100,1,tile3) --change itemID
		doRemoveItem(gettile1.uid,1)
		doRemoveItem(gettile2.uid,1)
		doRemoveItem(gettile3.uid,1)
		doTransformItem(item.uid,item.itemid-1)		
	else
		doPlayerSendCancel(cid,"Sorry, not possible.")
	end

	return 1
end

Would you mind fixing this script up? I think it's a little bit too long...
But I did the best I could.
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end


-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'carpet'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to fly with me?'})
	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 8, cost = 50, destination = {x=100, y=1000, z=7} })
	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then not.'})

keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How should I know where the carpet takes us?'})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

Please tell me what you changed, so I can learn from it.
 
Code:
--Script made by Empty
function onUse(cid, item, frompos, item2, topos)
	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
	gettile1 = getThingfromPos(tile1)
	gettile2 = getThingfromPos(tile2)
	gettile3 = getThingfromPos(tile3)

	if item.uid == 7007 and item.itemid == 1945 then
		doRemoveItem(gettile1.uid,1)
		doRemoveItem(gettile2.uid,1)
		doRemoveItem(gettile3.uid,1)
		doCreateItem(965,1,tile1)
		doCreateItem(965,1,tile2)
		doCreateItem(965,1,tile3)
		doTransformItem(item.uid,item.itemid+1)
	elseif item.uid == 7007 and item.itemid == 1946 then
		doCreateItem(100,1,tile1) --change itemID
		doCreateItem(100,1,tile2) --change itemID
		doCreateItem(100,1,tile3) --change itemID
		doRemoveItem(gettile1.uid,1)
		doRemoveItem(gettile2.uid,1)
		doRemoveItem(gettile3.uid,1)
		doTransformItem(item.uid,item.itemid-1)		
	else
		doPlayerSendCancel(cid,"Sorry, not possible.")
	end

	return 1
end

Would you mind fixing this script up? I think it's a little bit too long...
But I did the best I could.

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

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end


-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'carpet'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to fly with me?'})
	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 8, cost = 50, destination = {x=100, y=1000, z=7} })
	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then not.'})

keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How should I know where the carpet takes us?'})

-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

Please tell me what you changed, so I can learn from it.

Sorry, but I'm not able to optimize NPC's created that way.
 
Code:
---Made by Pablol
function onUse(cid, item, frompos, item2, topos)

	if getPlayerAccess >= 0 then ---keep the access at 0 if you want anyone to be able to do this quest----
        if getPlayerStorageValue(cid,1234) == -1 then
	create_position = {x=xxx, y=xxx, z=x} ---Enter the coords that you want to teleport to appear at----- 
	go_position = {x=xxx, y=xxx, z=x} ---Enter The Coords you want the teleport to the person to----
	doCreateTeleport(1387, go_position, create_position) 
        setPlayerStorageValue(cid,1234,1)
	doPlayerSendTextMessage(cid,22, Message) ---Enter The message you want it to say when the teleport appears----	
	end
	return 1
end
end
end
end
 
Code:
---Made by Pablol
function onUse(cid, item, frompos, item2, topos)

	if getPlayerAccess >= 0 then ---keep the access at 0 if you want anyone to be able to do this quest----
        if getPlayerStorageValue(cid,1234) == -1 then
	create_position = {x=xxx, y=xxx, z=x} ---Enter the coords that you want to teleport to appear at----- 
	go_position = {x=xxx, y=xxx, z=x} ---Enter The Coords you want the teleport to the person to----
	doCreateTeleport(1387, go_position, create_position) 
        setPlayerStorageValue(cid,1234,1)
	doPlayerSendTextMessage(cid,22, Message) ---Enter The message you want it to say when the teleport appears----	
	end
	return 1
end
end
end
end

I only optimize LUA scripts that works.
 
function onSay(cid, words, param)
if words == '!temple' then
if getPlayerStorageValue(target, 1338) == -1 then
local position = {x=1000, y=1000, z=7}
doTeleportThing(cid, position)
end

I saw that u said u only optimize them, but can u give me a hint at least to how to make this script work?
 
Last edited:
Add another end after the last 'end',
and if you're using theforgottenserver change:
doTeleportThing(cid, position)
to:
doTeleportThing(cid, position, TRUE)
 
Status
Not open for further replies.
Back
Top