PDA

View Full Version : delete it please.


vingbbit
01-05-2012, 04:32
[solved]

I'm making human class test suites for my zombie mod.
It similar AMXX ZP5.0 human class.
Made it and take test. But it isn't work well.
I don't know the problem.

It's Header.

/**
* Register human class.
*
* @param name Class name to register
*/
native ZP_RegisterHumanClass(const String:name[]);

/**
* Get the human class index
*
* @param name The class name to find class
*/
native ZP_GetHumanClassID(const String:name[]);

/**
* Get the human class name
*
* @param classid Internal class index
* @param classname The class name
*/
native ZP_GetHumanClassName(classid, const String:classname[]);

/**
* Display the class menu to human
*
* @param client Client index
*/
native ZP_DisplayHumanClass(client);

/**
* Call before client select the class
*
* @param client Client index
* @param classid Internal class index
*/
forward Action:ZP_OnClassSelect_Pre(&client, &classid);

/**
* Call after client select the class
*
* @param client Client index
* @param classid Internal class index
*/
forward ZP_OnClassSelect_Post(client, classid);




and It's API processor (natives and forwards)

#include <sourcemod>
#include <cstrike>
#include <classapi>

#pragma semicolon 1

#define ZP_INVALID_HUMAN_CLASS -1

/**
* @section Forward Line
*/
enum FWD
{
Handle:OnHumanClassSelect_Pre,
Handle:OnHumanClassSelect_Post
}
new g_hAPI[FWD];
/**
* @endsection
*/

/**
* @section Dynamic Array Line
*/
new Handle:g_hArrayClassName = INVALID_HANDLE;
/**
* @endsection
*/

new Handle:hMenuHumanClass = INVALID_HANDLE;

new g_iHumanClassCount; // is count of human class to use registering class.

public Plugin:myinfo =
{
name = "Player Class API Processor",
author = "Vingbbit",
description = "Add classes from external plugins and attach it to human races in CS:S",
version = "0.0.1",
url = "http://cafe.naver.com/vunit"
}

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("ZP_RegisterHumanClass", NativeRegisterHumanClass);
CreateNative("ZP_GetHumanClassID", NativeGetHumanClassID);
CreateNative("ZP_GetHumanClassName", NativeGetHumanClassName);
CreateNative("ZP_DisplayHumanClass", NativeDisplayHumanClass);

g_hAPI[OnHumanClassSelect_Pre] = CreateGlobalForward("ZP_OnClassSelect_Pre", ET_Hook, Param_CellByRef, Param_CellByRef);
g_hAPI[OnHumanClassSelect_Post] = CreateGlobalForward("ZP_OnClassSelect_Post", ET_Ignore, Param_Cell, Param_Cell);

g_hArrayClassName = CreateArray(32, 0);

return APLRes_Success;
}

public OnPluginStart()
{
RegConsoleCmd("sm_humanclass", Command_HumanClass);
PrintToServer(" [Zombie Plague Mod] Player Class API Test for human is loaded");
}

public Action:Command_HumanClass(client, args)
{
if (!IsClientInGame(client)) return Plugin_Handled;
if (!IsPlayerAlive(client)) return Plugin_Handled;

DisplayHumanClass(client);
return Plugin_Continue;
}

public NativeRegisterHumanClass(Handle:plugin, numParams)
{
// get parameter no.1
new String:name[32];
GetNativeString(1, name, sizeof(name));

// Check if the registering name size lower than 1
if (strlen(name) < 1)
{
LogError("Cannot register class '%s'. cause the name length is lower than 1", name);
return ZP_INVALID_HUMAN_CLASS;
}

// Check if the registering class is already added class.
decl String:sAddedClassName[32];
for (new x = 0; x < g_iHumanClassCount; x++)
{
GetArrayString(g_hArrayClassName, x, sAddedClassName, sizeof(sAddedClassName));
if (StrEqual(name, sAddedClassName))
{
LogError("Human class '%s' is already registered", name);
return ZP_INVALID_HUMAN_CLASS;
}
}

// Push string in array.
PushArrayString(g_hArrayClassName, name);

// Increase the class count.
g_iHumanClassCount++;

// Announce this.
PrintToServer("[ZP Human Class] '%s' is registered on human class. the human class count is now %d", name, g_iHumanClassCount);

return g_iHumanClassCount - 1;
}

public NativeGetHumanClassID(Handle:plugin, numParams)
{
// Get parameter no.1
new String:name[32];
GetNativeString(1, name, sizeof(name));

// Loop through every class.
decl String:sAddedClassName[32];
for (new x = 0; x < g_iHumanClassCount; x++)
{
// If the class ID detected then reflect the index.
GetArrayString(g_hArrayClassName, x, sAddedClassName, sizeof(sAddedClassName));
if (StrEqual(name, sAddedClassName))
{
return x;
}
}

// No index founded.
return ZP_INVALID_HUMAN_CLASS;
}

public NativeGetHumanClassName(Handle:plugin, numParams)
{
// Get parameter no.1
new classid = GetNativeCell(1);

// Check validation
if (classid < 0 || classid >= g_iHumanClassCount)
{
return false;
}

// Get parameter no.2
new String:classname[32];
GetNativeString(2, classname, sizeof(classname));

GetArrayString(g_hArrayClassName, classid, classname, sizeof(classname));
return true;
}

public NativeDisplayHumanClass(Handle:plugin, numParams)
{
// Get paramete no.1
new client = GetNativeCell(1);

if (!IsClientConnected(client)) return;
if (!IsClientInGame(client)) return;
if (!IsPlayerAlive(client)) return;

DisplayHumanClass(client);
}

Action:ZPAPI_OnClassSelect_Pre(&client, &classid)
{
Call_StartForward(g_hAPI[OnHumanClassSelect_Pre]);

Call_PushCellRef(client);
Call_PushCellRef(classid);

new Action:result;
Call_Finish(result);
return result;
}

ZPAPI_OnClassSelect_Post(client, classid)
{
Call_StartForward(g_hAPI[OnHumanClassSelect_Post]);

Call_PushCell(client);
Call_PushCell(classid);

Call_Finish();
}

DisplayHumanClass(client)
{
hMenuHumanClass = CreateMenu(Process_HumanClass);
new index;
decl String:classname[32]/*, String:classinfo[2]*/;

for (index = 0; index < g_iHumanClassCount; index++)
{
GetArrayString(g_hArrayClassName, index, classname, sizeof(classname));

new Action:result = ZPAPI_OnClassSelect_Pre(client, index);
if (result == Plugin_Stop)
{
PrintToServer("[DISPLAY HUMAN CLASS MENU: ERROR] SOME PLUGIN RETURNS Plugin_Stop");
continue;
}

if (GetClientTeam(client) != CS_TEAM_CT)
{
PrintToServer("[DISPLAY HUMAN CLASS MENU: ERROR] PLAYER IS NOT COUNTER-TERRORIST TEAM");
continue;
}

AddMenuItem(hMenuHumanClass, "", classname);
}

if (GetMenuItemCount(hMenuHumanClass) <= 0)
{
PrintToChat(client, "\x05[ZP] \x03No displayable human class :(");
return;
}

SetMenuExitButton(hMenuHumanClass, true);
SetMenuTitle(hMenuHumanClass, "[Zombie Plague Mod] Human Classes");
DisplayMenu(hMenuHumanClass, client, MENU_TIME_FOREVER);
}

public Process_HumanClass(Handle:menu, MenuAction:action, client, slot)
{
if (action == MenuAction_End) CloseHandle(hMenuHumanClass);

AttachClassToPlayer(client, slot);

if (action == MenuAction_Select) return;
}

AttachClassToPlayer(client, classid)
{
ZPAPI_OnClassSelect_Pre(client, classid);
if (result != Plugin_Continue)
{
PrintToServer("[HUMAN CLASS: ERROR] SOME PLGUIN RETURNS Plugin_Stop / Plugin_Handled ON AttachClassToPlayer");
return;
}

ZPAPI_OnClassSelect_Post(client, classid);
}



and It's sample class plugin texts. (filename: zp_class_raptor_human.sp)

#include <sourcemod>
#include <classapi>

#define CLASS_NAME "Raptor Human"

new g_iClass;

public Plugin:myinfo =
{
name = "Class; Raptor Human",
author = "Vingbbit",
description = "Raptor Human",
version = "1.0",
url = "<- URL ->"
}

public OnPluginStart()
{
ZP_RegisterHumanClass(CLASS_NAME);

RegConsoleCmd("sm_raptoris", Command_RaptorIs);
}

public Action:Command_RaptorIs(client, args)
{
g_iClass = ZP_GetHumanClassID(CLASS_NAME);
PrintToChat(client, "[ZP] Raptor Human index is %d", g_iClass);
}

public Action:ZP_OnClassSelect_Pre(&client, &classid)
{
g_iClass = ZP_GetHumanClassID(CLASS_NAME);
if (classid == g_iClass)
{
return Plugin_Continue;
}

else
{
PrintToServer("[ZP] T^T Raptor Human Class Index isn't match classid parameter. (Pre)");
return Plugin_Handled;
}
}

public ZP_OnClassSelect_Post(client, classid)
{
if (g_iClass != classid)
{
PrintToServer("[ZP] T^T Raptor Human Class Index isn't match classid parameter. (Post)");
return;
}

PrintToChat(client, "\x05[ZP] \x03You Selected Raptor Human class!");
}



compile is done and put the smx files in my server.
then my server throws this messages.

// api processor smx is loaded.
[Zombie Plague Mod] Player Class API Test for human is loaded

// sub plugins (human classes)
[ZP Human Class] 'Fat Human' is registered on human class. the human class count is now 1
[ZP Human Class] 'Leech Human' is registered on human class. the human class count is now 2
[ZP Human Class] 'Raptor Human' is registered on human class. the human class count is now 3

(ellipsis...)

// On type /humanclass in chat window
// result is following sentences. but Menu is displayed.
[ZP] T^T Leech Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Raptor Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Fat Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Raptor Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Fat Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Leech Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Fat Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Leech Human Class Index isn't match classid parameter. (Pre)

// Select 'Raptor Human' in menu. Then I can see this errors.
// Can't continue.
[HUMAN CLASS: ERROR] SOME PLGUIN RETURNS Plugin_Stop / Plugin_Handled ON AttachC
lassToPlayer
[ZP] T^T Leech Human Class Index isn't match classid parameter. (Pre)
[ZP] T^T Raptor Human Class Index isn't match classid parameter. (Pre)
[HUMAN CLASS: ERROR] SOME PLGUIN RETURNS Plugin_Stop / Plugin_Handled ON AttachClassToPlayer


Now I feel huge pain in head.
Anyone can help me? :cry:



--------------------------------------------------------------------------------
SORRY FOR MY BAD ENGLISH