plugins/testsuite/structtest.sp
author Peace-Maker <januk@freenet.de>
Sat May 10 05:42:33 2014 -0700 (2014-05-10)
changeset 4354 7011587e0021
parent 2360 1db1d8c288ca
permissions -rw-r--r--
Remove LogMessageEx definition from logging.inc (bug 5897, r=kyles).
     1 #include <sourcemod>
     2 #include <structs>
     3 
     4 public Plugin:myinfo = 
     5 {
     6 	name = "Struct Abstraction Test",
     7 	author = "pRED*",
     8 	description = "",
     9 	version = "1.0",
    10 	url = "http://www.sourcemod.net/"
    11 };
    12 
    13 public OnPluginStart()
    14 {
    15 	RegServerCmd("sm_getstructstring", Command_GetString);
    16 	RegServerCmd("sm_setstructstring", Command_SetString);
    17 	
    18 	RegServerCmd("sm_getstructint", Command_GetInt);
    19 	RegServerCmd("sm_setstructint", Command_SetInt);
    20 	
    21 	RegServerCmd("sm_getstructfloat", Command_GetFloat);
    22 	RegServerCmd("sm_setstructfloat", Command_SetFloat);
    23 
    24 }
    25 
    26 public Action:Command_GetString(args)
    27 {
    28 	if (args != 2)
    29 	{
    30 		ReplyToCommand(0, "[SM] Usage: sm_getstructstring <struct> <string>");
    31 		return Plugin_Handled;
    32 	}
    33 
    34 	decl String:arg1[32], String:arg2[32], String:value[32];
    35 	GetCmdArg(1, arg1, sizeof(arg1));
    36 	GetCmdArg(2, arg2, sizeof(arg2));
    37 
    38 	new Handle:strct = GetWeaponStruct(arg1);
    39 	GetStructString(strct, arg2, value, sizeof(value));
    40 
    41 	LogMessage("Value of %s: %s", arg2, value);
    42 
    43 	CloseHandle(strct);
    44 
    45 	return Plugin_Handled;
    46 }
    47 
    48 public Action:Command_SetString(args)
    49 {
    50 	if (args != 3)
    51 	{
    52 		ReplyToCommand(0, "[SM] Usage: sm_setstructstring <struct> <string> <value>");
    53 		return Plugin_Handled;
    54 	}
    55 
    56 	decl String:arg1[32], String:arg2[32], String:value[32];
    57 	GetCmdArg(1, arg1, sizeof(arg1));
    58 	GetCmdArg(2, arg2, sizeof(arg2));
    59 	GetCmdArg(3, value, sizeof(value));
    60 
    61 	new Handle:strct = GetWeaponStruct(arg1);
    62 	SetStructString(strct, arg2, value);
    63 
    64 	CloseHandle(strct);
    65 
    66 	return Plugin_Handled;	
    67 	
    68 }
    69 
    70 public Action:Command_GetInt(args)
    71 {
    72 	if (args != 2)
    73 	{
    74 		ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
    75 		return Plugin_Handled;
    76 	}
    77 
    78 	decl String:arg1[32], String:arg2[32];
    79 	GetCmdArg(1, arg1, sizeof(arg1));
    80 	GetCmdArg(2, arg2, sizeof(arg2));
    81 
    82 	new Handle:strct = GetWeaponStruct(arg1);
    83 	new value = GetStructInt(strct, arg2);
    84 
    85 	LogMessage("Value of %s: %i", arg2, value);
    86 
    87 	CloseHandle(strct);
    88 
    89 	return Plugin_Handled;
    90 }
    91 
    92 public Action:Command_SetInt(args)
    93 {
    94 	if (args != 3)
    95 	{
    96 		ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
    97 		return Plugin_Handled;
    98 	}
    99 
   100 	decl String:arg1[32], String:arg2[32], String:value[32];
   101 	GetCmdArg(1, arg1, sizeof(arg1));
   102 	GetCmdArg(2, arg2, sizeof(arg2));
   103 	GetCmdArg(3, value, sizeof(value));
   104 
   105 	new Handle:strct = GetWeaponStruct(arg1);
   106 	SetStructInt(strct, arg2, StringToInt(value));
   107 
   108 
   109 	CloseHandle(strct);
   110 
   111 	return Plugin_Handled;
   112 }
   113 
   114 public Action:Command_GetFloat(args)
   115 {
   116 	if (args != 2)
   117 	{
   118 		ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
   119 		return Plugin_Handled;
   120 	}
   121 
   122 	decl String:arg1[32], String:arg2[32];
   123 	GetCmdArg(1, arg1, sizeof(arg1));
   124 	GetCmdArg(2, arg2, sizeof(arg2));
   125 
   126 	new Handle:strct = GetWeaponStruct(arg1);
   127 	new Float:value = GetStructFloat(strct, arg2);
   128 
   129 	LogMessage("Value of %s: %f", arg2, value);
   130 
   131 	CloseHandle(strct);
   132 
   133 	return Plugin_Handled;
   134 }
   135 
   136 public Action:Command_SetFloat(args)
   137 {
   138 	if (args != 3)
   139 	{
   140 		ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
   141 		return Plugin_Handled;
   142 	}
   143 
   144 	decl String:arg1[32], String:arg2[32], String:value[32];
   145 	GetCmdArg(1, arg1, sizeof(arg1));
   146 	GetCmdArg(2, arg2, sizeof(arg2));
   147 	GetCmdArg(3, value, sizeof(value));
   148 
   149 	new Handle:strct = GetWeaponStruct(arg1);
   150 	SetStructFloat(strct, arg2, StringToFloat(value));
   151 
   152 
   153 	CloseHandle(strct);
   154 
   155 	return Plugin_Handled;
   156 }