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

Request a function tfs 1.2

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi my dear friends,

Could someone create a function that check if the player is in shared party and with four vocations and there is no MCs then will return a print.

Thanks.
 
Last edited:
Solution
Code:
function Vocation:getBaseVocation()
    while self:getDemotion() do
        self = self:getDemotion()
    end
    return self
end

function Player:vocationCount(countmc, shared)
    local party = self:getParty()
    if not party then
        return false
    end

    local vocations = {}
    local ips = {}
    local mc = false

    if shared and not party:isSharedExperienceActive() then
        return false
    end

    local members = party:getMembers()
    table.insert(members, party:getLeader())

    for i = 1, #members do
        local continue = false
        if not countmc then
            local ip = members[i]:getIp()
            if isInArray(ips, ip) then
                continue = true
                mc = true...
if you want it to not allow MC in party at all use this

Code:
function checkPartyForAllVocations(player)

    --CHECK MC--
    local ipList = {}
    local party = player:getParty()
    for i = 1, #party do
        local tmpPlayer = party[i]
        local ip = tmpPlayer:getIp()
        if ip ~= 0 then
            local list = ipList[ip]
            if not list then
                ipList[ip] = {}
                list = ipList[ip]
            end
            list[#list + 1] = tmpPlayer
        end
    end

    for ip, list in pairs(ipList) do
        local listLength = #list
        if listLength > 1 then
            return false
        
        end
    end

    local arrays = {
    [1] = {1, 5}, --sorcerer
    [2] = {2, 6}, --druid
    [3] = {3, 7}, --paladin
    [4] = {4, 8} --knight
    }

    local sorcerer, druid, paladin, knight = 0, 0, 0, 0
    --CHECK VOCATIONS--
    if isInArray(arrays[1], player:getVocation():getId()) then
    sorcerer = 1
    elseif isInArray(arrays[2], player:getVocation():getId()) then
    druid = 1
    elseif isInArray(arrays[3], player:getVocation():getId()) then
    paladin = 1
    elseif isInArray(arrays[4], player:getVocation():getId()) then
    knight = 1
    end

    for i = 1, #party do
        if isInArray(arrays[1], party[i]:getVocation():getId()) and sorcerer < 0 then
            sorcerer = 1
        elseif isInArray(arrays[2], party[i]:getVocation():getId()) and druid < 0 then
            druid = 1
        elseif isInArray(arrays[3], party[i]:getVocation():getId()) and paladin < 0 then
            paladin = 1
        elseif isInArray(arrays[4], party[i]:getVocation():getId()) and knight < 0 then
            knight = 1
        end
    end

    if sorcerer > 0 and druid > 0 and paladin > 0 and knight > 0 then
    return true
    else
    return false
    end
end
 
Last edited:
If you want it so players can be MC in party but their MC wont count then use this function

Code:
function checkPartyForAllVocations(player)
local arrays = {
    [1] = {1, 5}, --sorcerer
    [2] = {2, 6}, --druid
    [3] = {3, 7}, --paladin
    [4] = {4, 8} --knight
    }
  
    local sorcerer, druid, paladin, knight = 0, 0, 0, 0
  
    --CHECK MC--
    local ipList = {}
    local party = player:getParty()
    for i = 1, #party do
        local tmpPlayer = party[i]
        local ip = tmpPlayer:getIp()
        if ip ~= 0 then
            local list = ipList[ip]
            if not list then
                ipList[ip] = {}
                list = ipList[ip]
            end
            list[#list + 1] = tmpPlayer
        end
    end

    for ip, list in pairs(ipList) do
        local listLength = #list
        if listLength > 1 then
            for i = 2, listLength do
                tmpPlayer = list[i]
                if isInArray(arrays[1], tmpPlayer[i]:getVocation():getId()) and sorcerer < 0 then
                sorcerer = sorcerer - 1
                elseif isInArray(arrays[2], tmpPlayer[i]:getVocation():getId()) and druid < 0 then
                druid = druid - 1
                elseif isInArray(arrays[3], tmpPlayer[i]:getVocation():getId()) and paladin < 0 then
                paladin = paladin - 1
                elseif isInArray(arrays[4], tmpPlayer[i]:getVocation():getId()) and knight < 0 then
                knight = knight - 1
                end
            end
        end
    end

    local sorcerer, druid, paladin, knight = 0, 0, 0, 0
    --CHECK VOCATIONS--
    if isInArray(arrays[1], player:getVocation():getId()) then
    sorcerer = sorcerer + 1
    elseif isInArray(arrays[2], player:getVocation():getId()) then
    druid = druid + 1
    elseif isInArray(arrays[3], player:getVocation():getId()) then
    paladin = paladin + 1
    elseif isInArray(arrays[4], player:getVocation():getId()) then
    knight = knight + 1
    end
  
    for i = 1, #party do
        if isInArray(arrays[1], party[i]:getVocation():getId()) and sorcerer < 0 then
            sorcerer = sorcerer + 1
        elseif isInArray(arrays[2], party[i]:getVocation():getId()) and druid < 0 then
            druid = druid + 1
        elseif isInArray(arrays[3], party[i]:getVocation():getId()) and paladin < 0 then
            paladin = paladin + 1
        elseif isInArray(arrays[4], party[i]:getVocation():getId()) and knight < 0 then
            knight = knight + 1
        end
    end
  
    if sorcerer > 0 and druid > 0 and paladin > 0 and knight > 0 then
    return true
    else
    return false
    end
end
 
Last edited:
If you want it so players can be MC in party but their MC wont count then use this function

Code:
function checkPartyForAllVocations(player)
local arrays = {
    [1] = {1, 5}, --sorcerer
    [2] = {2, 6}, --druid
    [3] = {3, 7}, --paladin
    [4] = {4, 8} --knight
    }
  
    local sorcerer, druid, paladin, knight = 0, 0, 0, 0

    party = player:getParty()
  
    --CHECK MC--
    local ipList = {}
    local party = player:getParty()
    for i = 1, #party do
        local tmpPlayer = party[i]
        local ip = tmpPlayer:getIp()
        if ip ~= 0 then
            local list = ipList[ip]
            if not list then
                ipList[ip] = {}
                list = ipList[ip]
            end
            list[#list + 1] = tmpPlayer
        end
    end

    for ip, list in pairs(ipList) do
        local listLength = #list
        if listLength > 1 then
            for i = 2, listLength do
                tmpPlayer = list[i]
                if isInArray(arrays[1], tmpPlayer[i]:getVocation():getId()) and sorcerer < 0 then
                sorcerer = sorcerer - 1
                elseif isInArray(arrays[2], tmpPlayer[i]:getVocation():getId()) and druid < 0 then
                druid = druid - 1
                elseif isInArray(arrays[3], tmpPlayer[i]:getVocation():getId()) and paladin < 0 then
                paladin = paladin - 1
                elseif isInArray(arrays[4], tmpPlayer[i]:getVocation():getId()) and knight < 0 then
                knight = knight - 1
                end
            end
        end
    end

    local sorcerer, druid, paladin, knight = 0, 0, 0, 0
    --CHECK VOCATIONS--
    if isInArray(arrays[1], player:getVocation():getId()) then
    sorcerer = sorcerer + 1
    elseif isInArray(arrays[2], player:getVocation():getId()) then
    druid = druid + 1
    elseif isInArray(arrays[3], player:getVocation():getId()) then
    paladin = paladin + 1
    elseif isInArray(arrays[4], player:getVocation():getId()) then
    knight = knight + 1
    end
  
    for i = 1, #party do
        if isInArray(arrays[1], party[i]:getVocation():getId()) and sorcerer < 0 then
            sorcerer = sorcerer + 1
        elseif isInArray(arrays[2], party[i]:getVocation():getId()) and druid < 0 then
            druid = druid + 1
        elseif isInArray(arrays[3], party[i]:getVocation():getId()) and paladin < 0 then
            paladin = paladin + 1
        elseif isInArray(arrays[4], party[i]:getVocation():getId()) and knight < 0 then
            knight = knight + 1
        end
    end
  
    if sorcerer > 0 and druid > 0 and paladin > 0 and knight > 0 then
    return true
    else
    return false
    end
end

Hi my friend, this script is currently giving a error..

lie7pw1.png
 
edited them both

Same error at same line, just for curious if I'm doing it right.

The check how suppost to be? Currently I'm using this below.
Code:
function onCastSpell(creature, var, isHotkey)
   if checkPartyForAllVocations(creature) then
  return party:execute(creature, variant)
  else
  return combat:execute(creature, variant)
  end
end
 
Code:
function Vocation:getBaseVocation()
    while self:getDemotion() do
        self = self:getDemotion()
    end
    return self
end

function Player:vocationCount(countmc, shared)
    local party = self:getParty()
    if not party then
        return false
    end

    local vocations = {}
    local ips = {}
    local mc = false

    if shared and not party:isSharedExperienceActive() then
        return false
    end

    local members = party:getMembers()
    table.insert(members, party:getLeader())

    for i = 1, #members do
        local continue = false
        if not countmc then
            local ip = members[i]:getIp()
            if isInArray(ips, ip) then
                continue = true
                mc = true
            else
                table.insert(ips, ip)
            end
        end
        if not continue then
            local basevoc = members[i]:getVocation():getBaseVocation():getId()
            vocations[basevoc] = (vocations[basevoc] or 0) + 1
        end
    end

    return vocations, mc
end

function Player:checkForAllVocations(allowmc)
    local count, mc = self:vocationCount(false, true)
    if not count or (not allowmc and mc) then
        return false
    end

    if count[1] and count[2] and count[3] and count[4] then
        return count[1] > 0 and count[2] > 0 and count[3] > 0 and count[4] > 0
    else
        return false
    end
end


For what you want you use:

creature:checkForAllVocations(false) -- This won't allow mc at all, will return false if mc
creature:checkForAllVocations(true) -- This will allow mc but will only count it 1 player for mc.

If you want to count all mcs you change the function checkForAllVocations and put: "self:vocationCount(true, true)" that will count all mcs.

Edit: comparing nil copy again.
 
Last edited:
Solution
Back
Top