Action Desert Quest Switch

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
I don't know why, but when i saw this thread: http://otland.net/f81/might-good-someone-desert-quest-easy-configure-48895/. I decide to write my own, maybe i don't like Ezzam's code (no loops etc.) xD

Code is untested but shuold work:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	-- Positions/ID's/Vocations order: paladin, sorcerer, knight, druid.
	local positions = {
		players = {
			{x = 100, y = 100, z = 7, stackpos = 253},
			{x = 100, y = 100, z = 7, stackpos = 253},
			{x = 100, y = 100, z = 7, stackpos = 253},
			{x = 100, y = 100, z = 7, stackpos = 253}
		}
		items = {
			{x = 100, y = 100, z = 7, stackpos = 2},
			{x = 100, y = 100, z = 7, stackpos = 2},
			{x = 100, y = 100, z = 7, stackpos = 2},
			{x = 100, y = 100, z = 7, stackpos = 2}
		}
		new = {
			{x = 100, y = 100, z = 7},
			{x = 100, y = 100, z = 7},
			{x = 100, y = 100, z = 7},
			{x = 100, y = 100, z = 7}
		}
	}

	local vocations = {3, 1, 4, 2}
	local items = {2455, 2376, 2674, 2175}

	-- don't touch below.
	local check = {
		players = true,
		vocations = true,
		items = true
	}

	if (item.itemid == 1945) then
		for i = 1, 4 do
			if (not isPlayer(getThingFromPos(positions.players[i]).uid)) then
				doPlayerSendCancel(cid, "You need 4 players.")
				check.players = false
				break
			end
		end
		for i = 1, 4 do
			if (getPlayerVocation(getThingFromPos(positions.players[i]).uid) ~= vocations[i]) then
				doPlayerSendCancel(cid, "Wrong vocations.")
				check.vocations = false
				break
			end
		end
		for i = 1, 4 do
			if (getThingFromPos(positions.items[i]).itemid ~= items[i]) then
				doPlayerSendCancel(cid, "Wrong items.")
				check.items = false
				break
			end
		end
		if (check.players and check.vocations and check.items) then
			for i = 1, 4 do
				doTeleportThing(getThingFromPos(positions.players[i]).uid, positions.new[i])
				doSendMagicEffect(positions.players[i], CONST_ME_POFF)
				doSendMagicEffect(positions.new[i], CONST_ME_TELEPORT)
				doTransformItem(item.uid, item.itemid + 1)
			end
		end
	elseif (item.itemid == 1946) then
		doTransformItem(item.uid, item.itemid - 1)
	end

	return TRUE
end
 
Last edited:

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Best answers
0
Reaction score
12
Location
Poland
Good, much better than Ezzam's one :thumbup:
 

frankfarmer

who'r ninja now
Joined
Aug 5, 2008
Messages
1,472
Best answers
0
Reaction score
30
Location
swe?
Code:
<action uniqueid="xxxx" event="script" value="desert.lua"/>
Where xxxx is unique ID of your switch.




Mistaken :p


Also code is outdated a bit. p;
You don't think it can work?
 
OP
chojrak

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
You have to test it and pos result here, I will fix it ;p
 
OP
chojrak

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
Code:
for xx = y, zzz do
xd()
end
Code:
while xxxx do
xd()
end
Code:
repeat
xd()
until xxx
Loops :d
 

frankfarmer

who'r ninja now
Joined
Aug 5, 2008
Messages
1,472
Best answers
0
Reaction score
30
Location
swe?
Can you edit the first post? And make it none-loop?:p
 
OP
chojrak

chojrak

Banned User
Joined
Oct 25, 2008
Messages
5,832
Best answers
2
Reaction score
158
Lol, non-loop version will give lot of useless code. >.<
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
But why loop so many times? It can be shortened.
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
Not tested.
Code:
-- Positions/IDs/Vocations order: paladin, sorcerer, knight, druid.
local positions = {
	players = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	}[COLOR="Red"],[/COLOR]
	items = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	}[COLOR="red"],[/COLOR]
	new = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	}
}

local vocations = {3, 1, 4, 2}
local items = {2455, 2376, 2674, 2175}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(item.itemid == 1945) then
		for i = 1, 4 do
			local failed = true
			if (not isPlayer(getThingFromPos(positions.players[i]).uid)) then
				doPlayerSendCancel(cid, "You need 4 players.")
				break
			elseif (getPlayerVocation(getThingFromPos(positions.players[i]).uid) ~= vocations[i]) then
				doPlayerSendCancel(cid, "Wrong vocations.")
				break
			elseif (getTileItemById(positions.items[i], items[i]).uid == 0) then
				doPlayerSendCancel(cid, "Wrong items.")
				break
			else
				failed = false
			end
		end
		if(not failed) then
			for i = 1, 4 do
				[COLOR="Red"][B]doRemoveItem(getTileItemById(positions.items[i], items[i]).uid)[/B][/COLOR]
				doTeleportThing(getTopCreature(positions.players[i]).uid, positions.new[i])
				doSendMagicEffect(positions.players[i], CONST_ME_POFF)
				doSendMagicEffect(positions.new[i], CONST_ME_TELEPORT)
				doTransformItem(item.uid, item.itemid + 1)
			end
		end
	elseif(item.itemid == 1946) then
		doTransformItem(item.uid, item.itemid - 1)
	end
	return TRUE
end
 
Last edited:

frankfarmer

who'r ninja now
Joined
Aug 5, 2008
Messages
1,472
Best answers
0
Reaction score
30
Location
swe?
Not tested.
Code:
-- Positions/IDs/Vocations order: paladin, sorcerer, knight, druid.
local positions = {
	players = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	},
	items = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	},
	new = {
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7},
		{x = 100, y = 100, z = 7}
	}
}

local vocations = {3, 1, 4, 2}
local items = {2455, 2376, 2674, 2175}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(item.itemid == 1945) then
		for i = 1, 4 do
			local failed = true
			if (not isPlayer(getThingFromPos(positions.players[i]).uid)) then
				doPlayerSendCancel(cid, "You need 4 players.")
				break
			elseif (getPlayerVocation(getThingFromPos(positions.players[i]).uid) ~= vocations[i]) then
				doPlayerSendCancel(cid, "Wrong vocations.")
				break
			elseif (getTileItemById(positions.items[i], items[i]).uid == 0) then
				doPlayerSendCancel(cid, "Wrong items.")
				break
			else
				failed = false
			end
		end
		if(not failed) then
			for i = 1, 4 do
				doTeleportThing(getTopCreature(positions.players[i]).uid, positions.new[i])
				doSendMagicEffect(positions.players[i], CONST_ME_POFF)
				doSendMagicEffect(positions.new[i], CONST_ME_TELEPORT)
				doTransformItem(item.uid, item.itemid + 1)
			end
		end
	elseif(item.itemid == 1946) then
		doTransformItem(item.uid, item.itemid - 1)
	end
	return TRUE
end
I will test it now on 0.3.5 pl1

EDIT: No errors while reloading, gonna test the quest now after restart.
 
Top