core/smn_player.cpp
changeset 658 b46ff98c249b
parent 653 ef60870067ff
child 682 a70055d6d3b3
     1.1 --- a/core/smn_player.cpp	Wed Mar 28 20:28:42 2007 +0000
     1.2 +++ b/core/smn_player.cpp	Wed Mar 28 23:35:12 2007 +0000
     1.3 @@ -391,6 +391,252 @@
     1.4  	return pInfo->GetTeamIndex();
     1.5  }
     1.6  
     1.7 +static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	int client = params[1];
    1.10 +
    1.11 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.12 +	if (!pPlayer)
    1.13 +	{
    1.14 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
    1.15 +	} else if (!pPlayer->IsInGame()) {
    1.16 +		return pContext->ThrowNativeError("Player %d is not in game", client);
    1.17 +	}
    1.18 +
    1.19 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
    1.20 +	if (!pInfo)
    1.21 +	{
    1.22 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
    1.23 +	}
    1.24 +
    1.25 +	return pInfo->GetFragCount();
    1.26 +}
    1.27 +
    1.28 +static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
    1.29 +{
    1.30 +	int client = params[1];
    1.31 +
    1.32 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.33 +	if (!pPlayer)
    1.34 +	{
    1.35 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
    1.36 +	} else if (!pPlayer->IsInGame()) {
    1.37 +		return pContext->ThrowNativeError("Player %d is not in game", client);
    1.38 +	}
    1.39 +
    1.40 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
    1.41 +	if (!pInfo)
    1.42 +	{
    1.43 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
    1.44 +	}
    1.45 +
    1.46 +	return pInfo->GetDeathCount();
    1.47 +}
    1.48 +
    1.49 +static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
    1.50 +{
    1.51 +	int client = params[1];
    1.52 +
    1.53 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.54 +	if (!pPlayer)
    1.55 +	{
    1.56 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
    1.57 +	} else if (!pPlayer->IsInGame()) {
    1.58 +		return pContext->ThrowNativeError("Player %d is not in game", client);
    1.59 +	}
    1.60 +
    1.61 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
    1.62 +	if (!pInfo)
    1.63 +	{
    1.64 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
    1.65 +	}
    1.66 +
    1.67 +	return pInfo->GetArmorValue();
    1.68 +}
    1.69 +
    1.70 +static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
    1.71 +{
    1.72 +	int client = params[1];
    1.73 +
    1.74 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    1.75 +	if (!pPlayer)
    1.76 +	{
    1.77 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
    1.78 +	} else if (!pPlayer->IsInGame()) {
    1.79 +		return pContext->ThrowNativeError("Player %d is not in game", client);
    1.80 +	}
    1.81 +
    1.82 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
    1.83 +	if (!pInfo)
    1.84 +	{
    1.85 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
    1.86 +	}
    1.87 +
    1.88 +	cell_t *pVec;
    1.89 +	pContext->LocalToPhysAddr(params[2], &pVec);
    1.90 +
    1.91 +	Vector vec = pInfo->GetAbsOrigin();
    1.92 +	pVec[0] = sp_ftoc(vec.x);
    1.93 +	pVec[1] = sp_ftoc(vec.y);
    1.94 +	pVec[2] = sp_ftoc(vec.z);
    1.95 +
    1.96 +	return 1;
    1.97 +}
    1.98 +
    1.99 +static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
   1.100 +{
   1.101 +	int client = params[1];
   1.102 +
   1.103 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.104 +	if (!pPlayer)
   1.105 +	{
   1.106 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.107 +	} else if (!pPlayer->IsInGame()) {
   1.108 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.109 +	}
   1.110 +
   1.111 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.112 +	if (!pInfo)
   1.113 +	{
   1.114 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.115 +	}
   1.116 +
   1.117 +	cell_t *pAng;
   1.118 +	pContext->LocalToPhysAddr(params[2], &pAng);
   1.119 +
   1.120 +	QAngle ang = pInfo->GetAbsAngles();
   1.121 +	pAng[0] = sp_ftoc(ang.x);
   1.122 +	pAng[1] = sp_ftoc(ang.y);
   1.123 +	pAng[2] = sp_ftoc(ang.z);
   1.124 +
   1.125 +	return 1;
   1.126 +}
   1.127 +
   1.128 +static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
   1.129 +{
   1.130 +	int client = params[1];
   1.131 +
   1.132 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.133 +	if (!pPlayer)
   1.134 +	{
   1.135 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.136 +	} else if (!pPlayer->IsInGame()) {
   1.137 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.138 +	}
   1.139 +
   1.140 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.141 +	if (!pInfo)
   1.142 +	{
   1.143 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.144 +	}
   1.145 +
   1.146 +	cell_t *pVec;
   1.147 +	pContext->LocalToPhysAddr(params[2], &pVec);
   1.148 +
   1.149 +	Vector vec = pInfo->GetPlayerMins();
   1.150 +	pVec[0] = sp_ftoc(vec.x);
   1.151 +	pVec[1] = sp_ftoc(vec.y);
   1.152 +	pVec[2] = sp_ftoc(vec.z);
   1.153 +
   1.154 +	return 1;
   1.155 +}
   1.156 +
   1.157 +static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
   1.158 +{
   1.159 +	int client = params[1];
   1.160 +
   1.161 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.162 +	if (!pPlayer)
   1.163 +	{
   1.164 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.165 +	} else if (!pPlayer->IsInGame()) {
   1.166 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.167 +	}
   1.168 +
   1.169 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.170 +	if (!pInfo)
   1.171 +	{
   1.172 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.173 +	}
   1.174 +
   1.175 +	cell_t *pVec;
   1.176 +	pContext->LocalToPhysAddr(params[2], &pVec);
   1.177 +
   1.178 +	Vector vec = pInfo->GetPlayerMaxs();
   1.179 +	pVec[0] = sp_ftoc(vec.x);
   1.180 +	pVec[1] = sp_ftoc(vec.y);
   1.181 +	pVec[2] = sp_ftoc(vec.z);
   1.182 +
   1.183 +	return 1;
   1.184 +}
   1.185 +
   1.186 +static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
   1.187 +{
   1.188 +	int client = params[1];
   1.189 +
   1.190 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.191 +	if (!pPlayer)
   1.192 +	{
   1.193 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.194 +	} else if (!pPlayer->IsInGame()) {
   1.195 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.196 +	}
   1.197 +
   1.198 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.199 +	if (!pInfo)
   1.200 +	{
   1.201 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.202 +	}
   1.203 +
   1.204 +	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetWeaponName(), NULL);
   1.205 +
   1.206 +	return 1;
   1.207 +}
   1.208 +
   1.209 +static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
   1.210 +{
   1.211 +	int client = params[1];
   1.212 +
   1.213 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.214 +	if (!pPlayer)
   1.215 +	{
   1.216 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.217 +	} else if (!pPlayer->IsInGame()) {
   1.218 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.219 +	}
   1.220 +
   1.221 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.222 +	if (!pInfo)
   1.223 +	{
   1.224 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.225 +	}
   1.226 +
   1.227 +	pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetModelName(), NULL);
   1.228 +
   1.229 +	return 1;
   1.230 +}
   1.231 +
   1.232 +static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
   1.233 +{
   1.234 +	int client = params[1];
   1.235 +
   1.236 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   1.237 +	if (!pPlayer)
   1.238 +	{
   1.239 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
   1.240 +	} else if (!pPlayer->IsInGame()) {
   1.241 +		return pContext->ThrowNativeError("Player %d is not in game", client);
   1.242 +	}
   1.243 +
   1.244 +	IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
   1.245 +	if (!pInfo)
   1.246 +	{
   1.247 +		return pContext->ThrowNativeError("IPlayerInfo not supported by game");
   1.248 +	}
   1.249 +
   1.250 +	return pInfo->GetHealth();
   1.251 +}
   1.252 +
   1.253  REGISTER_NATIVES(playernatives)
   1.254  {
   1.255  	{"AddUserFlags",			AddUserFlags},
   1.256 @@ -412,6 +658,15 @@
   1.257  	{"RemoveUserFlags",			RemoveUserFlags},
   1.258  	{"SetUserAdmin",			SetUserAdmin},
   1.259  	{"SetUserFlagBits",			SetUserFlagBits},
   1.260 +	{"GetClientDeaths",			GetDeathCount},
   1.261 +	{"GetClientFrags",			GetFragCount},
   1.262 +	{"GetClientArmor",			GetArmorValue},
   1.263 +	{"GetClientAbsOrigin",		GetAbsOrigin},
   1.264 +	{"GetClientAbsAngles",		GetAbsAngles},
   1.265 +	{"GetClientMins",			GetPlayerMins},
   1.266 +	{"GetClientMaxs",			GetPlayerMaxs},
   1.267 +	{"GetClientWeapon",			GetWeaponName},
   1.268 +	{"GetClientModel",			GetModelName},
   1.269 +	{"GetClientHealth",			GetHealth},
   1.270  	{NULL,						NULL}
   1.271  };
   1.272 -