[go: up one dir, main page]

0% found this document useful (0 votes)
47 views5 pages

Advanced Quest System - Lua

The document outlines an advanced reward system for a game, detailing how rewards are structured and managed through various functions. It includes information on item types, weight calculations, and storage checks, as well as messaging configurations for player interactions. The code is designed to handle item rewards, including containers and stackable items, while ensuring players receive appropriate messages based on their actions.

Uploaded by

joanoc1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Advanced Quest System - Lua

The document outlines an advanced reward system for a game, detailing how rewards are structured and managed through various functions. It includes information on item types, weight calculations, and storage checks, as well as messaging configurations for player interactions. The code is designed to handle item rewards, including containers and stackable items, while ensuring players receive appropriate messages based on their actions.

Uploaded by

joanoc1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

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

--[[
###################### ADVANCED REWARD SYSTEM VERSION 1.0 BY: MIKII
######################
***********************************************************************************
*************************************
############################# http://otland.net/members/mikii.179336/
##################################
***********************************************************************************
*************************************
***********************************************************************************
*************************************

INFO REWARD VARS:


************************************
reward._type: 1 = Normal Item
reward._type: 2 = Rune
reward._type: 3 = Stackable
reward._type: 4 = Container
************************************
reward._inside: 0 = NOT INSIDE CONTAINER
reward._inside: 1 = INSIDE CONTAINER

OBS: DON'T WORK IF YOU INPUT ITEMS ON CONTAINER INSIDE ANOTHER CONTAINER
BUT WILL WORK IF YOU PUT SEVERAL ITEMS WITH CONTAINERS SEPARATELY.
**********************************
reward._amount = amount of itens Runes or Stackable or Normal = 1
**********************************
reward._weight = weight of itens

###################### ADVANCED REWARD SYSTEM VERSION 1.0 BY: MIKII


######################
***********************************************************************************
*************************************
############################# http://otland.net/members/mikii.179336/
##################################
***********************************************************************************
*************************************
***********************************************************************************
*************************************
BUGS OR UPDATES CHECK
THIS THREAD
***********************************************************************************
*************************************
]]

MSGMODE = 1
MSGADVANCEDGMODE = 1
local msg_config = {
_msg_empty_type = {
[1] = 'The chest is empty.',
-- Set 1 on MSGMODE
[2] = 'The corpse is empty.',
-- Set 2 on MSGMODE
[3] = 'It is empty.' -- Set 3
on MSGMODE
},

_msgadvance = {
[1] = MESSAGE_EVENT_ADVANCE,
-- Set 1 on MSGADVANCEDGMODE
[2] = MESSAGE_INFO_DESCR, --
Set 2 on MSGADVANCEDGMODE
[3] =
MESSAGE_STATUS_CONSOLE_BLUE -- Set 3 on MSGADVANCEDGMODE
}
}

--###########################--
--## WARNING DON'T EDIT THIS ##
--###########################--
local reward = {
_itemid = {},
_amount = {},
_weight = {},
_type = {},
_inside = {}
}
--###########################--
--## WARNING DON'T EDIT THIS ##
--###########################--

--############################ FUNCTION CHECK ITENS ON CONTAINER


###############################--

local size = isContainer(item.uid) and getContainerSize(item.uid) or 0

if(size > 0) then


for i = 0, size do
local tmp = getContainerItem(item.uid, i)
if(tmp.itemid > 0) then
table.insert(reward._itemid, tmp.itemid)
if isContainer(tmp.uid) then
table.insert(reward._inside, 0)
table.insert(reward._amount, 1)
table.insert(reward._type, 4)
table.insert(reward._weight,
getItemWeight(tmp.itemid))

local containersize = getContainerSize(tmp.uid)

if(containersize > 0) then


for b = 0, containersize do
local tmp_inside =
getContainerItem(tmp.uid, b)
if(tmp_inside.itemid > 0) then

--
table.insert(reward._inside, (i + 1))

table.insert(reward._inside, 1)

table.insert(reward._itemid, tmp_inside.itemid)
if (tmp_inside.type >
0 ) then

table.insert(reward._amount, tmp_inside.type)

table.insert(reward._weight, (tmp_inside.type *
getItemWeight(tmp_inside.itemid)))
if
isItemRune(tmp_inside.itemid) then

table.insert(reward._type, 2)
elseif
isItemStackable(tmp_inside.itemid) then

table.insert(reward._type, 3)
end
else

table.insert(reward._amount, 1)

table.insert(reward._type, 1)

table.insert(reward._weight, getItemWeight(tmp_inside.itemid))
end

end

end
end

else

table.insert(reward._inside, 0)
if (tmp.type > 0 ) then
table.insert(reward._amount, tmp.type)
table.insert(reward._weight, (tmp.type *
getItemWeight(tmp.itemid)))
if isItemRune(tmp.itemid) then
table.insert(reward._type, 2)
elseif isItemStackable(tmp.itemid) then
table.insert(reward._type, 3)
end
else
table.insert(reward._amount, 1)
table.insert(reward._type, 1)
table.insert(reward._weight,
getItemWeight(tmp.itemid))
end
end
end
end
end

--
***********************************************************************************
*--
--
***********************************************************************************
*--
--############################### GLOBAL FUNCTIONS
###################################--
--
***********************************************************************************
*--
--
***********************************************************************************
*--

--####################### FUNCTION COUNT AND GET TOTAL ITEMS


###############################--

function GetTotalItems()
CountItems = table.maxn(reward._itemid)
return CountItems
end

--####################### FUNCTION COUNT AND GET TOTAL WEIGHT


###############################--

function GetTotalWheight()
CountItems = GetTotalItems()
TotalWheight = 0
if (CountItems > 0) then
for i = 1, CountItems do
TotalWheight = (TotalWheight + reward._weight[i])
end
end
return TotalWheight
end

--############################ IMPORTANT FUNCTION ###############################--


-- Check Storage Fisrt Item - IF is Container Add Next Item <> Container Storage
--############################ IMPORTANT FUNCTION ###############################--

function CheckStorageItemId()
CountItems = GetTotalItems()
storage = nil
if (CountItems > 0) then
for i = 1, CountItems do
if reward._type[i] ~= 4 then
storage = reward._itemid[i]
break
end
end
end
return storage
end

--####################### FUNCTION RETURN RESULT REWARD


###############################--

function ReturnResultOnPlayer()
local ret = getItemDescriptions(reward._itemid[1])
if(reward._type[1] == 2) then
result = reward._amount[1] .. " charges " .. ret.name
elseif (reward._type[1] == 3) then
result = reward._amount[1].. " " .. ret.plural
elseif (reward._type[1] == 4) then
result = ret.article .. " " .. ret.name
else
result = ret.article .. " " .. ret.name
end
result = "You have found " .. result .. "."
return result
end

--####################### FUNCTION ADD REWARD ###############################--

if (GetTotalItems() > 0) and (CheckStorageItemId() ~= nil ) and


(getPlayerStorageValue(cid,CheckStorageItemId()) == -1 ) then
if getPlayerFreeCap(cid) >= GetTotalWheight() then
for c = 1, GetTotalItems() do
if reward._type[c] == 4 then
container = doPlayerAddItem(cid, reward._itemid[c],
1)
elseif reward._inside[c] > 0 then
doAddContainerItem(container, reward._itemid[c],
reward._amount[c])
else
doPlayerAddItem(cid, reward._itemid[c],
reward._amount[c])
end
end

setPlayerStorageValue(cid,CheckStorageItemId(),1)
ReturnResultOnPlayer()
else
result = "You have found a reward weighing " .. TotalWheight .. "
oz. It is too heavy or you have not enough space."
end
else
result = msg_config._msg_empty_type[MSGMODE]
end

--####################### SEND MSG REWARD ###############################--

doPlayerSendTextMessage(cid, msg_config._msgadvance[MSGADVANCEDGMODE], result


)
return true
end

You might also like