- Joined
- Aug 19, 2007
- Messages
- 4,940
- Solutions
- 11
- Reaction score
- 354
action system + examples
item_functions.lua [has to be included with dofile("./data/path/to/item_functions.lua") at global/constant.lua]:
LUA:
-- Action 40 000 - 40 022 (Rook)
-- Action 6421 - 6429 (Main)
--######## COUNT PARAMETER IS OPTIONAL AT .item & .items BUT HAS TO BE ADDED IN CASE OF EXTRA PARAMETERS
--######## COUNT PARAMETER IS OPTIONAL AT .removeItem & .createItem and should be third [3]
--######## TO TRANSFORM ANOTHER ITEM THAN USED ONE: .transformItem = { { fromId, toId, itemPos } } ELSE .transformItem = { { toId } }
--[[
#AVAILABLE PARAMETERS @ .notQuest = false
.item = { { itemid [, count = 1][, text = ""][, actionid = 0][, description = ""] } }
.items = { { itemid [, count = 1][, text = ""][, actionid = 0][, description = ""] }[, anotherItemList] }
.container = containerId [Reward(s) will be given in this container, NOTE: you have to use .items parameter with .container, not .item]
.storage = (int) quest storage value [NOTE: Default is same as actionid]
#AVAILABLE PARAMETERS @ .notQuest = true
.itemFunction = function name from item_function.lua file to be executed when using this item
.removeItem = { { itemid, position [, count = 1] } [, { anotherItem }] }
.createItem = { { itemid, position [, count = 1] } [, { anotherItem }] }
.transformItem = { { toId [, decay = false ] } [, { anotherItem }] } OR .transformItem = { { fromId, toId, itemPos [, decay = false] } [, { anotherItem }] }
.effects = { { effect, position } [, { effect2, position2 }] }
.relocate = { { fromPos, toPos } [, { fromPos2, toPos2 }] }
.createTeleport = { { teleportId, positionToGo, teleportPosition } [, { anotherOne } ] }
.createMonster = { { name, pos } [, { anotherOne }] }
]]--
local ACCESS_GAMEMASTER = 3
local config = {
-- Usable items go here --
[0] = {
notQuest = true,
[2120] = { itemFunction = rope },
[2420] = { itemFunction = machete },
[2550] = { itemFunction = scythe },
[2553] = { itemFunction = pick },
[2554] = { itemFunction = shovel },
[2580] = { itemFunction = fishing }
},
-- Main --
--[[Demon Helmet]]--
[6421] = {
notQuest = true,
[1945] = {
removeItem = { { 1355, { x = 33314, y = 31592, z = 15 } } },
transformItem = { { 1946 } },
relocate = { { { x = 33315, y = 31590, z = 15 }, { x = 33320, y = 31592, z = 14 } } },
createTeleport = { { 1387, { x = 33320, y = 31592, z = 14 }, { x = 33315, y = 31590, z = 15 } } },
},
[1946] = {
createItem = { { 1355, { x = 33314, y = 31592, z = 15 } } },
removeItem = { { 1387, { x = 33315, y = 31590, z = 15 } } },
transformItem = { { 1945 } }
}
},
[6422] = { item = { 2493 } },
[6423] = { item = { 2645 } },
[6424] = { item = { 2520 } },
--[[Behemoth Quest]]--
[6425] = { item = { 2427 } },
[6426] = { item = { 2171 } },
[6427] = { item = { 2466 } },
[6428] = { item = { 2520 } },
[6429] = {
notQuest = true,
[1945] = {
effects = { { CONST_ME_MAGIC_RED, { x = 33295, y = 31677, z = 15 } }, { CONST_ME_MAGIC_RED, { x = 33296, y = 31677, z = 15 } }, { CONST_ME_MAGIC_RED, { x = 33297, y = 31677, z = 15 } }, { CONST_ME_MAGIC_RED, { x = 33298, y = 31677, z = 15 } }, { CONST_ME_MAGIC_RED, { x = 33299, y = 31677, z = 15 } } },
removeItem = { { 1304, { x = 33295, y = 31677, z = 15 } }, { 1304, { x = 33296, y = 31677, z = 15 } }, { 1304, { x = 33297, y = 31677, z = 15 } }, { 1304, { x = 33298, y = 31677, z = 15 } }, { 1304, { x = 33299, y = 31677, z = 15 } } },
transformItem = { { 1946 } }
},
[1946] = {
effects = { { CONST_ME_POFF, { x = 33295, y = 31677, z = 15 } }, { CONST_ME_POFF, { x = 33296, y = 31677, z = 15 } }, { CONST_ME_POFF, { x = 33297, y = 31677, z = 15 } }, { CONST_ME_POFF, { x = 33298, y = 31677, z = 15 } }, { CONST_ME_POFF, { x = 33299, y = 31677, z = 15 } } },
createItem = { { 1304, { x = 33295, y = 31677, z = 15 } }, { 1304, { x = 33296, y = 31677, z = 15 } }, { 1304, { x = 33297, y = 31677, z = 15 } }, { 1304, { x = 33298, y = 31677, z = 15 } }, { 1304, { x = 33299, y = 31677, z = 15 } } },
relocate = { { { x = 33295, y = 31677, z = 15 }, { x = 33295, y = 31678, z = 15 } }, { { x = 33296, y = 31677, z = 15 }, { x = 33296, y = 31678, z = 15 } }, { { x = 33297, y = 31677, z = 15 }, { x = 33297, y = 31678, z = 15 } }, { { x = 33298, y = 31677, z = 15 }, { x = 33298, y = 31678, z = 15 } }, { { x = 33299, y = 31677, z = 15 }, { x = 33299, y = 31678, z = 15 } } },
transformItem = { { 1945 } }
}
},
-- Rookgaard --
[40000] = { item = { 2404 } }, -- Combat Knife
[40001] = { item = { 2485 } }, -- Doublet
[40002] = { item = { 2384 } }, -- Rapier
[40003] = { item = { 2050 } }, -- Torch
[40004] = { item = { 2464 } }, -- Chain Armor
[40005] = { item = { 2460 } }, -- Brass Helmet
[40006] = { item = { 2412 } }, -- Katana
[40007] = { item = { 2473 } }, -- Viking Helmet
[40008] = {
notQuest = true,
[1945] = {
effects = { { CONST_ME_POFF, { x = 32145, y = 32101, z = 11 } } },
removeItem = { { 1304, { x = 32145, y = 32101, z = 11 } } }, transformItem = { { 1946 } }
},
[1946] = {
effects = { { CONST_ME_POFF, { x = 32145, y = 32101, z = 11 } } },
createItem = { { 1304, { x = 32145, y = 32101, z = 11 } } },
relocate = { { { x = 32145, y = 32101, z = 11 }, { x = 32145, y = 32102, z = 11 } } },
transformItem = { { 1945 } }
}
}, -- Bear Room Lever
[40009] = {
notQuest = true,
[1945] = {
createItem = { { 405, { x = 32100, y = 32205, z = 8 } }, { 405, { x = 32101, y = 32205, z = 8 } } },
removeItem = { { 4799, { x = 32100, y = 32205, z = 8 } }, { 4797, { x = 32101, y = 32205, z = 8 } } },
transformItem = { { 1945, 1946, { x = 32098, y = 32204, z = 8 } }, { 1945, 1946, { x = 32104, y = 32204, z = 8 } } }
},
[1946] = {
createItem = { { 493, { x = 32100, y = 32205, z = 8 } }, { 493, { x = 32101, y = 32205, z = 8 } }, { 4799, { x = 32100, y = 32205, z = 8 } }, { 4797, { x = 32101, y = 32205, z = 8 } } },
transformItem = { { 1946, 1945, { x = 32098, y = 32204, z = 8 } }, { 1946, 1945, { x = 32104, y = 32204, z = 8 } } },
relocate = { { { x = 32100, y = 32205, z = 8 }, { x = 32099, y = 32205, z = 8 } }, { { x = 32101, y = 32205, z = 8 }, { x = 32102, y = 32205, z = 8 } } }
}
}, -- Bridge under main square
[40010] = { item = { 2395 } }, -- Carlin Sword
[40011] = { item = { 2580 } }, -- Fishing Rod
[40012] = { container = 1987, items = { { 2545, 4 }, { 2544, 10 } } }, -- Mino Hell -> Arrows
[40013] = { container = 1987, items = { { 2530 }, { 2480 } } }, -- Dragon Corpse
[40014] = { container = 1987, items = { { 2544, 12 }, { 2148, 40 } } }, -- Bear Room
[40015] = { container = 1987, items = { { 2333, 1, text = "Orc Language chuju" } } }, -- Captain Iglues Treasure Quest, letter
[40016] = { item = { 2668, 2 } }, -- Captain Iglues Treasure Quest, salmon
[40017] = { container = 1988, items = { { 1990 }, { 2014 }, { 2035 }, { 2013 } } }, -- Present Box Quest
[40018] = { item = { 2103 } }, -- Honey Flower
[40019] = { item = { 2676 } }, -- Banana
[40020] = { item = { 2089, 1, actionid = 4601 } }, -- Bear Room Key (4601)
[40021] = { item = { 2088, 1, actionid = 4603 } }, -- Katana Room Key (4603)
[40022] = { item = { 2559 } } -- Small Axe
}
local function getWeight(id)
local weight = config[id]
local result = 0
if(weight)then
if(weight.container)then
result = result + getItemWeightById(weight.container, 1)
for i = 1, #weight.items do
result = result + getItemWeightById(weight.items[i][1], weight.items[i][2] or 1)
end
else
return getItemWeightById(weight.item[1], weight.item[2] or 1)
end
return result
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local action = config[item.actionid]
local str = "You have found a "
if(action)then
if(action.notQuest)then
local action_ = action[item.itemid]
if(action_)then
if(action_.itemFunction)then
action_.itemFunction(cid, item, fromPosition, itemEx, toPosition)
end
if(action_.removeItem)then
for i = 1, #action_.removeItem do
local thing = getTileItemById(action_.removeItem[i][2], action_.removeItem[i][1]).uid
if(thing > 0)then
doRemoveItem(thing, action_.removeItem[i][3] or 1)
end
end
end
if(action_.createItem)then
for i = 1, #action_.createItem do
doCreateItem(action_.createItem[i][1], action_.createItem[i][3] or 1, action_.createItem[i][2])
end
end
if(action_.transformItem)then
for i = 1, #action_.transformItem do
if(action_.transformItem[i][2] and action_.transformItem[i][3])then
local thing = getTileItemById(action_.transformItem[i][3], action_.transformItem[i][1]).uid
if(thing > 0)then
doTransformItem(thing, action_.transformItem[i][2])
if(action_.transformItem[i][4])then
doDecayItem(thing)
end
end
else
doTransformItem(item.uid, action_.transformItem[i][1])
if(action_.transformItem[i].decay)then
doDecayItem(item.uid)
end
end
end
end
if(action_.effects)then
for i = 1, #action_.effects do
doSendMagicEffect(action_.effects[i][2], action_.effects[i][1])
end
end
if(action_.createTeleport)then
for i = 1, #action_.createTeleport do
doCreateTeleport(action_.createTeleport[i][1], action_.createTeleport[i][2], action_.createTeleport[i][3])
end
end
if(action_.createMonster)then
for i = 1, #action_.createMonster do
doCreateMonster(action_.createMonster[i][1], action_.createMonster[i][2])
end
end
if(action_.relocate)then
for i = 1, #action_.relocate do
doRelocate(action_.relocate[i][1], action_.relocate[i][2])
end
end
end
else
if(getPlayerAccess(cid) >= ACCESS_GAMEMASTER)then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can not do quests :(!")
return LUA_ERROR
end
if(getPlayerStorageValue(cid, action.storage or item.actionid) ~= TRUE)then
if(getPlayerFreeCap(cid) >= getWeight(item.actionid))then
if(action.container)then
local container = doPlayerAddItem(cid, action.container, 1, 0)
if(container ~= LUA_ERROR)then
for i = 1, #action.items do
local reward = doAddContainerItem(container, action.items[i][1], action.items[i][2] or 1)
if(action.items[i].text)then
doSetItemText(reward, action.items[i].text)
end
if(action.items[i].actionid)then
doSetItemActionId(reward, action.items[i].actionid)
end
if(action.items[i].description)then
doSetItemSpecialDescription(reward, action.items[i].description)
end
end
setPlayerStorageValue(cid, action.storage or item.actionid, TRUE)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str..getItemName(action.container)..".")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str..getItemName(action.container).." but you do not have free space.")
end
else
local reward = doPlayerAddItem(cid, action.item[1], action.item[2] or 1, 0)
if(reward ~= LUA_ERROR)then
if(action.item.text)then
doSetItemText(reward, action.item.text)
end
if(action.item.actionid)then
doSetItemActionId(reward, action.item.actionid)
end
if(action.item.description)then
doSetItemSpecialDescription(reward, action.item.description)
end
setPlayerStorageValue(cid, action.storage or item.actionid, TRUE)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str..getItemName(action.item[1])..".")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str..getItemName(action.item[1]).." but you do not have free space.")
end
end
else
str = str..getItemName(action.item[1])
if(action.container)then
str = str..getItemName(action.container)
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str.." but it is too heavy.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
end
end
end
return TRUE
end
item_functions.lua [has to be included with dofile("./data/path/to/item_functions.lua") at global/constant.lua]:
LUA:
-- item functions file
function shovel(cid, item, fromPosition, itemEx, toPosition)
if(isInArray(CLOSED_HOLE, itemEx.itemid) == TRUE)then
doTransformItem(itemEx.uid, itemEx.itemid + 1)
doDecayItem(itemEx.uid)
elseif(itemEx.itemid == 231)then
local rand = math.random(1, 100)
if rand == 1 then
doCreateItem(2159, 1, toPosition)
elseif rand > 95 then
doSummonCreature("Scarab", toPosition)
end
doSendMagicEffect(toPosition, CONST_ME_POFF)
else
doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
end
return TRUE
end
function rope(cid, item, fromPosition, itemEx, toPosition)
if(toPosition.x == CONTAINER_POSITION) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
return TRUE
end
local itemGround = getThingFromPos(toPosition)
if(isInArray(ROPE_SPOT, itemGround.itemid) == TRUE) then
doTeleportThing(cid, { x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1 }, FALSE)
elseif(isInArray(OPENED_HOLE, itemEx.itemid)) then
local hole = getThingFromPos({ x = toPosition.x, y = toPosition.y, z = toPosition.z + 1, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE })
if(hole.itemid > 0) then
doTeleportThing(hole.uid, { x = toPosition.x, y = toPosition.y + 1, z = toPosition.z }, FALSE)
else
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
else
doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
return FALSE
end
return TRUE
end
local useWorms = true
function fishing(cid, item, fromPosition, itemEx, toPosition)
if(isInArray(FISHING, itemEx.itemid) == TRUE)then
if(itemEx.itemid ~= 493)then
if(math.random(1, (100 + (getPlayerSkill(cid, SKILL_FISHING) / 10))) <= getPlayerSkill(cid, SKILL_FISHING))then
if(useWorms)then
if(doPlayerRemoveItem(cid, ITEM_WORM, 1) == TRUE)then
doPlayerAddItem(cid, ITEM_FISH, 1)
doPlayerAddSkillTry(cid, SKILL_FISHING, 1, TRUE)
else
doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
end
else
doPlayerAddItem(cid, ITEM_FISH, 1)
doPlayerAddSkillTry(cid, SKILL_FISHING, 1, TRUE)
end
end
doPlayerAddSkillTry(cid, SKILL_FISHING, 1)
end
doSendMagicEffect(toPosition, CONST_ME_LOSEENERGY)
return TRUE
else
doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
end
return FALSE
end
function machete(cid, item, fromPosition, itemEx, toPosition)
if(isInArray(JUNGLE_GRASS, itemEx.itemid) == TRUE)then
doTransformItem(itemEx.uid, itemEx.itemid - 1)
doDecayItem(itemEx.uid)
return TRUE
end
return destroyItem(cid, itemEx, toPosition)
end
function pick(cid, item, fromPosition, itemEx, toPosition)
if itemEx.actionid == 4500 then
doSendMagicEffect(toPosition, CONST_ME_POFF)
doTransformItem(itemEx.uid, 392)
doDecayItem(itemEx.uid)
return TRUE
end
return FALSE
end
function scythe(cid, item, fromPosition, toPosition)
if itemEx.itemid == 2739 then
doTransformItem(itemEx.uid, 2737)
doCreateItem(2694, 1, toPosition)
doDecayItem(itemEx.uid)
return TRUE
end
return destroyItem(cid, itemEx, toPosition)
end