Was having a hell of a time getting collsions from a prop_dynamic_override entity. Searched up and down the forums and nothing! I couldn't use prop_physics_override because I needed to attach this model to the player but still have it detect collsions. Without further ado here is the code hopefully it will help someone and prevent lot of grief in the future.
PHP Code:
public Action:Attach_Shield(client)
{
new ent = CreateEntityByName("prop_dynamic_override");
if ( ent == -1 )
{
ReplyToCommand( client, "Failed to create a Shield!" );
return Plugin_Handled;
}
//Set the model, use your own model this won't work for you ;)
SetEntityModel(ent, MODEL_SHIELD01);
//make sure to do this before we actually spawn the P.O.S.
SetEntProp(ent, Prop_Data, "m_takedamage", 2);
DispatchSpawn(ent);
new String:playerName[128];
Format(playerName, sizeof(playerName), "target%i", client);
DispatchKeyValue(client, "targetname", playerName);
//Set the Shield's owner
SetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity", client);
//Parent the shield to the player
SetVariantString(playerName);
AcceptEntityInput(ent, "SetParent");
//Attach the shield to the 'flag'
SetVariantString("flag");
AcceptEntityInput(ent, "SetParentAttachment");
new iTeam = GetClientTeam(client);
SetVariantInt(iTeam);
AcceptEntityInput(ent, "TeamNum", -1, -1, 0);
SetVariantInt(iTeam);
AcceptEntityInput(ent, "SetTeam", -1, -1, 0);
//Yes! Again
SetEntProp(ent, Prop_Data, "m_takedamage", 2);
SetEntPropEnt(ent, Prop_Data, "m_hLastAttacker", client);
//Use the shields VPhysics for collisions
SetEntProp( ent, Prop_Data, "m_nSolidType", 6 );
SetEntProp( ent, Prop_Send, "m_nSolidType", 6 );
//Only detect bullet/damage collisions
SetEntProp(ent, Prop_Data, "m_CollisionGroup", 2);
SetEntProp(ent, Prop_Send, "m_CollisionGroup", 2);
//Set the shield's health
SetEntProp(ent, Prop_Data, "m_iMaxHealth", 100);
SetEntProp(ent, Prop_Data, "m_iHealth", 100);
//wait Wah? That doesn't make sense
//but it works!
AcceptEntityInput( ent, "DisableCollision" );
AcceptEntityInput( ent, "EnableCollision" );
HookSingleEntityOutput(ent, "OnTakeDamage", shieldDamage, false);
return Plugin_Handled;
}
public shieldDamage (const String:output[], caller, activator, Float:delay)
{
//your damage code goes here
}