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

Solved TFS 1.1 function vocation list

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
834
Solutions
123
Reaction score
675
Location
United States
For Client 10.77

When I do codes that need a list with it for instance:

Code:
player:getVocation():getId() == 2,4,6,8

or

local config = {
VOC = 3,5,7
}

spectator:getVocation():getId ~= config.VOC

Then it only picks up on the first number. How do I get it to read all the numbers?
 
Solution
In this case I would use isInArray(table, value).
LUA:
isInArray({2, 4, 6, 8}, player:getVocation():getId())

local config = {
    VOC = {3, 5, 7}
}

if not isInArray(config.VOC, spectator:getVocation():getId()) then
What are you trying to do? do you want to print out the list? if so use a for loop.
 
It's a npc guard that attacks skulls and players with certain vocations. Also tried to do it in a pet system but I just ended up rewriting it all for each vocation, but the guard one is tricky.

Here's the guard script:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end

local config = {
    attackRadius = {x = 7, y = 5},
    attackPK = {value = true, skulls = {SKULL_WHITE, SKULL_RED}},
    attackMonster = {value = true, ignore = {"Rat", "Cave Rat"}},
    damageValue = {min = 10, max = 20},
    VOC_ID = 9,10,11,12,25,26,27,28
}

local targetId = 0
local function searchTarget()
    for _, spectator in ipairs(Game.getSpectators(Npc():getPosition(), false, false, config.attackRadius.x, config.attackRadius.x, config.attackRadius.y, config.attackRadius.y)) do
        if not spectator:isNpc() then
            if ((spectator:isPlayer() and not spectator:getGroup():getAccess()) and config.attackPK.value and isInArray(config.attackPK.skulls, spectator:getSkull())) or ((spectator:isPlayer()) and (spectator:getVocation():getId() ~= config.VOC_ID)) then
                targetId = spectator:getId()
            elseif spectator:isMonster() and config.attackMonster.value and not isInArray(config.attackMonster.ignore, spectator:getName()) then
                targetId = spectator:getId()
            end
        end
    end
end

function onThink()
    local npc = Npc()
    local target = Creature(targetId)
    local vocs = 8

    -- If we have not a target, then we shall search for one
    if not target then
        searchTarget(npc)
        return
    end

    -- Let's get target offset position
    local npcPosition = npc:getPosition()
    local targetPosition = target:getPosition()
    local offsetX = npcPosition.x - targetPosition.x
    local offsetY = npcPosition.y - targetPosition.y

    -- Target is out of reach, search for new one
    if math.abs(offsetX) > config.attackRadius.x or math.abs(offsetY) > config.attackRadius.y then
        targetId = 0
        searchTarget(npc)
        return
    end

    -- If target is found
    doTargetCombatHealth(npc:getId(), targetId, COMBAT_ICEDAMAGE, -config.damageValue.min, -config.damageValue.max, CONST_ME_ICEATTACK)
    npcPosition:sendDistanceEffect(targetPosition, CONST_ANI_ICE)
    doNpcSetCreatureFocus(targetId)
    npcHandler:onThink()                   
end
 
In this case I would use isInArray(table, value).
LUA:
isInArray({2, 4, 6, 8}, player:getVocation():getId())

local config = {
    VOC = {3, 5, 7}
}

if not isInArray(config.VOC, spectator:getVocation():getId()) then
 
Solution

Similar threads

Back
Top