added iplayerinfo natives

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40664
This commit is contained in:
Borja Ferrer 2007-03-28 23:35:12 +00:00
parent 22dd1ba592
commit daeb5a7dba
3 changed files with 355 additions and 2 deletions

View File

@ -520,7 +520,7 @@ void CPlayer::SetName(const char *name)
const char *CPlayer::GetName()
{
return m_Name.c_str();
return (m_Info) ? m_Info->GetName(): m_Name.c_str();
}
const char *CPlayer::GetIPAddress()

View File

@ -391,6 +391,252 @@ static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
return pInfo->GetTeamIndex();
}
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
return pInfo->GetFragCount();
}
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
return pInfo->GetDeathCount();
}
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
return pInfo->GetArmorValue();
}
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
cell_t *pVec;
pContext->LocalToPhysAddr(params[2], &pVec);
Vector vec = pInfo->GetAbsOrigin();
pVec[0] = sp_ftoc(vec.x);
pVec[1] = sp_ftoc(vec.y);
pVec[2] = sp_ftoc(vec.z);
return 1;
}
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
cell_t *pAng;
pContext->LocalToPhysAddr(params[2], &pAng);
QAngle ang = pInfo->GetAbsAngles();
pAng[0] = sp_ftoc(ang.x);
pAng[1] = sp_ftoc(ang.y);
pAng[2] = sp_ftoc(ang.z);
return 1;
}
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
cell_t *pVec;
pContext->LocalToPhysAddr(params[2], &pVec);
Vector vec = pInfo->GetPlayerMins();
pVec[0] = sp_ftoc(vec.x);
pVec[1] = sp_ftoc(vec.y);
pVec[2] = sp_ftoc(vec.z);
return 1;
}
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
cell_t *pVec;
pContext->LocalToPhysAddr(params[2], &pVec);
Vector vec = pInfo->GetPlayerMaxs();
pVec[0] = sp_ftoc(vec.x);
pVec[1] = sp_ftoc(vec.y);
pVec[2] = sp_ftoc(vec.z);
return 1;
}
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetWeaponName(), NULL);
return 1;
}
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetModelName(), NULL);
return 1;
}
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsInGame()) {
return pContext->ThrowNativeError("Player %d is not in game", client);
}
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
if (!pInfo)
{
return pContext->ThrowNativeError("IPlayerInfo not supported by game");
}
return pInfo->GetHealth();
}
REGISTER_NATIVES(playernatives)
{
{"AddUserFlags", AddUserFlags},
@ -412,6 +658,15 @@ REGISTER_NATIVES(playernatives)
{"RemoveUserFlags", RemoveUserFlags},
{"SetUserAdmin", SetUserAdmin},
{"SetUserFlagBits", SetUserFlagBits},
{"GetClientDeaths", GetDeathCount},
{"GetClientFrags", GetFragCount},
{"GetClientArmor", GetArmorValue},
{"GetClientAbsOrigin", GetAbsOrigin},
{"GetClientAbsAngles", GetAbsAngles},
{"GetClientMins", GetPlayerMins},
{"GetClientMaxs", GetPlayerMaxs},
{"GetClientWeapon", GetWeaponName},
{"GetClientModel", GetModelName},
{"GetClientHealth", GetHealth},
{NULL, NULL}
};

View File

@ -282,3 +282,101 @@ native CreateFakeClient(const String:name[]);
* or client not a fake client.
*/
native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
/**
* Returns the client's health.
*
* @param client Player's index.
* @return Health value.
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientHealth(client);
/**
* Returns the client's model name.
*
* @param client Player's index.
* @param model Buffer to store the client's model name.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientModel(client, String:model[], maxlen);
/**
* Returns the client's weapon name.
*
* @param client Player's index.
* @param weapon Buffer to store the client's weapon name.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientWeapon(client, String:weapon[], maxlen);
/**
* Returns the client's max size vector.
*
* @param client Player's index.
* @param vec Destination vector to store the client's max size.
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientMaxs(client, Float:vec[3]);
/**
* Returns the client's min size vector.
*
* @param client Player's index.
* @param vec Destination vector to store the client's min size.
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientMins(client, Float:vec[3]);
/**
* Returns the client's position angle.
*
* @param client Player's index.
* @param ang Destination vector to store the client's position angle.
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientAbsAngles(client, Float:ang[3]);
/**
* Returns the client's origin vector.
*
* @param client Player's index.
* @param vec Destination vector to store the client's origin vector.
* @noreturn
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientAbsOrigin(client, Float:vec[3]);
/**
* Returns the client's armor.
*
* @param client Player's index.
* @return Armor value.
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientArmor(client);
/**
* Returns the client's death count.
*
* @param client Player's index.
* @return Death count.
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientDeaths(client);
/**
* Returns the client's frag count.
*
* @param client Player's index.
* @return Frag count.
* @error Invalid client index, client not in game, or no mod support.
*/
native GetClientFrags(client);