1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/testsuite/structtest.sp Thu Sep 18 15:32:22 2008 +1200
1.3 @@ -0,0 +1,156 @@
1.4 +#include <sourcemod>
1.5 +#include "structs.inc"
1.6 +
1.7 +public Plugin:myinfo =
1.8 +{
1.9 + name = "Struct Abstraction Test",
1.10 + author = "pRED*",
1.11 + description = "",
1.12 + version = "1.0",
1.13 + url = "http://www.sourcemod.net/"
1.14 +};
1.15 +
1.16 +public OnPluginStart()
1.17 +{
1.18 + RegServerCmd("sm_getstructstring", Command_GetString);
1.19 + RegServerCmd("sm_setstructstring", Command_SetString);
1.20 +
1.21 + RegServerCmd("sm_getstructint", Command_GetInt);
1.22 + RegServerCmd("sm_setstructint", Command_SetInt);
1.23 +
1.24 + RegServerCmd("sm_getstructfloat", Command_GetFloat);
1.25 + RegServerCmd("sm_setstructfloat", Command_SetFloat);
1.26 +
1.27 +}
1.28 +
1.29 +public Action:Command_GetString(args)
1.30 +{
1.31 + if (args != 2)
1.32 + {
1.33 + ReplyToCommand(0, "[SM] Usage: sm_getstructstring <struct> <string>");
1.34 + return Plugin_Handled;
1.35 + }
1.36 +
1.37 + decl String:arg1[32], String:arg2[32], String:value[32];
1.38 + GetCmdArg(1, arg1, sizeof(arg1));
1.39 + GetCmdArg(2, arg2, sizeof(arg2));
1.40 +
1.41 + new Handle:strct = GetWeaponStruct(arg1);
1.42 + GetStructString(strct, arg2, value, sizeof(value));
1.43 +
1.44 + LogMessage("Value of %s: %s", arg2, value);
1.45 +
1.46 + CloseHandle(strct);
1.47 +
1.48 + return Plugin_Handled;
1.49 +}
1.50 +
1.51 +public Action:Command_SetString(args)
1.52 +{
1.53 + if (args != 3)
1.54 + {
1.55 + ReplyToCommand(0, "[SM] Usage: sm_setstructstring <struct> <string> <value>");
1.56 + return Plugin_Handled;
1.57 + }
1.58 +
1.59 + decl String:arg1[32], String:arg2[32], String:value[32];
1.60 + GetCmdArg(1, arg1, sizeof(arg1));
1.61 + GetCmdArg(2, arg2, sizeof(arg2));
1.62 + GetCmdArg(3, value, sizeof(value));
1.63 +
1.64 + new Handle:strct = GetWeaponStruct(arg1);
1.65 + SetStructString(strct, arg2, value);
1.66 +
1.67 + CloseHandle(strct);
1.68 +
1.69 + return Plugin_Handled;
1.70 +
1.71 +}
1.72 +
1.73 +public Action:Command_GetInt(args)
1.74 +{
1.75 + if (args != 2)
1.76 + {
1.77 + ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
1.78 + return Plugin_Handled;
1.79 + }
1.80 +
1.81 + decl String:arg1[32], String:arg2[32];
1.82 + GetCmdArg(1, arg1, sizeof(arg1));
1.83 + GetCmdArg(2, arg2, sizeof(arg2));
1.84 +
1.85 + new Handle:strct = GetWeaponStruct(arg1);
1.86 + new value = GetStructInt(strct, arg2);
1.87 +
1.88 + LogMessage("Value of %s: %i", arg2, value);
1.89 +
1.90 + CloseHandle(strct);
1.91 +
1.92 + return Plugin_Handled;
1.93 +}
1.94 +
1.95 +public Action:Command_SetInt(args)
1.96 +{
1.97 + if (args != 3)
1.98 + {
1.99 + ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
1.100 + return Plugin_Handled;
1.101 + }
1.102 +
1.103 + decl String:arg1[32], String:arg2[32], String:value[32];
1.104 + GetCmdArg(1, arg1, sizeof(arg1));
1.105 + GetCmdArg(2, arg2, sizeof(arg2));
1.106 + GetCmdArg(3, value, sizeof(value));
1.107 +
1.108 + new Handle:strct = GetWeaponStruct(arg1);
1.109 + SetStructInt(strct, arg2, StringToInt(value));
1.110 +
1.111 +
1.112 + CloseHandle(strct);
1.113 +
1.114 + return Plugin_Handled;
1.115 +}
1.116 +
1.117 +public Action:Command_GetFloat(args)
1.118 +{
1.119 + if (args != 2)
1.120 + {
1.121 + ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
1.122 + return Plugin_Handled;
1.123 + }
1.124 +
1.125 + decl String:arg1[32], String:arg2[32];
1.126 + GetCmdArg(1, arg1, sizeof(arg1));
1.127 + GetCmdArg(2, arg2, sizeof(arg2));
1.128 +
1.129 + new Handle:strct = GetWeaponStruct(arg1);
1.130 + new Float:value = GetStructFloat(strct, arg2);
1.131 +
1.132 + LogMessage("Value of %s: %f", arg2, value);
1.133 +
1.134 + CloseHandle(strct);
1.135 +
1.136 + return Plugin_Handled;
1.137 +}
1.138 +
1.139 +public Action:Command_SetFloat(args)
1.140 +{
1.141 + if (args != 3)
1.142 + {
1.143 + ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
1.144 + return Plugin_Handled;
1.145 + }
1.146 +
1.147 + decl String:arg1[32], String:arg2[32], String:value[32];
1.148 + GetCmdArg(1, arg1, sizeof(arg1));
1.149 + GetCmdArg(2, arg2, sizeof(arg2));
1.150 + GetCmdArg(3, value, sizeof(value));
1.151 +
1.152 + new Handle:strct = GetWeaponStruct(arg1);
1.153 + SetStructFloat(strct, arg2, StringToFloat(value));
1.154 +
1.155 +
1.156 + CloseHandle(strct);
1.157 +
1.158 + return Plugin_Handled;
1.159 +}