For those wondering how much code it takes to display that little image here is a look at the programing behind displaying that little thing in game:
GlobalVars:
Code:
//Decals
new String:IronFileVMT[] = "materials/decals/custom/ibisgaming/iron.vmt";
new String:IronFileVTF[] = "materials/decals/custom/ibisgaming/iron.vtf";
OnMapStart:
Code:
//decals load
OnMapStart_PrepareDecal(IronFileVMT, IronFileVTF);
Display the actual effect to clients:
Code:
//Shield Sprite
decl Float:clientLocation[3];
GetClientAbsOrigin(attacker, clientLocation);
clientLocation[2]+=40;
decl Float:targetLocation[3];
GetClientAbsOrigin(targetclient, targetLocation);
targetLocation[2]+=40;
decl Float:vecEyeAng[3];
GetClientEyeAngles(attacker, vecEyeAng);
if(vecEyeAng[1]>180.0)
{
vecEyeAng[1]=vecEyeAng[1]-360;
}
new Float:distance = IronBaseRange + (skill_level*IronRangeMult);
if(Entity_GetDistance(attacker, targetclient) <= distance)
{
distance = Entity_GetDistance(attacker, targetclient);
}
decl Float:vecLocation[3];
Math_MoveVector(targetLocation, clientLocation, distance/GetVectorDistance(targetLocation, clientLocation), vecLocation);
CreateSprite(victim, IronFileVMT, vecLocation, vecEyeAng, 0.15, "1", 1.0);
//END SHIELD SPRITE
So that is what you actually see in the source code of the race but you notice a lot of native function calls. Some are from others and some are from my stocks. You hear me talk about making stocks a lot and without stock functions all the code below would be in the race sourcecode making things hard to read and debug. As this same code is reused as often as the above functions are there is no point in cluttering up races with all that extra code making it harder to read the program and find bugs and make quick and easy changes.
Code:
/*
* Precaches and adds decal files to DL.
*
* @param String:VMT VMT file
* @param String:VTF VTF file
* @return
*/
stock OnMapStart_PrepareDecal(String:VMT[], String:VTF[])
{
PrecacheModel(VTF);
AddFileToDownloadsTable(VMT);
AddFileToDownloadsTable(VTF);
}
Code:
/**
* Returns the Float distance between an entity
* and a vector origin.
*
* @param entity Entity Index.
* @param target Vector Origin.
* @return Distance Float value.
*/
stock Float:Entity_GetDistanceOrigin(entity, const Float:vec[3])
{
new Float:entityVec[3];
Entity_GetAbsOrigin(entity, entityVec);
return GetVectorDistance(entityVec, vec);
}
Code:
/*
* Moves the start vector on a direct line to the end vector by the given scale.
* Note: If scale is 0.0 the output will be the same as the start vector and if scale is 1.0 the output vector will be the same as the end vector.
* Exmaple usage: Move an entity to another entity but only 12 units: Vector_MoveVector(entity1Origin,entity2Origin,(12.0 / GetVectorDistance(entity1Origin,entity2Origin)),newEntity1Origin); now only teleport your entity to newEntity1Origin.
*
* @param start The start vector where the imagined line starts.
* @param end The end vector where the imagined line ends.
* @param scale The position on the line 0.0 is the start 1.0 is the end.
* @param output Output vector
* @noreturn
*/
stock Math_MoveVector(const Float:start[3], const Float:end[3], Float:scale, Float:output[3])
{
SubtractVectors(end,start,output);
ScaleVector(output,scale);
AddVectors(start,output,output);
}
And finally the one that actually makes the dam thing show up on your screen:
Code:
/*
* CREATE SPRITE
*
* @param iClient Player to target.
* @param String:sprite Path to VMT File.
* @param Float:vOrigin[3] Location of Sprite.
* @param Float:fAng[3] Angles (P Y R).
* @param Float:Scale Size of Sprite.
* @param String:fps Render Speed.
* @param Float:fLifetime Life of Sprite. -1 for infinate
* @return Ent on success, -1 otherwise.
*/
stock CreateSprite(iClient, String:sprite[], Float:vOrigin[3], Float:fAng[3], Float:Scale, String:fps[], Float:fLifetime)
{
new String:szTemp[64];
Format(szTemp, sizeof(szTemp), "client%i", iClient);
DispatchKeyValue(iClient, "targetname", szTemp);
new ent = CreateEntityByName("env_sprite_oriented");
if(IsValidEdict(ent))
{
new String:StrEntityName[64]; Format(StrEntityName, sizeof(StrEntityName), "ent_sprite_oriented_%i", ent);
DispatchKeyValue(ent, "model", sprite);
DispatchKeyValue(ent, "classname", "env_sprite_oriented");
DispatchKeyValue(ent, "spawnflags", "1");
DispatchKeyValueFloat(ent, "scale", Scale);
DispatchKeyValue(ent, "rendermode", "1");
DispatchKeyValue(ent, "rendercolor", "255 255 255");
DispatchKeyValue(ent, "framerate", fps);
DispatchKeyValueVector(ent, "Angles", fAng);
DispatchSpawn(ent);
TeleportEntity(ent, vOrigin, fAng, NULL_VECTOR);
if(fLifetime > 0)
{
CreateTimer(fLifetime, RemoveParticle, ent);
}
return ent;
}
return -1;
}
So there you have it, the inner workings of making a single little image popup on your screen for 1 second. The question is if you can animate this image...