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

Action TFS 0.2/1.0 system.lua (Questsystem)

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,013
Solutions
8
Reaction score
3,055
Location
Netherlands
divider_i_by_rbsrdesigns-d353f7e.png

TFS 0.2/1.0 system.lua

Chest.gif

Tested with TFS 0.2.13, TFS 0.2.14, TFS 0.2.15 and TFS 1.0


I've been posting this script already since 2012, but since there is still a huge amount of support threads about it I decided to make a thread.
All credits go to the maker of the TFS 0.3 system.lua, I only edited it to make it work for TFS 0.2/1.0, fixed some bugs and added that people get a different textmessage when the item is to heavy or when they don't have enough space.​



How does it work:
This is the questsytem script from TFS 0.3/0.4 where you have to add actionid 2000, an uniqueid for the storage and the items in the chest.
NiBJKJ.png

If players use the chest, they will get the items you added in the chest one time with a message which items they got, after that they will get a message that it's empty.
http://otland.net/f479/how-quests-148708/


actions.xml
Code:
<action actionid="2000" script="quests/system.lua"/>


system.lua
Code:
local specialQuests = {
   [2001] = 30015 --Annihilator
}

local questsExperience = {
   [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     local storage = specialQuests[item.actionid]
     if(not storage) then
         storage = item.uid
             if(storage > 65535) then
             return false
         end
     end

     if(getPlayerStorageValue(cid, storage) > 0) then
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
         return true
     end

     local items = {}
     local reward = 0

     local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
     if(size == 0) then
         reward = doCopyItem(item, false)
     else
         for i = 0, size do
             local tmp = getContainerItem(item.uid, i)
             if(tmp.itemid > 0) then
                 table.insert(items, tmp)
             end
         end
     end

     size = table.maxn(items)
     if(size == 1) then
         reward = doCopyItem(items[1], true)
     end

     local result = ""
     if(reward ~= 0) then
         local ret = getItemDescriptions(reward.itemid)
         if(reward.type > 0 and isItemRune(reward.itemid)) then
             result = reward.type .. " charges " .. ret.name
         elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
             result = reward.type .. " " .. ret.plural
         else
             result = ret.article .. " " .. ret.name
         end
     else
         if(size > 20) then
             reward = doCopyItem(item, false)
         elseif(size > 8) then
             reward = getThing(doCreateItemEx(1988, 1))
         else
             reward = getThing(doCreateItemEx(1987, 1))
         end
         for i = 1, size do
             local tmp = doCopyItem(items[i], true)
             if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
                 print("[Warning] QuestSystem:", "Could not add quest reward")
             else
                 local ret = ", "
                 if(i == 1) then
                     ret = ""
                 elseif(i == size) then
                     ret = " and "
                 end
                 result = result .. ret
                 ret = getItemDescriptions(tmp.itemid)
                 if(tmp.type > 0 and isItemRune(tmp.itemid)) then
                     result = result .. tmp.type .. " charges " .. ret.name
                 elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
                     result = result .. tmp.type .. " " .. ret.plural
                 else
                     result = result .. ret.article .. " " .. ret.name
                 end
             end
         end
     end

     if getPlayerFreeCap(cid) < getItemWeightByUID(reward.uid) then
         result = "You have found a reward weighing "..getItemWeightByUID(reward.uid).." oz. It is to heavy."
     elseif(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
         result = "You have found a reward, but you don't have enough space."
     else
         result = "You have found " .. result .. "."
         setPlayerStorageValue(cid, storage, 1)
         if(questsExperience[storage] ~= nil) then
             doPlayerAddExp(cid, questsExperience[storage])
         end
     end

     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
     return true
end


Also remove this if you want to use those chests for the system.lua
Code:
<action itemid="1740" script="quests/quests.lua"/>
<action fromid="1747" toid="1749" script="quests/quests.lua"/>

If you use TFS 1.0, add this in global.lua
Code:
function doCopyItem(item, attributes)
     local attributes = attributes or false

     local ret = doCreateItemEx(item.itemid, item.type)
     if(attributes) then
         if(item.actionid > 0) then
             doSetItemActionId(ret, item.actionid)
         end
     end

     if(isContainer(item.uid) == TRUE) then
         for i = (getContainerSize(item.uid) - 1), 0, -1 do
             local tmp = getContainerItem(item.uid, i)
             if(tmp.itemid > 0) then
                 doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
             end
         end
     end
     return getThing(ret)
end
 
Last edited:
Thanks Limos, i know this was much needed for people using mystic spirit. I have some friends i can refer to this thread who were having problems with their system.lua.
 
Last edited:
Hi im probly just dumb but the system.lua that file doesnt i have i guess its suppossed to be at data/actions/scripts/-""- but i got annihlator and the quest file should i just add it in the quest file or remove all in the existing and just have the new code?

btw first time ever im doing an ot :p

kind regards
Friherren
 
You can add it to the folder quests as new lua files called system (you can also add it to an other folder or use a different lua file name, but then you have to change quests and system in the xml line).
You don't have to remove anything. Only if you want to use the chests with id 1740 and 1747 till 1749 for the system.lua then you have to remove these lines from actions.xml.
XML:
<action itemid="1740" script="quests/quests.lua"/>
<action fromid="1747" toid="1749" script="quests/quests.lua"/>
 
Last edited:
i don't quite get what this means, is this guide for the annihilator quest or is this how you make chests work for any quest, because i made my own quest with 3 chests, i want the players to be able to take all 3 items but when one person opens the chest and takes the items another person cant get an item from the chest i dont quite understand how to set it up this way can you explain maybe abit easier for me please :S

- - - Updated - - -

for instance when i goto data/actions i have three options lib/scripts/actions.xml when i click on scripts it says other/quests/tools
when i click on quests it says annihilator/quests i don't see anything about system :S
 
You have to add the script in folder quests, then add the line in actions.xml.
TFS 0.3 and 0.4 have this script by default, TFS 0.2 hasn't and it needed some edits to make it work for TFS 0.2.
 
Last edited:
From a request.
Version with cap and space message separated.
Lua:
local specialQuests = {
	[2001] = 30015 --Annihilator
}
 
local questsExperience = {
	[30015] = 10000
}
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
	local storage = specialQuests[item.actionid]
	if(not storage) then
		storage = item.uid
		if(storage > 65535) then
			return false
		end
	end
 
	if(getPlayerStorageValue(cid, storage) > 0) then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
		return true
	end
 
	local items = {}
	local reward = 0
 
	local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
	if(size == 0) then
		reward = doCopyItem(item, false)
	else
		for i = 0, size do
			local tmp = getContainerItem(item.uid, i)
			if(tmp.itemid > 0) then
				table.insert(items, tmp)
			end
		end
	end
 
	size = table.maxn(items)
	if(size == 1) then
		reward = doCopyItem(items[1], true)
	end
 
	local result = ""
	if(reward ~= 0) then
		local ret = getItemDescriptions(reward.itemid)
		if(reward.type > 0 and isItemRune(reward.itemid)) then
			result = reward.type .. " charges " .. ret.name
		elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
			result = reward.type .. " " .. ret.plural
		else
			result = ret.article .. " " .. ret.name
		end
	else
		if(size > 20) then
			reward = doCopyItem(item, false)
		elseif(size > 8) then
			reward = getThing(doCreateItemEx(1988, 1))
		else
			reward = getThing(doCreateItemEx(1987, 1))
		end
 
		for i = 1, size do
			local tmp = doCopyItem(items[i], true)
			if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
				print("[Warning] QuestSystem:", "Could not add quest reward")
			else
				local ret = ", "
				if(i == 2) then
					ret = " and "
				elseif(i == 1) then
					ret = ""
				end
 
				result = result .. ret
				ret = getItemDescriptions(tmp.itemid)
				if(tmp.type > 0 and isItemRune(tmp.itemid)) then
					result = result .. tmp.type .. " charges " .. ret.name
				elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
					result = result .. tmp.type .. " " .. ret.plural
				else
					result = result .. ret.article .. " " .. ret.name
				end
			end
		end
	end
 
	if getPlayerFreeCap(cid) < getItemWeightByUID(reward.uid) then
		result = "You have found a reward weighing "..getItemWeightByUID(reward.uid).." oz. It is to heavy."
	elseif(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
		result = "You have found a reward, but you don't have enough space."
	else
		result = "You have found " .. result .. "."
		setPlayerStorageValue(cid, storage, 1)
		if(questsExperience[storage] ~= nil) then
			doPlayerAddExp(cid, questsExperience[storage])
		end
	end
 
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
	return true
end

Example:
Not enough cap: You have found a reward weighing 80 oz. It is to heavy.
Not enough space: You have found a reward, but you don't have enough space.
 
Last edited:
Useful I'll change mine for yours to test it and report bugs, in case you don't know what to do potions.lua is also shitty in 0.2, I wouldn't post mine because honestly I just changed some function names and is not 100% tested so I don't want shitty code all around
 
Not working Mystic Spirit 9.8

[C]: in function '__lt'
[06/10/2013 16:25:58] data/global.lua:970: in function 'doCopyItem'
[06/10/2013 16:25:58] data/actions/scripts/quests/system.lua:63: in function <data/actions/scripts/quests/system.lua:8>
 
Try looking in the folder Doc and under LUA_FUNCTIONS maybe there is somthing there that looks similar to doCopyItem
 
there is no function

this insted will fit ?
doPlayerAddItem
 
Code:
[07/10/2013 04:51:35] Lua Script Error: [Action Interface]
[07/10/2013 04:51:35] data/actions/scripts/quests/system.lua:onUse
[07/10/2013 04:51:35] data/global.lua:970: attempt to compare number with nil
[07/10/2013 04:51:35] stack traceback:
[07/10/2013 04:51:35]    [C]: in function '__lt'
[07/10/2013 04:51:35]    data/global.lua:970: in function 'doCopyItem'
[07/10/2013 04:51:35]    data/actions/scripts/quests/system.lua:64: in function <data/actions/scripts/quests/system.lua:9>
 
How did you added it?
It's also tested on TFS 0.2.15 (Mystic Spirit) client 9.8-9.86

Newer version with item result message fix when there are 3+ items in the chest.
I will update the rest when the Lua tags are back
Code:
local specialQuests = {
   [2001] = 30015 --Annihilator
}

local questsExperience = {
   [30015] = 10000
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

   local storage = specialQuests[item.actionid]
   if(not storage) then
     storage = item.uid
     if(storage > 65535) then
       return false
     end
   end

   if(getPlayerStorageValue(cid, storage) > 0) then
     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
     return true
   end

   local items = {}
   local reward = 0

   local size = isContainer(item.uid) and getContainerSize(item.uid) or 0
   if(size == 0) then
     reward = doCopyItem(item, false)
   else
     for i = 0, size do
       local tmp = getContainerItem(item.uid, i)
       if(tmp.itemid > 0) then
         table.insert(items, tmp)
       end
     end
   end

   size = table.maxn(items)
   if(size == 1) then
     reward = doCopyItem(items[1], true)
   end

   local result = ""
   if(reward ~= 0) then
     local ret = getItemDescriptions(reward.itemid)
     if(reward.type > 0 and isItemRune(reward.itemid)) then
       result = reward.type .. " charges " .. ret.name
     elseif(reward.type > 0 and isItemStackable(reward.itemid)) then
       result = reward.type .. " " .. ret.plural
     else
       result = ret.article .. " " .. ret.name
     end
   else
     if(size > 20) then
       reward = doCopyItem(item, false)
     elseif(size > 8) then
       reward = getThing(doCreateItemEx(1988, 1))
     else
       reward = getThing(doCreateItemEx(1987, 1))
     end

     for i = 1, size do
       local tmp = doCopyItem(items[i], true)
       if(doAddContainerItemEx(reward.uid, tmp.uid) ~= RETURNVALUE_NOERROR) then
         print("[Warning] QuestSystem:", "Could not add quest reward")
       else
         local ret = ", "
         if(i == 1) then
           ret = ""
         elseif(i == size) then
           ret = " and "
         end

         result = result .. ret
         ret = getItemDescriptions(tmp.itemid)
         if(tmp.type > 0 and isItemRune(tmp.itemid)) then
           result = result .. tmp.type .. " charges " .. ret.name
         elseif(tmp.type > 0 and isItemStackable(tmp.itemid)) then
           result = result .. tmp.type .. " " .. ret.plural
         else
           result = result .. ret.article .. " " .. ret.name
         end
       end
     end
   end

   if(doPlayerAddItemEx(cid, reward.uid, false) ~= RETURNVALUE_NOERROR) then
     result = "You have found a reward weighing " .. getItemWeightByUID(reward.uid) .. " oz. It is too heavy or you have not enough space."
   else
     result = "You have found " .. result .. "."
     setPlayerStorageValue(cid, storage, 1)
     if(questsExperience[storage] ~= nil) then
       doPlayerAddExp(cid, questsExperience[storage])
     end
   end

   doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, result)
   return true
end
 
I aint got the copy item func I think
Added like this -

<action itemid="1740" script="quests/quests.lua"/> -- kept this chest for other quest system
<action actionid="2000" script="quests/system.lua"/>
<action fromaid="2001" toaid="2006" script="quests/system.lua"/>


And in chests I did uniqeId -60000+
and action 2000

But now that Im writing this down I guess something is wrong in the actions right?
 
I tested it on TFS 0.2.15 (Mystic Spirit) client 9.8-9.86, this is the server you are using right?
And do you use the script from this thread?
Because you don't need to add this.
Code:
<action fromaid="2001" toaid="2006" script="quests/system.lua"/>

You can add 2001 if you are going to use it, this is for pick only one item from more chests, like annihilator chests.
If you want to add more, you can look here.
http://otland.net/threads/how-to-quests.148708/

Btw, if you keep this line
Code:
<action itemid="1740" script="quests/quests.lua"/>
Then you can't use the chest with id 1740 for the system.lua.
 
Last edited:
Yeah the script is from this thread and Im using this server.

Ok deleting it and testing


Btw, if you keep this line
Code:
<action itemid="1740" script="quests/quests.lua"/>
Then you can't use the chest with id 1740 for the system.lua.
Yeah I know I added it by what you posted :)
 
Again

Code:
[07/10/2013 21:40:25]    [C]: in function 'doCreateItemEx'
[07/10/2013 21:40:25]    data/global.lua:968: in function 'doCopyItem'
[07/10/2013 21:40:25]    data/actions/scripts/quests/system.lua:64: in function <data/actions/scripts/quests/system.lua:9>

[07/10/2013 21:40:25] Lua Script Error: [Action Interface]
[07/10/2013 21:40:25] data/actions/scripts/quests/system.lua:onUse
[07/10/2013 21:40:25] data/global.lua:970: attempt to compare number with nil
[07/10/2013 21:40:25] stack traceback:
[07/10/2013 21:40:25]    [C]: in function '__lt'
[07/10/2013 21:40:25]    data/global.lua:970: in function 'doCopyItem'
[07/10/2013 21:40:25]    data/actions/scripts/quests/system.lua:64: in function <data/actions/scripts/quests/system.lua:9>
 
2hyzypd.jpg






Seems the function in global is diffrent maybe?
7rr8.jpg
 
Last edited:
Looks the same
Code:
function doCopyItem(item, attributes)
   local attributes = attributes or false

   local ret = doCreateItemEx(item.itemid, item.type)
   if(attributes) then
     if(item.actionid > 0) then
       doSetItemActionId(ret, item.actionid)
     end
   end

   if(isContainer(item.uid) == TRUE) then
     for i = (getContainerSize(item.uid) - 1), 0, -1 do
       local tmp = getContainerItem(item.uid, i)
       if(tmp.itemid > 0) then
         doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
       end
     end
   end

   return getThing(ret)
end

Did you changed someting after you downloaded the server? for example in global.lua.
Because it works with the server files you get when you download the server.

Btw, are you sure the itemid, actionid or uniqueid is not used by an other action script?
 
Last edited:
Back
Top