plugins/testsuite/entpropelements.sp
author David Anderson <dvander@alliedmods.net>
Mon Aug 12 00:22:41 2013 +0100 (2013-08-12)
changeset 3989 b73dae36a0da
parent 3293 f688cf4a4201
permissions -rw-r--r--
Eliminate InfoVars::rval (bug 5844 part 6, r=ds).
     1 #include <sourcemod>
     2 #include <sdktools>
     3 
     4 // Coverage:
     5 // GetEntPropArraySize - PropSend/PropData
     6 
     7 // GetEntPropString - PropData
     8 
     9 // GetEntProp    - PropSend/PropData
    10 // GetEntPropEnt - PropSend/PropData
    11 
    12 // SetEntProp    - PropSend/PropData
    13 
    14 public OnPluginStart()
    15 {
    16 	RegConsoleCmd("sm_listammo", sm_listammo, "sm_listammo <send|data> [target] - Lists current ammo for self or specified player");
    17 	RegConsoleCmd("sm_listweapons", sm_listweapons, "sm_listweapons <send|data> [target] - Lists current weapons for self or specified player");
    18 	RegConsoleCmd("sm_setammo", sm_setammo, "sm_setammo <ammotype> <amount> <send|data> [target]");
    19 	RegConsoleCmd("sm_teststrings", sm_teststrings);
    20 }
    21 
    22 public Action:sm_listammo(client, argc)
    23 {
    24 	decl String:buffer[64];
    25 	new target = client;
    26 	if (argc >= 2)
    27 	{
    28 		GetCmdArg(2, buffer, sizeof(buffer));
    29 		target = FindTarget(client, buffer, false, false);
    30 		if (target <= 0)
    31 		{
    32 			ReplyToCommand(client, "Bad client");
    33 			return Plugin_Handled;
    34 		}
    35 	}
    36 	else if (client == 0)
    37 	{
    38 		ReplyToCommand(client, "Dillweed");
    39 		return Plugin_Handled;
    40 	}
    41 	
    42 	new PropType:proptype = PropType:-1;
    43 	GetCmdArg(1, buffer, sizeof(buffer));
    44 	if (!strcmp(buffer, "send"))
    45 		proptype = Prop_Send;
    46 	else if (!strcmp(buffer, "data"))
    47 		proptype = Prop_Data;
    48 	
    49 	new ammo;
    50 	new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
    51 	for (new i = 0; i < max; i++)
    52 	{
    53 		if ((ammo = GetEntProp(target, proptype, "m_iAmmo", _, i)) > 0)
    54 			ReplyToCommand(client, "Slot %d, Ammo %d", i, ammo);
    55 	}
    56 		
    57 	return Plugin_Handled;
    58 }
    59 
    60 public Action:sm_listweapons(client, argc)
    61 {
    62 	decl String:buffer[64];
    63 	new target = client;
    64 	if (argc >= 2)
    65 	{
    66 		GetCmdArg(2, buffer, sizeof(buffer));
    67 		target = FindTarget(client, buffer, false, false);
    68 		if (target <= 0)
    69 		{
    70 			ReplyToCommand(client, "Bad client");
    71 			return Plugin_Handled;
    72 		}
    73 	}
    74 	else if (client == 0)
    75 	{
    76 		ReplyToCommand(client, "Dillweed");
    77 		return Plugin_Handled;
    78 	}
    79 	
    80 	new PropType:proptype = PropType:-1;
    81 	GetCmdArg(1, buffer, sizeof(buffer));
    82 	if (!strcmp(buffer, "send"))
    83 		proptype = Prop_Send;
    84 	else if (!strcmp(buffer, "data"))
    85 		proptype = Prop_Data;
    86 	
    87 	new weapon, String:classname[64];
    88 	new max = GetEntPropArraySize(target, proptype, "m_hMyWeapons");
    89 	for (new i = 0; i < max; i++)
    90 	{
    91 		if ((weapon = GetEntPropEnt(target, proptype, "m_hMyWeapons", i)) == -1)
    92 			continue;
    93 		
    94 		GetEdictClassname(weapon, classname, sizeof(classname));
    95 		ReplyToCommand(client, "Slot %d - \"%s\"", i, classname);
    96 	}
    97 		
    98 	return Plugin_Handled;
    99 }
   100 
   101 public Action:sm_setammo(client, argc)
   102 {
   103 	decl String:buffer[64];
   104 	new target = client;
   105 	if (argc >= 4)
   106 	{
   107 		GetCmdArg(4, buffer, sizeof(buffer));
   108 		target = FindTarget(client, buffer, false, false);
   109 		if (target <= 0)
   110 		{
   111 			ReplyToCommand(client, "Bad client");
   112 			return Plugin_Handled;
   113 		}
   114 	}
   115 	else if (client == 0)
   116 	{
   117 		ReplyToCommand(client, "Dillweed");
   118 		return Plugin_Handled;
   119 	}
   120 	
   121 	new PropType:proptype = PropType:-1;
   122 	GetCmdArg(3, buffer, sizeof(buffer));
   123 	if (!strcmp(buffer, "send"))
   124 		proptype = Prop_Send;
   125 	else if (!strcmp(buffer, "data"))
   126 		proptype = Prop_Data;
   127 	
   128 	new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
   129 	
   130 	GetCmdArg(1, buffer, sizeof(buffer));
   131 	new ammotype = StringToInt(buffer);
   132 	
   133 	if (ammotype >= max)
   134 	{
   135 		ReplyToCommand(client, "Ammotype out of bounds");
   136 		return Plugin_Handled;
   137 	}
   138 	
   139 	GetCmdArg(2, buffer, sizeof(buffer));
   140 	new amount = StringToInt(buffer);
   141 	
   142 	SetEntProp(target, proptype, "m_iAmmo", amount, _, ammotype);
   143 	
   144 	return Plugin_Handled;
   145 }
   146 
   147 public Action:sm_teststrings(client, argc)
   148 {
   149 	new gpe = CreateEntityByName("game_player_equip");
   150 	DispatchKeyValue(gpe, "tf_weapon_rocketlauncher", "2");
   151 	DispatchKeyValue(gpe, "tf_weapon_pistol",         "1");
   152 	
   153 	decl String:value[64];
   154 	for (new i = 0; i < 2; i++)
   155 	{
   156 		GetEntPropString(gpe, Prop_Data, "m_weaponNames", value, sizeof(value), i);
   157 		ReplyToCommand(client, "At %d, I see a \"%s\"", i, value);
   158 	}
   159 	
   160 	AcceptEntityInput(gpe, "Kill");
   161 	
   162 	return Plugin_Handled;
   163 }