Added Struct Abstraction extension (bug 2666 and bug 2663)
--HG-- rename : extensions/structs/structs.txt => gamedata/structs.gamedata.txt rename : extensions/structs/structs.inc => plugins/include/structs.inc rename : extensions/structs/structtest.sp => plugins/testsuite/structtest.sp
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#if defined _structs_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _structs_included
|
||||
|
||||
/**
|
||||
* Struct Gamedata Notes:
|
||||
*
|
||||
* Types: Sizes:
|
||||
* int/int* 1/2/4
|
||||
* float/float* Not required
|
||||
* char/char* Length of char array
|
||||
* Vector/Vector* Not required
|
||||
* ent/ent* Not required
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieves an integer value from a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to retrieve.
|
||||
* @return Integer value.
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native GetStructInt(Handle:strct, const String:member[]);
|
||||
|
||||
/**
|
||||
* Sets an integer value in a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to set.
|
||||
* @param value Value to set.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native SetStructInt(Handle:strct, const String:member[], value);
|
||||
|
||||
/**
|
||||
* Retrieves a float value from a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to retrieve.
|
||||
* @return Float value.
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native Float:GetStructFloat(Handle:strct, const String:member[]);
|
||||
|
||||
/**
|
||||
* Sets a float value in a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to set.
|
||||
* @param value Value to set.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native SetStructFloat(Handle:strct, const String:member[], Float:value);
|
||||
|
||||
/**
|
||||
* Retrieves an integer value from a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to retrieve.
|
||||
* @param vec Buffer for the retrieved vector.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native GetStructVector(Handle:strct, const String:member[], Float:vec[3]);
|
||||
|
||||
/**
|
||||
* Sets a Vector value in a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to set.
|
||||
* @param vec Value to set.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native SetStructVector(Handle:strct, const String:member[], Float:vec[3]);
|
||||
|
||||
/**
|
||||
* Retrieves a string from a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to retrieve.
|
||||
* @param value Buffer for the retrieved string.
|
||||
* @param maxlen Max length of the buffer
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native GetStructString(Handle:strct, const String:member[], const String:value[], maxlen);
|
||||
|
||||
/**
|
||||
* Sets a string value in a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to set.
|
||||
* @param value Value to set.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native SetStructString(Handle:strct, const String:member[], String:value[]);
|
||||
|
||||
/**
|
||||
* Retrieves an entity handle from a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to retrieve.
|
||||
* @return Entity index.
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native GetStructEnt(Handle:strct, const String:member[]);
|
||||
|
||||
/**
|
||||
* Sets an entity handle value in a struct.
|
||||
*
|
||||
* @param strct Struct Handle.
|
||||
* @param member Member name to set.
|
||||
* @param entity Entity index to set.
|
||||
* @noreturn
|
||||
* @error Undefined member, or member type mismatch.
|
||||
*/
|
||||
native SetStructEnt(Handle:strct, const String:member[], entity);
|
||||
|
||||
/**
|
||||
* Retrieves a struct handle to a FileWeaponInfo_t for the given weapon name.
|
||||
* This handle needs to be closed when you have finished using it.
|
||||
*
|
||||
* @param weapon Weapon name to retrieve.
|
||||
* @return Struct handle or INVALID_HANDLE on failure.
|
||||
*/
|
||||
native Handle:GetWeaponStruct(const String:weapon[]);
|
||||
|
||||
/**
|
||||
* Do not edit below this line!
|
||||
*/
|
||||
public Extension:__ext_struct =
|
||||
{
|
||||
name = "Struct Abstraction Extension",
|
||||
file = "structs.ext",
|
||||
autoload = 1,
|
||||
#if defined REQUIRE_EXTENSIONS
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
#include <sourcemod>
|
||||
#include "structs.inc"
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Struct Abstraction Test",
|
||||
author = "pRED*",
|
||||
description = "",
|
||||
version = "1.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegServerCmd("sm_getstructstring", Command_GetString);
|
||||
RegServerCmd("sm_setstructstring", Command_SetString);
|
||||
|
||||
RegServerCmd("sm_getstructint", Command_GetInt);
|
||||
RegServerCmd("sm_setstructint", Command_SetInt);
|
||||
|
||||
RegServerCmd("sm_getstructfloat", Command_GetFloat);
|
||||
RegServerCmd("sm_setstructfloat", Command_SetFloat);
|
||||
|
||||
}
|
||||
|
||||
public Action:Command_GetString(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructstring <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
GetStructString(strct, arg2, value, sizeof(value));
|
||||
|
||||
LogMessage("Value of %s: %s", arg2, value);
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetString(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructstring <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructString(strct, arg2, value);
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
|
||||
}
|
||||
|
||||
public Action:Command_GetInt(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
new value = GetStructInt(strct, arg2);
|
||||
|
||||
LogMessage("Value of %s: %i", arg2, value);
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetInt(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructInt(strct, arg2, StringToInt(value));
|
||||
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_GetFloat(args)
|
||||
{
|
||||
if (args != 2)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_getstructint <struct> <string>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
new Float:value = GetStructFloat(strct, arg2);
|
||||
|
||||
LogMessage("Value of %s: %f", arg2, value);
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Command_SetFloat(args)
|
||||
{
|
||||
if (args != 3)
|
||||
{
|
||||
ReplyToCommand(0, "[SM] Usage: sm_setstructint <struct> <string> <value>");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
decl String:arg1[32], String:arg2[32], String:value[32];
|
||||
GetCmdArg(1, arg1, sizeof(arg1));
|
||||
GetCmdArg(2, arg2, sizeof(arg2));
|
||||
GetCmdArg(3, value, sizeof(value));
|
||||
|
||||
new Handle:strct = GetWeaponStruct(arg1);
|
||||
SetStructFloat(strct, arg2, StringToFloat(value));
|
||||
|
||||
|
||||
CloseHandle(strct);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
Reference in New Issue
Block a user