Action [ULTRA RELEASE] Addon Quest System

Godely

Member
Joined
Aug 19, 2007
Messages
233
Best answers
0
Reaction score
15
Hi guys!

I'll explain it fast cuz I don't have enough time.

Question of the year: why would I use it?
Answer: Well, by creating this function on the lib/actions.lua you'll be able to make really cool quests that when you open the chest/whatever it will send messages like "You need 10 dragon leathers, 50 red pieces of cloth and 20 chicken feather." in case you don't have the required items to get the addon. And these messages are automatic, and by saying that I mean that they will get the IDs of the required items and get their names and send you this message. There are many other features like: if you are a woman, you can change the message given to you (message2) when you get an addon; the addon scripts you need to make will be really shorter; just take a look :)

STEPS:
* Go to actions/lib and open the file actions.lua
* On the end of the file you jump 2 spaces and paste the following code:

Code:
function addonQuest(cid, fromPosition, storageValue, piecePositions, pieceIds, pieceNumbers, outfitIds, message1, message2)
	local playerSex = getPlayerSex(cid)
	local playerPos = getCreaturePosition(cid)
	local numberItems = {}  
	local itemNames = {}
	local pieceStatus = 0

	if getPlayerStorageValue(cid,storageValue) == -1 then
		for i=1, #pieceIds do
			numberItems[i] = getPlayerItemCount(cid, pieceIds[i])
			if pieceNumbers[i] == 1 then
				itemNames[i] = "a " .. getItemNameById(pieceIds[i]) .. ""
			else
				itemNames[i] = "" .. pieceNumbers[i] .. " " .. getItemNameById(pieceIds[i]) .. ""
			end
			if numberItems[i] >= pieceNumbers[i] then
				pieceStatus = pieceStatus + 1
			end
		end
		if pieceStatus == #pieceIds then
			for i=1, #pieceIds do
				doPlayerRemoveItem(cid, pieceIds[i], pieceNumbers[i])
			end
			if message2 == 0 then
				doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message1)
			else
				if playerSex == 1 then
					doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message1)
				else
					doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,message2)
				end
			end
			doPlayerAddOutfit(cid,outfitIds[1],outfitIds[2])
			setPlayerStorageValue(cid,storageValue,1)
			doSendMagicEffect(playerPos, CONST_ME_MAGIC_GREEN)
		else
			if #pieceIds == 1 then
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You must have " .. concat(itemNames, ", ", " and ") .. " with you.")
			else
				doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You must have " .. concat(itemNames, ", ", " and ") .. " with you.")
			end
			return true
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
		return true
	end
    return true
end
ATTENTION: YOU MUST HAVE THE FOLLOWING FUNCTION ON YOUR functions.lua
Code:
function concat(t, f1, f2)
	local str
	local i=1
	local maxv = table.maxv(t) 
	for _, v in pairs(t) do
		if i > 1 then
			if i == maxv then
				str = str..f2..v
			else
				str = str..f1..v
			end
		else
			str = v
		end
		i=i+1
	end
	return str
end
Done. Now, how it works? Well, create a script named "addons.lua", for example. Inside it here is the structure of the file:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.uid == STORAGE1 then
		storageValue = STORAGE1
		pieceIds = {ITEM1,ITEM2,ITEM3,ITEM4}
		pieceNumbers = {ITEM1_COUNT,ITEM2_COUNT,ITEM3_COUNT,ITEM4_COUNT}
		outfitIds = {MALE_OUTFIT_ID,ADDON_NUMBER}
		message1 = "You have found an ANYTHING_ADDON from ANYTHING_OUTFIT."
		message2 = 0
	end
end
THE ITEM1, ITEM2, ITEM3 and ITEM4 are the ids of the items required. The ITEM1_COUNT etc. are the count of those items, in the respective order. The message2 is used in case a female character gets a different message when making the quest. You just need to put the MALE_OUTFIT_ID, because if a player is a female she will automatically get her outfit - in TFS 0.3.5.

Now here is the example of my file that I used to run in my server. I hope it helps :)

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.uid == 2077 then
		storageValue = 2077
		pieceIds = {5882,2195,5947,5881,5875}
		pieceNumbers = {50,1,1,25,1}
		outfitIds = {129,3}
		message1 = "You have found a sniper gloves and a hooded cloak from hunter outfit."
		message2 = "You have found a sniper gloves and a winged tiara from hunter outfit."
	elseif item.uid == 2078 then
		storageValue = 2078
		pieceIds = {5877}
		pieceNumbers = {100}
		outfitIds = {131,1}
		message1 = "You have found a sword from knight outfit."
		message2 = 0
	elseif item.uid == 2079 then
		storageValue = 2079
		pieceIds = {5890,5902}
		pieceNumbers = {50,25}
		outfitIds = {128,2}
		message1 = "You have found a feather hat from citizen outfit."
		message2 = 0
	elseif item.uid == 2080 then
		storageValue = 2080
		pieceIds = {5878}
		pieceNumbers = {50}
		outfitIds = {128,1}
		message1 = "You have found a backpack from citizen outfit."
		message2 = 0
	elseif item.uid == 2081 then
		storageValue = 2081
		pieceIds = {2536,2492,2488,2123}
		pieceNumbers = {1,1,1,1}
		outfitIds = {145,2}
		message1 = "You have found a skull mask from wizard outfit."
		message2 = "You have found a snake tiara from wizard outfit."
	elseif item.uid == 2082 then
		storageValue = 2082
		pieceIds = {2160}
		pieceNumbers = {15}
		outfitIds = {132,1}
		message1 = "You have found a coat from nobleman outfit."
		message2 = "You have found a dress from noblewoman outfit."
	elseif item.uid == 2083 then
		storageValue = 2083
		pieceIds = {2160}
		pieceNumbers = {15}
		outfitIds = {132,2}
		message1 = "You have found a top hat from nobleman outfit."
		message2 = "You have found a hat from noblewoman outfit."
	elseif item.uid == 2084 then
		storageValue = 2084
		pieceIds = {2487,5880}
		pieceNumbers = {1,50}
		outfitIds = {134,2}
		message1 = "You have found a sword from warrior outfit."
		message2 = 0
	elseif item.uid == 2085 then
		storageValue = 2085
		pieceIds = {5880,5893,5876,2429}
		pieceNumbers = {50,25,25,1}
		outfitIds = {143,1}
		message1 = "You have found an axe from barbarian outfit."
		message2 = 0
	elseif item.uid == 2086 then
		storageValue = 2086
		pieceIds = {5897,5896}
		pieceNumbers = {40,25}
		outfitIds = {144,1}
		message1 = "You have found paws from druid outfit."
		message2 = 0
	elseif item.uid == 2087 then
		storageValue = 2087
		pieceIds = {5911,5879,2498}
		pieceNumbers = {25,50,1}
		outfitIds = {143,2}
		message1 = "You have found a barbarian wig from barbarian outfit."
		message2 = 0
	elseif item.uid == 2089 then
		storageValue = 2089
		pieceIds = {5948,5911}
		pieceNumbers = {100,50}
		outfitIds = {133,2}
		message1 = "You have found a cloak from summoner outfit."
		message2 = "You have found a tiara from mage outfit."
	elseif item.uid == 2090 then
		storageValue = 2090
		pieceIds = {5954,5930}
		pieceNumbers = {25,50}
		outfitIds = {131,2}
		message1 = "You have found a horned helmet from knight outfit."
		message2 = "You have found an adorned helmet from knight outfit."
	elseif item.uid == 2092 then
		storageValue = 2092
		pieceIds = {5903}
		pieceNumbers = {1}
		outfitIds = {130,2}
		message1 = "You have found the ferumbras' hat from the mage outfit."
		message2 = "You have found the ferumbras' hat from the summoner outfit."
	elseif item.uid == 2093 then
		storageValue = 2093
		pieceIds = {5922}
		pieceNumbers = {30}
		outfitIds = {145,1}
		message1 = "You have found a skull shoulder pad from wizard outfit."
		message2 = "You have found wings from wizard outfit."
	elseif item.uid == 2094 then
		storageValue = 2094
		pieceIds = {5893,5894,5913,5914}
		pieceNumbers = {20,30,50,20}
		outfitIds = {134,1}
		message1 = "You have found a shoulder spike from warrior outfit."
		message2 = 0
	elseif item.uid == 2095 then
		storageValue = 2095
		pieceIds = {2663,2160,5912}
		pieceNumbers = {1,5,25}
		outfitIds = {146,2}
		message1 = "You have found a turban from oriental outfit."
		message2 = "You have found a veil from oriental outfit."
	elseif item.uid == 2096 then
		storageValue = 2096
		pieceIds = {5909,5914,5902,5894}
		pieceNumbers = {20,20,30,25}
		outfitIds = {144,2}
		message1 = "You have found an animal fur from druid outfit."
		message2 = 0
	elseif item.uid == 2097 then
		storageValue = 2097
		pieceIds = {5945}
		pieceNumbers = {1}
		outfitIds = {146,1}
		message1 = "You have found a scimitar from oriental outfit."
		message2 = "You have found a jewelled belt from oriental outfit."
	end
	return addonQuest(cid, fromPosition, storageValue, piecePositions, pieceIds, pieceNumbers, outfitIds, message1, message2)
end
And on actions.xml:
Code:
<action uniqueid="2077-2087;2089-2090;2092-2097" script="quests/addons.lua" />
Have fun guys!
And rep++ if you like =)
 
Last edited:
OP
Godely

Godely

Member
Joined
Aug 19, 2007
Messages
233
Best answers
0
Reaction score
15
I just updated with more info
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
I wouldn't call it 'ultra release' because the script still has flaws, but it's okay.

Code:
function addonQuest(cid, fromPosition, storageValue, piecePositions, pieceIds, pieceNumbers, outfitIds, message1, message2)
	if getPlayerStorageValue(cid, storageValue) < 1 then
		local numberItems, itemNames, pieceStatus = {}, {}, 0
		for i = 1, #pieceIds do
			numberItems[i], itemNames[i] = getPlayerItemCount(cid, pieceIds[i]), pieceNumbers[i] == 1 and "a " .. getItemNameById(pieceIds[i]) or pieceNumbers[i] .. " " .. getItemNameById(pieceIds[i])
			pieceStatus = pieceStatus + (numberItems[i] >= pieceNumbers[i] and 1 or 0)
		end
		if pieceStatus == #pieceIds then
			for i = 1, #pieceIds do
				doPlayerRemoveItem(cid, pieceIds[i], pieceNumbers[i])
			end
			doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, message == 0 or getPlayerSex(cid) == 1 and message1 or message2)
			doPlayerAddOutfit(cid,outfitIds[1], outfitIds[2])
			setPlayerStorageValue(cid, storageValue, 1)
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You must have " .. concat(itemNames, ", ", " and ") .. " with you.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
	end
    return true
end
Code:
function concat(t, f1, f2)
	local str, maxn = "", table.maxv(t) 
	for i = 1, #t do
		str = i > 1 and str..(i == maxv and f2 or f1)..t[i] or t[i]
	end
	return str
end
 
Last edited:
OP
Godely

Godely

Member
Joined
Aug 19, 2007
Messages
233
Best answers
0
Reaction score
15
Cykotitan, I don't mind about you trying to make it shorter - it seems that every single scripter in otland or otfans tries to do that - but that doesn't mean I'll change my main post. My work is shown up there, and your work seems to be also here, so anyone can decide which script to use.

After all, I never heard that a little-bit-longer script can be considered as a fail, or am I wrong?

Thanks.
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
Cykotitan, I don't mind about you trying to make it shorter - it seems that every single scripter in otland or otfans tries to do that - but that doesn't mean I'll change my main post. My work is shown up there, and your work seems to be also here, so anyone can decide which script to use.

After all, I never heard that a little-bit-longer script can be considered as a fail, or am I wrong?

Thanks.
Your script doesn't have anything that could slow it down (under normal circumstances), which means that my script would only probably be 0.00000001 faster.
 
Last edited:
Top