1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

HL2RP IsPlayerCombineRank

Discussion in 'Development' started by vexus, Apr 20, 2017.

  1. vexus

    vexus ej rockwell's worst nightmare Staff Member Manager Legend Clockwork Customer

    How exactly does IsPlayerCombineRank() work? Does it fetch a string out of the name or does it look for specific identifiers? I'm trying to make a plugin to change models of units based on keywords in their name, (ie. HELIX = model 1, HELIX.DvL = model 2).

    Same with IsStringCombineRank(). What's the difference between the two?
     
  2. redcatjack

    redcatjack Moderator and Map Developer Staff Member Moderator

    Look at sv_hooks.lua in "garrysmod\gamemodes\cwhl2rp\schema" it has:
    Code:
    -- Called when a player's default model is needed.
    function Schema:GetPlayerDefaultModel(player)
        local faction = player:GetFaction();
       
        if (self:IsCombineFaction(faction)) then
            if (self:IsPlayerCombineRank(player, "GHOST")) then
                return "models/eliteghostcp.mdl";
            elseif (self:IsPlayerCombineRank(player, "OfC")) then
                return "models/policetrench.mdl";
            elseif (self:IsPlayerCombineRank(player, "DvL")) then
                return "models/eliteshockcp.mdl";
            elseif (self:IsPlayerCombineRank(player, "SeC")) then
                return "models/sect_police2.mdl";
            end;
        end;
    end;
    Should give you an idea on how to use it, just remember to do it in a plugin and don't edit core files
     
  3. Viz

    Viz Legend Clockwork Customer

    Code:
    -- A function to check if a player is a Combine rank.
    function Schema:IsPlayerCombineRank(player, rank, realRank)
        local name = player:Name();
        local faction = player:GetFaction();
        if (self:IsCombineFaction(faction)) then
            if (type(rank) == "table") then
                for k, v in ipairs(rank) do
                    if (self:IsPlayerCombineRank(player, v, realRank)) then
                        return true;
                    end;
                end;
            elseif (rank == "EpU" and !realRank) then
                if (string.find(name, "%pSeC%p") or string.find(name, "%pDvL%p")
                or string.find(name, "%pEpU%p")) then
                    return true;
                end;
            else
                return string.find(name, "%p"..rank.."%p");
            end;
        end;
    end;
    
    IsPlayerCombineRank() will fetch a string out of the player's name using string.find(name, "%p"..rank.."%p"); and then return the rank if it finds it in their name.
    So doing IsPlayerCombineRank(player, "HELIX.DvL") will search that player's name for the string "HELIX.DvL" and, if it finds it, the function will return true.

    Code:
    -- A function to check if a string is a Combine rank.
    function Schema:IsStringCombineRank(text, rank)
        if (type(rank) == "table") then
            for k, v in ipairs(rank) do
                if (self:IsStringCombineRank(text, v)) then
                    return true;
                end;
            end;
        elseif (rank == "EpU") then
            if (string.find(text, "%pSeC%p") or string.find(text, "%pDvL%p")
            or string.find(text, "%pEpU%p")) then
                return true;
            end;
        else
            return string.find(text, "%p"..rank.."%p");
        end;
    end;
    
    IsStringCombineRank() does the same thing as the IsPlayerCombineRank() function, except it searches the string you provide instead of a player for a rank.
    So doing IsStringCombineRank(".RCT.", "RCT") would return true, whereas IsStringCombineRank("jimbo", "RCT") would return false. I think. I could be wrong.

    For what you're trying to do, you'll want to use IsPlayerCombineRank()

    EDIT: Also, forgot to add, %p is checking for any punctuation before or after the rank you provide.
     
    • Winner Winner x 1
    Last edited: Apr 20, 2017

Previous Readers (Total: 0)