Added array element selection with Get/SetEntProp* on arrays (bug 4160, r=fyren).
This commit is contained in:
+31
-10
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* SourceMod (C)2004-2011 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
@@ -504,10 +504,11 @@ stock GetEntSendPropOffs(ent, const String:prop[], bool:actual=false)
|
||||
* @param size Number of bytes to write (valid values are 1, 2, or 4).
|
||||
* This value is auto-detected, and the size parameter is
|
||||
* only used as a fallback in case detection fails.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @return Value at the given property offset.
|
||||
* @error Invalid entity or property not found.
|
||||
*/
|
||||
native GetEntProp(entity, PropType:type, const String:prop[], size=4);
|
||||
native GetEntProp(entity, PropType:type, const String:prop[], size=4, element=0);
|
||||
|
||||
/**
|
||||
* Sets an integer value in an entity's property.
|
||||
@@ -518,13 +519,15 @@ native GetEntProp(entity, PropType:type, const String:prop[], size=4);
|
||||
* @param entity Entity/edict index.
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param value Value to set.
|
||||
* @param size Number of bytes to write (valid values are 1, 2, or 4).
|
||||
* This value is auto-detected, and the size parameter is
|
||||
* only used as a fallback in case detection fails.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @error Invalid entity or offset out of reasonable bounds.
|
||||
* @noreturn
|
||||
*/
|
||||
native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4);
|
||||
native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4, element=0);
|
||||
|
||||
/**
|
||||
* Retrieves a float value from an entity's property.
|
||||
@@ -535,10 +538,11 @@ native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4)
|
||||
* @param entity Entity/edict index.
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @return Value at the given property offset.
|
||||
* @error Invalid entity or offset out of reasonable bounds.
|
||||
*/
|
||||
native Float:GetEntPropFloat(entity, PropType:type, const String:prop[]);
|
||||
native Float:GetEntPropFloat(entity, PropType:type, const String:prop[], element=0);
|
||||
|
||||
/**
|
||||
* Sets a float value in an entity's property.
|
||||
@@ -550,10 +554,11 @@ native Float:GetEntPropFloat(entity, PropType:type, const String:prop[]);
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param value Value to set.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @noreturn
|
||||
* @error Invalid entity or offset out of reasonable bounds.
|
||||
*/
|
||||
native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value);
|
||||
native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value, element=0);
|
||||
|
||||
/**
|
||||
* Retrieves an entity index from an entity's property.
|
||||
@@ -564,12 +569,13 @@ native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value);
|
||||
* @param entity Entity/edict index.
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @return Entity index at the given property.
|
||||
* If there is no entity, or the entity is not valid,
|
||||
* then -1 is returned.
|
||||
* @error Invalid entity or offset out of reasonable bounds.
|
||||
*/
|
||||
native GetEntPropEnt(entity, PropType:type, const String:prop[]);
|
||||
native GetEntPropEnt(entity, PropType:type, const String:prop[], element=0);
|
||||
|
||||
/**
|
||||
* Sets an entity index in an entity's property.
|
||||
@@ -581,10 +587,11 @@ native GetEntPropEnt(entity, PropType:type, const String:prop[]);
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param other Entity index to set, or -1 to unset.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @noreturn
|
||||
* @error Invalid entity or offset out of reasonable bounds.
|
||||
*/
|
||||
native SetEntPropEnt(entity, PropType:type, const String:prop[], other);
|
||||
native SetEntPropEnt(entity, PropType:type, const String:prop[], other, element=0);
|
||||
|
||||
/**
|
||||
* Retrieves a vector of floats from an entity, given a named network property.
|
||||
@@ -596,11 +603,12 @@ native SetEntPropEnt(entity, PropType:type, const String:prop[], other);
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param vec Vector buffer to store data in.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @noreturn
|
||||
* @error Invalid entity, property not found, or property not
|
||||
* actually a vector data type.
|
||||
*/
|
||||
native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]);
|
||||
native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3], element=0);
|
||||
|
||||
/**
|
||||
* Sets a vector of floats in an entity, given a named network property.
|
||||
@@ -612,11 +620,12 @@ native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @param vec Vector to set.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @noreturn
|
||||
* @error Invalid entity, property not found, or property not
|
||||
* actually a vector data type.
|
||||
*/
|
||||
native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3]);
|
||||
native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3], element=0);
|
||||
|
||||
/**
|
||||
* Gets a network property as a string.
|
||||
@@ -626,10 +635,11 @@ native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:
|
||||
* @param prop Property to use.
|
||||
* @param buffer Destination string buffer.
|
||||
* @param maxlen Maximum length of output string buffer.
|
||||
* @param element Element # (starting from 0) if property is an array.
|
||||
* @return Number of non-null bytes written.
|
||||
* @error Invalid entity, offset out of reasonable bounds, or property is not a valid string.
|
||||
*/
|
||||
native GetEntPropString(entity, PropType:type, const String:prop[], String:buffer[], maxlen);
|
||||
native GetEntPropString(entity, PropType:type, const String:prop[], String:buffer[], maxlen, element=0);
|
||||
|
||||
/**
|
||||
* Sets a network property as a string.
|
||||
@@ -646,6 +656,17 @@ native GetEntPropString(entity, PropType:type, const String:prop[], String:buffe
|
||||
*/
|
||||
native SetEntPropString(entity, PropType:type, const String:prop[], const String:buffer[]);
|
||||
|
||||
/**
|
||||
* Retrieves the count of values that an entity property's array can store.
|
||||
*
|
||||
* @param entity Entity/edict index.
|
||||
* @param type Property type.
|
||||
* @param prop Property name.
|
||||
* @return Size of array (in elements) or 1 if property is not an array.
|
||||
* @error Invalid entity or property not found.
|
||||
*/
|
||||
native GetEntPropArraySize(entity, PropType:type, const String:prop[]);
|
||||
|
||||
/**
|
||||
* Copies an array of cells from an entity at a given offset.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
|
||||
// Coverage:
|
||||
// GetEntPropArraySize - PropSend/PropData
|
||||
|
||||
// GetEntPropString - PropData
|
||||
|
||||
// GetEntProp - PropSend/PropData
|
||||
// GetEntPropEnt - PropSend/PropData
|
||||
|
||||
// SetEntProp - PropSend/PropData
|
||||
|
||||
public OnPluginStart()
|
||||
{
|
||||
RegConsoleCmd("sm_listammo", sm_listammo, "sm_listammo <send|data> [target] - Lists current ammo for self or specified player");
|
||||
RegConsoleCmd("sm_listweapons", sm_listweapons, "sm_listweapons <send|data> [target] - Lists current weapons for self or specified player");
|
||||
RegConsoleCmd("sm_setammo", sm_setammo, "sm_setammo <ammotype> <amount> <send|data> [target]");
|
||||
RegConsoleCmd("sm_teststrings", sm_teststrings);
|
||||
}
|
||||
|
||||
public Action:sm_listammo(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 2)
|
||||
{
|
||||
GetCmdArg(2, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(1, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new ammo;
|
||||
new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
|
||||
for (new i = 0; i < max; i++)
|
||||
{
|
||||
if ((ammo = GetEntProp(target, proptype, "m_iAmmo", _, i)) > 0)
|
||||
ReplyToCommand(client, "Slot %d, Ammo %d", i, ammo);
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_listweapons(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 2)
|
||||
{
|
||||
GetCmdArg(2, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(1, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new weapon, String:classname[64];
|
||||
new max = GetEntPropArraySize(target, proptype, "m_hMyWeapons");
|
||||
for (new i = 0; i < max; i++)
|
||||
{
|
||||
if ((weapon = GetEntPropEnt(target, proptype, "m_hMyWeapons", i)) == -1)
|
||||
continue;
|
||||
|
||||
GetEdictClassname(weapon, classname, sizeof(classname));
|
||||
ReplyToCommand(client, "Slot %d - \"%s\"", i, classname);
|
||||
}
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_setammo(client, argc)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
new target = client;
|
||||
if (argc >= 4)
|
||||
{
|
||||
GetCmdArg(4, buffer, sizeof(buffer));
|
||||
target = FindTarget(client, buffer, false, false);
|
||||
if (target <= 0)
|
||||
{
|
||||
ReplyToCommand(client, "Bad client");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
else if (client == 0)
|
||||
{
|
||||
ReplyToCommand(client, "Dillweed");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
new PropType:proptype = PropType:-1;
|
||||
GetCmdArg(3, buffer, sizeof(buffer));
|
||||
if (!strcmp(buffer, "send"))
|
||||
proptype = Prop_Send;
|
||||
else if (!strcmp(buffer, "data"))
|
||||
proptype = Prop_Data;
|
||||
|
||||
new max = GetEntPropArraySize(target, proptype, "m_iAmmo");
|
||||
|
||||
GetCmdArg(1, buffer, sizeof(buffer));
|
||||
new ammotype = StringToInt(buffer);
|
||||
|
||||
if (ammotype >= max)
|
||||
{
|
||||
ReplyToCommand(client, "Ammotype out of bounds");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
GetCmdArg(2, buffer, sizeof(buffer));
|
||||
new amount = StringToInt(buffer);
|
||||
|
||||
SetEntProp(target, proptype, "m_iAmmo", amount, _, ammotype);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:sm_teststrings(client, argc)
|
||||
{
|
||||
new gpe = CreateEntityByName("game_player_equip");
|
||||
DispatchKeyValue(gpe, "tf_weapon_rocketlauncher", "2");
|
||||
DispatchKeyValue(gpe, "tf_weapon_pistol", "1");
|
||||
|
||||
decl String:value[64];
|
||||
for (new i = 0; i < 2; i++)
|
||||
{
|
||||
GetEntPropString(gpe, Prop_Data, "m_weaponNames", value, sizeof(value), i);
|
||||
ReplyToCommand(client, "At %d, I see a \"%s\"", i, value);
|
||||
}
|
||||
|
||||
AcceptEntityInput(gpe, "Kill");
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
Reference in New Issue
Block a user