Page 1 of 1

@setskill

Posted: Sun May 10, 2015 2:15 pm
by TeoTwawki
Variations of this have been posted here before, but there are now bindings in the DakrStar trunk for it rather than 3rd party ones, so I remade this largely based off EDGECOM's old lua's (2 commands, now 1) to work with the bindings Demolish made.

I know its messy, please forgive me for that. I was doing this for some friends and didn't bother to make it neat or efficient - I only made sure it functions and didn't make it well written after that, so this script will look like crap. If someone wants to clean it up and post a better version (or even pull request it to the project) that'd be cool. I just didn't didn't have any more time to spend on it, rl drama right now.

If no skill level is specified, it will simply print the targets current skill. if no target is specified, the user will be the target.

if the skill is a crafting skill, rank will be adjusted.

Both the user and the target will receive log messages about the skill change.

Code: Select all

---------------------------------------------------------------------------------------------------
-- func: @setskill <skill name or ID> <skill level> <target>
-- desc: set specified skill
---------------------------------------------------------------------------------------------------

cmdprops =
{
    permission = 2,
    parameters = "sis"
};

function onTrigger(player, skill, skillLV, target)
    if (skill == nill) then
        player:PrintToPlayer("@setskill <skill name or ID> <skill level> <target>")
        return;
    end

    local skillList =
    {
        ["h2h"]          = 1,
        ["hand2hand"]    = 1,
        ["handtohand"]   = 1,
        ["dagger"]       = 2,
        ["sword"]        = 3,
        ["gsword"]       = 4,
        ["greatsword"]   = 4,
        ["axe"]          = 5,
        ["gaxe"]         = 6,
        ["greataxe"]     = 6,
        ["scythe"]       = 7,
        ["polearm"]      = 8,
        ["spear"]        = 8,
        ["lance"]        = 8,
        ["katana"]       = 9,
        ["gkatana"]      = 10,
        ["greatkatana"]  = 10,
        ["club"]         = 11,
        ["staff"]        = 12,
        -- 13 to 21 do not exist.
        -- automaton melee     = 22,
        -- automaton archery   = 23,
        -- automaton magic     = 24,
        ["archery"]      = 25,
        ["marksmanship"] = 26,
        ["throwing"]     = 27,
        ["guard"]        = 28,
        ["evasion"]      = 29,
        ["shield"]       = 30,
        ["parry"]        = 31,
        ["divine"]       = 32,
        ["healing"]      = 33,
        ["enhancing"]    = 34,
        ["enfeebling"]   = 35,
        ["elemental"]    = 36,
        ["dark"]         = 37,
        ["summoning"]    = 38,
        ["ninjutsu"]     = 39, -- Correct spelling is "ninjutsu" but
        ["ninjitsu"]     = 39, -- everyone misspells as "ninjitsu" so added both
        ["singing"]      = 40,
        ["string"]       = 41,
        ["wind"]         = 42,
        ["blue"]         = 43,
        ["geomancy"]     = 44,
        ["handbell"]     = 45,
        -- 46 and 47 do not exist.
        ["fishing"]      = 48,
        ["woodworking"]  = 49,
        ["smithing"]     = 50,
        ["goldsmithing"] = 51,
        ["clothcraft"]   = 52,
        ["leathercraft"] = 53,
        ["bonecraft"]    = 54,
        ["alchemy"]      = 55,
        ["cooking"]      = 56,
        ["synergy"]      = 57,
        -- ["riding"]       = 58,
        -- ["digging"]      = 59,
        -- 60+ do not exist.
    }
    local skillID = skillList[string.lower(skill)];
    local targ = nil;

    if (skillID == nil) then
        skillID = tonumber(skill,10);
    end

    if (skillID ~= nil) then
        if (skillID == 0 or (skillID > 12 and skillID < 25)
        or skillID == 46 or skillID == 47 or skillID > 57) then
            player:PrintToPlayer("Must specify a valid skill.")
            return;
        end
    else
        player:PrintToPlayer("Must specify a valid skill.")
        return;
    end

    if (target == nil) then
        targ = player;
    else
        targ = GetPlayerByName(target);
        if (targ == nil) then
            player:PrintToPlayer(string.format("Player named '%s' not found!", target));
            return;
        end
    end

    if (skillLV == nil) then
        player:PrintToPlayer(string.format("%s's %s Skill: %u", targ:getName(), skill, targ:getSkillLevel(skillID)))
        if (skillID > 47) then
            player:PrintToPlayer(string.format("%s's %s Rank: %u", targ:getName(), skill, targ:getSkillRank(skillID)))
        end
    else
        if (skillID > 47) then
            if (skillLV >= 0 and skillLV < 8) then
                targ:setSkillRank(skillID,0);   -- Amateur 0-8
            elseif (skillLV >= 8 and skillLV < 18) then
                targ:setSkillRank(skillID,1);   -- Recruit 8-18
            elseif (skillLV >= 18 and skillLV < 28) then
                targ:setSkillRank(skillID,2);   -- Initiate 18-28
            elseif (skillLV >= 28 and skillLV < 38) then
                targ:setSkillRank(skillID,3);   -- Novice 28-38
            elseif (skillLV >= 38 and skillLV < 48) then
                targ:setSkillRank(skillID,4);   -- Apprentice 38-48
            elseif (skillLV >= 48 and skillLV < 58) then
                targ:setSkillRank(skillID,5);   -- Journeyman 48-58
            elseif (skillLV >= 58 and skillLV < 68) then
                targ:setSkillRank(skillID,6);   -- Craftsman 58-68
            elseif (skillLV >= 68 and skillLV < 78) then
                targ:setSkillRank(skillID,7);   -- Artisan" 68-78
            elseif (skillLV >= 78 and skillLV < 88) then
                if (skillID == 57) then
                    targ:setSkillRank(skillID,7); -- Synergy currently caps at 80 on retail.
                else
                    targ:setSkillRank(skillID,8); -- Adept 78-88
                end
            elseif (skillLV >= 88 and skillLV < 98) then
                targ:setSkillRank(skillID,9);   -- Veteran 88-98
            elseif (skillLV >= 98 and skillLV < 101) then
                -- targ:setSkillRank(skillID,10);  -- Expert 98-100
                -- Temp Veteran rank till we implement additional cap increase miniquests
                targ:setSkillRank(skillID,9);
            elseif (skillLV > 100) then
                -- Future editing will be needed here.
                targ:setSkillRank(skillID,10);
                -- 11 = Authority
                -- 12 = Luminary
                -- 13 = master
                -- 14 = Grandmaster
                -- 15 = Legend
                -- 16+ invalid.
            end
        end
        targ:setSkillLevel(skillID, skillLV);
        targ:messageBasic(53, skillID, skillLV);
        player:PrintToPlayer(string.format("%s's new %s Skill: %u", targ:getName(), skill, targ:getSkillLevel(skillID)))
        if (skillID > 47) then
            player:PrintToPlayer(string.format("%s's new %s Rank: %u", targ:getName(), skill, targ:getSkillRank(skillID)))
        end
    end
end;

Re: @setskill

Posted: Mon May 11, 2015 7:38 pm
by Wannabc5
This happens when I do @setskill goldsmithing 100 Hiro

this error pops up on game server

[Error] cmdhandler::call: (setskill): scripts/commands/setskill.lua:148: attempt to call method 'setSkillLevel' (a nil value)

I should probably mention that it changes my rank from Amateur to Expert but does not change the number.

Re: @setskill

Posted: Mon May 11, 2015 9:42 pm
by TeoTwawki
Wannabc5 wrote:This happens when I do @setskill goldsmithing 100 Hiro

this error pops up on game server

[Error] cmdhandler::call: (setskill): scripts/commands/setskill.lua:148: attempt to call method 'setSkillLevel' (a nil value)

I should probably mention that it changes my rank from Amateur to Expert but does not change the number.
This depends on recently added bindings, if you are on older version of the server code the binding for setSkillLevel() won't exist. Pull the changes, recompile.