source: binary-improvements/CoppisAdditions/src/Commands/GiveXP.cs@ 277

Last change on this file since 277 was 273, checked in by alloc, 9 years ago

fixes 8_10_13_1

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5namespace CoppisAdditions.CustomCommands
6{
7 public class GiveXP : ConsoleCmdAbstract
8 {
9 public override string GetDescription ()
10 {
11 return "give an amount XP to a player (entity id or name)";
12 }
13
14 public override string GetHelp ()
15 {
16 return "Give XP to a player\n" +
17 "Usage:\n" +
18 " givexp <name / entity id> <amount xp> <skill name>\n" +
19 "Skills names are: Athletics, Scavenging, Clothing, Light_Armor, Heavy_Armor, Blunt_Weapons, Blade_Weapons, Mining_Tools, Construction_Tools, Pistols, Shotguns, Rifles, Archery, Medicine, Weapon_Smithing, Tool_Smithing, Gun_Smithing, Science, Tailoring, Leatherworking, Armor_Smithing, Miscellaneous_Crafting, Quality_Joe";
20 }
21
22 public override string[] GetCommands ()
23 {
24 return new string[] { "givexp" };
25 }
26
27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
28 {
29 try {
30 if (_params.Count != 3) {
31 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3, found " + _params.Count + ".");
32 return;
33 }
34
35 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
36 if (ci == null) {
37 SdtdConsole.Instance.Output ("Playername or entity id not found.");
38 return;
39 }
40
41 int xp = int.MinValue;
42 int.TryParse (_params [1], out xp);
43
44 if (xp <= 0) {
45 SdtdConsole.Instance.Output ("The amount of XP is not a valid positive integer.");
46 return;
47 }
48
49 String skillName = _params [2].Replace ('_', ' ');
50
51 Skill skill = new Skills ().GetSkillByName (skillName);
52 if (skill == null) {
53 SdtdConsole.Instance.Output ("Invalid skill name: \"" + skillName + "\"");
54 return;
55 }
56 EntityPlayer ep = GameManager.Instance.World.Players.dict [ci.entityId];
57 GameManager.Instance.AddExpServer (ci.entityId, skill.Id, xp);
58 SdtdConsole.Instance.Output (xp + " xp was given on skill " + skillName + " to player " + ci.playerName);
59 } catch (Exception e) {
60 Log.Out ("Error in GiveXP.Execute: " + e);
61 }
62 }
63 }
64}
Note: See TracBrowser for help on using the repository browser.