Godely
Member
- Joined
- Aug 19, 2007
- Messages
- 233
- Reaction score
- 16
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:
ATTENTION: YOU MUST HAVE THE FOLLOWING FUNCTION ON YOUR functions.lua
Done. Now, how it works? Well, create a script named "addons.lua", for example. Inside it here is the structure of the file:
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
And on actions.xml:
Have fun guys!
And rep++ if you like =)
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
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" />
And rep++ if you like =)
Last edited: