5 name = "Function Call Testing Lab",
6 author = "AlliedModders LLC",
7 description = "Tests basic function calls",
9 url = "http://www.sourcemod.net/"
12 public OnPluginStart()
14 RegServerCmd("test_callfunc", Command_CallFunc);
17 public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
19 PrintToServer("Inside OnCallFuncReceived...");
21 PrintToServer("num = %d (expected: %d)", num, 5);
22 PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
23 PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
24 PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
26 PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
29 PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
32 PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
33 for (new i = 0; i < size; i++)
35 PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
37 for (new i = 0; i < size; i++)
39 PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
42 /* This shouldn't get copied back */
43 StrCopy(str, strlen(str) + 1, "Yeti");
44 /* This should get copied back */
45 StrCopy(str2, strlen(str2) + 1, "Gaben is fat.");
47 /* This should get copied back */
50 /* This shouldn't get copied back */
56 public Action:Command_CallFunc(args)
60 new const String:what[] = "Gaben";
61 new String:truth[] = ".taf si nebaG";
62 new hello[] = {0, 1, 2, 3, 4, 5};
68 new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived");
70 if (func == INVALID_FUNCTION)
72 PrintToServer("Failed to get the function id of OnCallFuncReceived");
73 return Plugin_Handled;
76 PrintToServer("Calling OnCallFuncReceived...");
78 Call_StartFunction(INVALID_HANDLE, func);
81 Call_PushString(what);
82 Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
85 Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
86 Call_PushArray(hello, pm);
88 Call_PushArray(hello2, 1);
89 err = Call_Finish(ret);
91 PrintToServer("Call to OnCallFuncReceived has finished!");
92 PrintToServer("Error code = %d (expected: %d)", err, 0);
93 PrintToServer("Return value = %d (expected: %d)", ret, 42);
95 PrintToServer("a = %d (expected: %d)", a, 15);
96 PrintToServer("b = %f (expected: %f)", b, 1.5);
97 PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
98 PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
99 PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
100 PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
101 PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
103 return Plugin_Handled;