Merge pull request #267 from 50Wliu/tf2_setclientteam

Add TF2_SetClientTeam to provide symmetry to TF2_GetClientTeam (r=psychonic).
This commit is contained in:
Nicholas Hastings 2015-02-24 10:23:23 -05:00
commit b8223d1b98

View File

@ -9,7 +9,7 @@
* This program is free software; you can redistribute it and/or modify it under * 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 * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
@ -262,7 +262,7 @@ enum
TFWeaponSlot_Building, TFWeaponSlot_Building,
TFWeaponSlot_PDA, TFWeaponSlot_PDA,
TFWeaponSlot_Item1, TFWeaponSlot_Item1,
TFWeaponSlot_Item2 TFWeaponSlot_Item2
}; };
// Identifiers for the eventtype property on the teamplay_flag_event event // Identifiers for the eventtype property on the teamplay_flag_event event
@ -279,12 +279,12 @@ enum TFResourceType
TFResource_Ping, TFResource_Ping,
TFResource_Score, TFResource_Score,
TFResource_Deaths, TFResource_Deaths,
TFResource_TotalScore, TFResource_TotalScore,
TFResource_Captures, TFResource_Captures,
TFResource_Defenses, TFResource_Defenses,
TFResource_Dominations, TFResource_Dominations,
TFResource_Revenge, TFResource_Revenge,
TFResource_BuildingsDestroyed, TFResource_BuildingsDestroyed,
TFResource_Headshots, TFResource_Headshots,
TFResource_Backstabs, TFResource_Backstabs,
TFResource_HealPoints, TFResource_HealPoints,
@ -320,7 +320,7 @@ static const String:TFResourceNames[TFResourceType][] =
/** /**
* Gets a client's current team. * Gets a client's current team.
* *
* @param client Client index. * @param client Client index.
* @return Current TFTeam of client. * @return Current TFTeam of client.
* @error Invalid client index. * @error Invalid client index.
@ -330,6 +330,19 @@ stock TFTeam:TF2_GetClientTeam(client)
return TFTeam:GetClientTeam(client); return TFTeam:GetClientTeam(client);
} }
/**
* Changes a client's current team.
*
* @param client Client index.
* @param team TFTeam team symbol.
* @noreturn
* @error Invalid client index.
*/
stock TF2_ChangeClientTeam(client, TFTeam:team)
{
ChangeClientTeam(client, _:team);
}
/** /**
* Gets a client's current class. * Gets a client's current class.
* *
@ -357,7 +370,7 @@ stock TFClassType:TF2_GetPlayerClass(client)
stock TF2_SetPlayerClass(client, TFClassType:classType, bool:weapons=true, bool:persistent=true) stock TF2_SetPlayerClass(client, TFClassType:classType, bool:weapons=true, bool:persistent=true)
{ {
SetEntProp(client, Prop_Send, "m_iClass", _:classType); SetEntProp(client, Prop_Send, "m_iClass", _:classType);
if (persistent) if (persistent)
{ {
SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:classType); SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", _:classType);
@ -377,23 +390,23 @@ stock TF2_GetPlayerResourceData(client, TFResourceType:type)
{ {
if (!IsClientConnected(client)) if (!IsClientConnected(client))
{ {
return -1; return -1;
} }
new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]); new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
if (offset < 1) if (offset < 1)
{ {
return -1; return -1;
} }
new entity = TF2_GetResourceEntity(); new entity = TF2_GetResourceEntity();
if (entity == -1) if (entity == -1)
{ {
return -1; return -1;
} }
return GetEntData(entity, offset + (client*4)); return GetEntData(entity, offset + (client*4));
} }
@ -413,26 +426,26 @@ stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
{ {
if (!IsClientConnected(client)) if (!IsClientConnected(client))
{ {
return false; return false;
} }
new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]); new offset = FindSendPropInfo("CTFPlayerResource", TFResourceNames[type]);
if (offset < 1) if (offset < 1)
{ {
return false; return false;
} }
new entity = TF2_GetResourceEntity(); new entity = TF2_GetResourceEntity();
if (entity == -1) if (entity == -1)
{ {
return false; return false;
} }
SetEntData(entity, offset + (client*4), value); SetEntData(entity, offset + (client*4), value);
return true; return true;
} }
/** /**
@ -510,7 +523,7 @@ stock bool:TF2_IsPlayerInCondition(client, TFCond:cond)
{ {
return true; return true;
} }
if ((GetEntProp(client, Prop_Send, "_condition_bits") & bit) == bit) if ((GetEntProp(client, Prop_Send, "_condition_bits") & bit) == bit)
{ {
return true; return true;
@ -540,7 +553,7 @@ stock bool:TF2_IsPlayerInCondition(client, TFCond:cond)
return true; return true;
} }
} }
return false; return false;
} }
@ -554,12 +567,12 @@ stock bool:TF2_IsPlayerInCondition(client, TFCond:cond)
stock TFObjectType:TF2_GetObjectType(entity) stock TFObjectType:TF2_GetObjectType(entity)
{ {
new offset = GetEntSendPropOffs(entity, "m_iObjectType"); new offset = GetEntSendPropOffs(entity, "m_iObjectType");
if (offset <= 0) if (offset <= 0)
{ {
ThrowError("Entity index %d is not an object", entity); ThrowError("Entity index %d is not an object", entity);
} }
return TFObjectType:GetEntData(entity, offset); return TFObjectType:GetEntData(entity, offset);
} }
@ -573,11 +586,11 @@ stock TFObjectType:TF2_GetObjectType(entity)
stock TFObjectMode:TF2_GetObjectMode(entity) stock TFObjectMode:TF2_GetObjectMode(entity)
{ {
new offset = GetEntSendPropOffs(entity, "m_iObjectMode"); new offset = GetEntSendPropOffs(entity, "m_iObjectMode");
if (offset <= 0) if (offset <= 0)
{ {
ThrowError("Entity index %d is not an object", entity); ThrowError("Entity index %d is not an object", entity);
} }
return TFObjectMode:GetEntData(entity, offset); return TFObjectMode:GetEntData(entity, offset);
} }