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

4 switches, trigger something

Evan

A splendid one to behold
Senator
Premium User
Joined
May 6, 2009
Messages
7,018
Solutions
1
Reaction score
1,040
Location
United States
Is it possible to have four switches pulled in different times to remove a piece of wall?
For example, there is a switch in each of four rooms. You pull the one, then move to the next room, pull that and so on until all 4 rooms are pulled.
After they are all pulled, a wall will be deleted. Is something like this possible?

I just don't have a plan on how it works, it's been awhile since I did some good scripting.

Thanks
 
bump

is it possible that we can use global storage?
when a switch is pulled, it sets a global storage and checks of the 3 other exist, if not, then move on to the next switch until it checks that all 3 storages exist?
 
Mmm.....
You can do it with 1 storage....
But i recommend this to you:
If you want it to all players for a certain time, then use global Storage and remove wall...
But if you want it to only one player, use a personal storage, and a door.... xD
 
Code:
<action uniqueid="[b][COLOR="red"]1234;5678;9001;4321[/COLOR][/b]" event="script" value="[COLOR="orange"][B]scriptname.lua[/B][/COLOR]" />

Code:
local t, i, p = { [b][COLOR="red"]1234, 5678, 9001, 4321[/COLOR][/b] }, [COLOR="orange"]WALLID[/COLOR], Position([B][COLOR="orange"]WALLPOSX[/COLOR][/B], [B][COLOR="orange"]WALLPOSY[/COLOR][/B], [COLOR="orange"][B]WALLPOSZ[/B][/COLOR])

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if not isInArray(t, item.uid) or item.itemid ~= 1945 then
		return true
	end

	doTransformItem(item.uid, 1946)
	local ret = 0
	for _, v in pairs(t) do
		local switch = getThing(v)
		if switch.uid ~= 0 and switch.itemid == 1946 then
			ret = ret + 1
		end
	end

	if ret == #t then
		local wall = getTileItemById(p, i).uid
		if wall ~= 0 then
			doRemoveItem(wall)
		end
	end
	return true
end

- Unieque IDs of switches.
- Hope you understand those :p.

@Sidenote:
It's gonna work probably only at TFS 0.4.
 
Last edited:
Code:
local t, i, p = { [b][COLOR="red"]1234, 5678, 9001, 4321[/COLOR][/b] }, [COLOR="orange"]WALLID[/COLOR], { Position([B][COLOR="orange"]WALLPOSX1[/COLOR][/B], [B][COLOR="orange"]WALLPOSY1[/COLOR][/B], [COLOR="orange"][B]WALLPOSZ1[/B][/COLOR]),  Position([B][COLOR="orange"]WALLPOSX2[/COLOR][/B], [B][COLOR="orange"]WALLPOSY2[/COLOR][/B], [COLOR="orange"][B]WALLPOSZ2[/B][/COLOR]) }

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if not isInArray(t, item.uid) or item.itemid ~= 1945 then
		return true
	end

	doTransformItem(item.uid, 1946)
	local ret = 0
	for _, v in pairs(t) do
		local switch = getThing(v)
		if switch.uid ~= 0 and switch.itemid == 1946 then
			ret = ret + 1
		end
	end

	if ret == #t then
		for _, wp in pairs(p) do
			local wall = getTileItemById(wp, i).uid
			if wall ~= 0 then
				doRemoveItem(wall)
			end
		end
	end
	return true
end

Also I was told it should work on 0.2, 0.3 and 0.4.
 
Works like a charm, Derek.
Now, I forgot to mention a couple things that I also needed.

I wanted the gate to come back and the switches to all reset at the same time after 3 seconds.

I got the gates to come back, but the switches don't reset.
I knew it was not going to work and the error was expected, but the way you wrote the code, I can't seem to figure out what you defined the switches as.

Here's what I have so far now:
PHP:
local t, i, p = {23100, 23101, 23102, 23103}, 1547, { Position(764, 888, 11),  Position(765, 888, 11) }

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if not isInArray(t, item.uid) or item.itemid ~= 1945 then
		return true
	end
	doSendMagicEffect(fromPosition, 14)
	doTransformItem(item.uid, 1946)
	local ret = 0
	for _, v in pairs(t) do
		local switch = getThing(v)
		if switch.uid ~= 0 and switch.itemid == 1946 then
			ret = ret + 1
		end
	end

	if ret == #t then
		for _, wp in pairs(p) do
			local wall = getTileItemById(wp, i).uid
			if wall ~= 0 then
				doRemoveItem(wall)
				doSendMagicEffect(fromPosition, 2)
				addEvent(createWallEntr, 3 * 1000)
			end
		end
	end
	return true
end

function createWallEntr()
    doCreateItem(1547, {x=765, y=888, z=11}) 
	doCreateItem(1547, {x=764, y=888, z=11}) 
    doSendMagicEffect({x=765, y=888, z=11}, 3)		
    doSendMagicEffect({x=764, y=888, z=11}, 3)
	doTransformItem(switch, 1945)
end

Here is the error:
[20:17:13.212] [Error - Action Interface]
[20:17:13.213] In a timer event called from:
[20:17:13.219] data/actions/scripts/quests/hellgateentrance.lua:onUse
[20:17:13.222] Description:
[20:17:13.225] (luaDoTransformItem) Item not found

[20:17:13.228] [Error - Action Interface]
[20:17:13.229] In a timer event called from:
[20:17:13.232] data/actions/scripts/quests/hellgateentrance.lua:onUse
[20:17:13.234] Description:
[20:17:13.235] (luaDoTransformItem) Item not found
 
LUA:
local walls = {
	{x=764, y=888, z=11},
	{x=765, y=888, z=11}
}

local function reset()
	for i = 1, #walls do
		doCreateItem(1547, 1, walls[i])
		doSendMagicEffect(walls[i], 3)
	end
	for i = 23100, 23103 do
		doTransformItem(i, 1945)
	end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1946 then
		return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
	end

	doSendMagicEffect(fromPosition, 14)
	doTransformItem(item.uid, 1946)

	for i = 23100, 23103 do
		if i ~= item.uid and getThing(i).itemid == 1945 then
			return true
		end
	end

	for i = 1, #walls do
		doRemoveItem(getTileItemById(walls[i], 1547).uid)
		doSendMagicEffect(walls[i], 2)
	end
	addEvent(reset, 3000)
	return true
end
will be fail
 
Lol, what are you talking about being fail?
It works like a charm.

You must spread some Reputation around before giving it to Cykotitan again.
Also gave rep to Derek for initially working.
 
Back
Top