mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-08 07:53:20 +00:00
jutils: Add utility methods
This commit is contained in:
parent
a949868806
commit
357b351c7a
1 changed files with 82 additions and 32 deletions
|
@ -531,3 +531,53 @@ stock void NotifyAllAdmins(const char[] format, any ...) {
|
|||
}
|
||||
PrintToServer("%s", buffer);
|
||||
}
|
||||
|
||||
stock float GetNearestEntityDistance(int originEntity, char[] classname) {
|
||||
float compareVec[3], entityVecOrigin[3];
|
||||
GetEntPropVector(originEntity, Prop_Send, "m_vecOrigin", compareVec);
|
||||
|
||||
//Get the distance between the first entity and client
|
||||
float distance, nearestDistance = -1.0;
|
||||
|
||||
int entity = -1, closest;
|
||||
while ((entity = FindEntityByClassname(entity, classname)) != -1)
|
||||
{
|
||||
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", entityVecOrigin);
|
||||
distance = GetVectorDistance(compareVec, entityVecOrigin);
|
||||
PrintDebug(DEBUG_SPAWNLOGIC, "Comparing %s (id %d) (%.2f,%.2f,%.2f) distance to entity %d (%.2f,%.2f,%.2f) is %.4f", classname, entity, entityVecOrigin[0], entityVecOrigin[1], entityVecOrigin[2], originEntity, compareVec[0], compareVec[1], compareVec[2], distance);
|
||||
|
||||
if (distance < nearestDistance || nearestDistance == -1.0)
|
||||
{
|
||||
nearestDistance = distance;
|
||||
closest = entity;
|
||||
}
|
||||
}
|
||||
return closest > 0 ? nearestDistance : -1.0;
|
||||
}
|
||||
|
||||
stock int FindNearestEntityInRange(int originEntity, char[] classname, float range) {
|
||||
float compareVec[3], entityVecOrigin[3];
|
||||
GetEntPropVector(originEntity, Prop_Send, "m_vecOrigin", compareVec);
|
||||
|
||||
//Get the distance between the first entity and client
|
||||
float distance, nearestDistance = -1.0;
|
||||
|
||||
int entity = -1, closest = -1;
|
||||
while ((entity = FindEntityByClassname(entity, classname)) != -1) {
|
||||
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", entityVecOrigin);
|
||||
distance = GetVectorDistance(compareVec, entityVecOrigin);
|
||||
|
||||
if (distance <= range && (distance < nearestDistance || nearestDistance == -1.0)) {
|
||||
PrintDebug(DEBUG_SPAWNLOGIC, "Comparing %s (id %d) (%.2f,%.2f,%.2f) distance to entity %d (%.2f,%.2f,%.2f) is %.4f", classname, entity, entityVecOrigin[0], entityVecOrigin[1], entityVecOrigin[2], originEntity, compareVec[0], compareVec[1], compareVec[2], distance);
|
||||
nearestDistance = distance;
|
||||
closest = entity;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
stock void MakeEntityGlow(int entity, const int color[3], float distance = 1500.0) {
|
||||
SetEntProp(entity, Prop_Send, "m_iGlowType", 3);
|
||||
SetEntProp(entity, Prop_Send, "m_nGlowRange", distance);
|
||||
SetEntProp(entity, Prop_Send, "m_glowColorOverride", color[0] + (color[1] * 256) + (color[2] * 65536));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue