View Single Post
rswallen
SourceMod Donor
Join Date: Jun 2013
Location: 127.0.0.1
Old 05-16-2014 , 02:31   Re: [TF2] Medic's Anti-Projectile Shield v1.0
Reply With Quote #4

Quote:
Originally Posted by abrandnewday View Post
If you die during the shield's 10 second lifetime, if the server has any amount of respawn time, you can control the shield while waiting to respawn and it will continue to damage any who touch it until its 10 second lifetime is up. I'm too dumb to figure out how to target an entity spawned by a specific player and kill it without killing every other instance of that entity. halp me plz
Cache the entity reference of the shield when you create it.
When the player dies, check if its still a valid entity, and kill it if it is

PHP Code:
new g_entCurrentShield[MAXPLAYERS+1] = { INVALID_ENT_REFERENCE, ... }

EventHook_OnPlayerDeath(Handle:event, const String:name[], bool:dontbroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
client != 0)
    {
        if (
IsValidEntity(g_entCurrentShield[client]))
        {
            
AcceptEntityInput(g_entCurrentShield[client], "Kill");
            
g_entCurrentShield[client] = INVALID_ENT_REFERENCE;
        }
    }
}

//[OnShieldCreated]
{
    new 
shield CreateEntityByName("entity_medigun_shield");
    if(
shield != -1)
    {
        
g_entCurrentShield[client] = EntIndexToEntRef(shield);
        
// do other stuff
    
}


Last edited by rswallen; 05-16-2014 at 03:07. Reason: fixed example :S
rswallen is offline