Quote:
Originally Posted by abrandnewday
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
}
}