View Single Post
  #2  
Old 02-11-2012, 05:18 AM
Madrigal
Fire Beetle
 
Join Date: Mar 2010
Posts: 10
Default

Although the above code still works, I tightened up the targeting in command.cpp so that improper targets (NPCs, etc.) will result in an error message rather than target-defaulting to the player who issued the command.

command.cpp patch
Code:
Index: command.cpp
===================================================================
--- command.cpp	(revision 2100)
+++ command.cpp	(working copy)
@@ -328,6 +328,7 @@
 		command_add("qglobal","[on/off/view] - Toggles qglobal functionality on an NPC",100,command_qglobal) ||
 		command_add("loc","- Print out your or your target's current location and heading",0,command_loc) ||
 		command_add("goto","[x] [y] [z] - Teleport to the provided coordinates or to your target",10,command_goto) ||
+		command_add("practices","[add/set] [value] - Adds or sets practices to a player. Must zone afterward to take effect.",100,command_practices) ||
 #ifdef BUGTRACK
 		command_add("bugtrack","[bug description] - Report a bug",0,command_bug) ||
 #endif
@@ -4683,6 +4684,47 @@
 		c->MovePC(zone->GetZoneID(), zone->GetInstanceID(), atof(sep->arg[1]), atof(sep->arg[2]), atof(sep->arg[3]), 0.0f);
 }
 
+void command_practices(Client *c, const Seperator *sep)
+{
+	Client *t=c;
+
+	if(c->GetTarget() && c->GetTarget()->IsClient())
+	{
+		t=c->GetTarget()->CastToClient();
+		if ((strcasecmp( sep->arg[1], "add" ) == 0 ) && (sep->IsNumber(2)))
+		{
+			if ((atoi(sep->arg[2]) < 1) || (atoi(sep->arg[2]) > 5000))
+				c->Message(0, "Error: #practices: add <value> must range from 1 to 5000.");
+			else if (((t->GetPractices()) + (atoi(sep->arg[2]))) > 5000)
+				c->Message(0, "Error: #practices: Target has too many practices already.");
+			else
+			{
+				t->AddPractices(atoi(sep->arg[2]));
+				t->Save();
+				if (atoi(sep->arg[2]) == 1)
+					t->Message(0, "You have gained 1 practice!");
+				else
+					t->Message(0, "You have gained %i practices!", atoi(sep->arg[2]));
+			}
+		}
+		else if ((strcasecmp( sep->arg[1], "set" ) == 0 ) && (sep->IsNumber(2)))
+		{
+			if ((atoi(sep->arg[2]) < 0) || (atoi(sep->arg[2]) > 5000))
+				c->Message(0, "Error: #practices: set <value> must range from 0 to 5000.");
+			else
+			{
+				t->SetPractices(atoi(sep->arg[2]));
+				t->Save();
+				t->Message(0, "Your total practices have been set to %i.", atoi(sep->arg[2]));
+			}
+		}
+		else
+			c->Message(0, "Usage: #practices <add|set> <value>");
+	}
+	else
+		c->Message(0, "Error: #practices: Target must be a player.");
+}
+
 #ifdef BUGTRACK
 void command_bug(Client *c, const Seperator *sep)
 {
Reply With Quote