Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ACTIONVAR_USER = 1
- ACTIONVAR_OBJ1 = 2
- ACTIONVAR_OBJ2 = 3
- ACTIONBAR_TEMP = 4
- ACTIONVAR_USERPOS = 5
- ACTIONVAR_OBJ1POS = 6
- ACTIONVAR_OBJ2POS = 7
- ACTIONVAR_OBJ2TYPE = 8
- ACTIONVAR_OBJ1ID = 9
- ActionSystem = {
- actionsId = {
- [ACTIONVAR_OBJ1] = {},
- },
- actionsAId = {
- [ACTIONVAR_OBJ1] = {},
- },
- actionsUid = {
- [ACTIONVAR_OBJ1] = {},
- },
- b = 100,
- }
- function ActionSystem:executeConditions(conditionList, vars, fromPosition, isHotkey)
- if #conditionList == 0 then
- return true
- end
- for _, func in ipairs(conditionList) do
- if not func(vars, fromPosition, isHotkey) then
- return false
- end
- end
- return true
- end
- function ActionSystem:executeActions(actionList, vars, fromPosition, isHotkey)
- for _, func in ipairs(actionList) do
- if not func(vars, fromPosition, isHotkey) then
- return false
- end
- end
- return true
- end
- function ActionSystem:doActionList(list, vars, fromPosition, isHotkey)
- for _, data in ipairs(list) do
- if self:executeConditions(data.conditions, vars, fromPosition, isHotkey) then
- if self:executeActions(data.actions, vars, fromPosition, isHotkey) then
- return true
- end
- end
- end
- return false
- end
- function ActionSystem:getActions(whichObjectId, list, id)
- return list[whichObjectId][id]
- end
- function ActionSystem:onUseEventCallback(player, item, playerPosition, itemPosition, fromPosition, target, toPosition, isHotkey)
- local vars = {
- [ACTIONVAR_USER] = player,
- [ACTIONVAR_OBJ1] = item,
- [ACTIONVAR_OBJ1POS] = itemPosition,
- }
- local itemId = item:getId()
- local actionId = item:getActionId()
- local uniqueId = item:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
- vars[ACTIONVAR_OBJ1ID] = itemId
- if uniqueId > 0 then
- local list = self:getActions(ACTIONVAR_OBJ1, self.ActionsUid, uniqueId)
- if list then
- if self:doActionList(list, vars, fromPosition, isHotkey) then
- return true
- end
- end
- end
- if actionId > 0 then
- local list = self:getActions(ACTIONVAR_OBJ1, self.actionsAId, actionId)
- if list then
- if self:doActionList(list, vars, fromPosition, isHotkey) then
- return true
- end
- end
- end
- local list = self:getActions(ACTIONVAR_OBJ1, self.actionsId, itemId)
- if list then
- if self:doActionList(list, vars, fromPosition, isHotkey) then
- return true
- end
- end
- return false
- end
- function IsType(var, id)
- return function()
- return var, id
- end
- end
- function IsPosition(target, x, y, z)
- local p = Position(x, y, z)
- return function(vars, fromPosition, isHotkey)
- local posVar
- if target == ACTIONVAR_OBJ1 then
- posVar = ACTIONVAR_OBJ1POS
- end
- return (vars[ACTIONVAR_OBJ1POS] == p)
- end
- end
- function Effect(target, effect)
- return function(vars, fromPosition, isHotkey)
- vars[ACTIONVAR_OBJ1POS]:sendMagicEffect(effect)
- return true
- end
- end
- function Use(...)
- local parameters = {...}
- --first condition must be the function that defines item id/unique id/action id define
- local firstCondition = parameters[1]
- table.remove(parameters, 1)
- local var, choiceId = firstCondition()
- local foundActions = false
- local conditions = {}
- local actions = {}
- for _, param in ipairs(parameters) do
- if param == "->" then
- foundActions = true
- else
- if foundActions then
- table.insert(actions, param)
- else
- table.insert(conditions, param)
- end
- end
- end
- local data = {conditions = conditions, actions = actions}
- if not ActionSystem.actionsId[var][choiceId] then
- ActionSystem.actionsId[var][choiceId] = {}
- end
- table.insert(ActionSystem.actionsId[var][choiceId], data)
- end
Add Comment
Please, Sign In to add comment