Member
Join Date: Aug 2019
Location: CN
|
12-03-2022
, 06:15
[L4D2]How to find which player deploy the upgradeAmmo pack
|
#1
|
I was writing a mine plugin. When players deploy the upgrade ammo pack, a mine will be deploy instead. I use the "SDKHook_StartTouch" hook the mine so i can let the mine explode when someone touch it.Here's some my code:
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
if (StrEqual(classname, "upgrade_ammo_explosive", false) || StrEqual(classname, "upgrade_ammo_incendiary", false)){
RequestFrame(OnNextFrame, EntIndexToEntRef(entity));
}
}
void OnNextFrame(int iEntRef)
{
if (!IsValidEntRef(iEntRef)){
return;
}
int entity = EntRefToEntIndex(iEntRef);
float Pos[3];
char mineExplosive[64];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", Pos);//position
// PrintToChatAll("%f %f %f", Pos[0], Pos[1], Pos[2]);
AcceptEntityInput(entity, "kill");
int physics = CreateEntityByName("prop_dynamic_override");
if (IsValidEntity(physics) && IsValidEdict(physics)){
char tmp[128];
Format(mineExplosive, sizeof(mineExplosive), "mineExplosive%d", gCount);
gCount = gCount > 10000 ? 1 : gCount + 1;
if (gCount > 10000){
gCount = 1;
}
DispatchKeyValue(physics, "model", MDL_MINE);
DispatchSpawn(physics);
TeleportEntity(physics, Pos, NULL_VECTOR, NULL_VECTOR);
SetEntProp(physics, Prop_Send, "m_iGlowType", 2);
SetEntProp(physics, Prop_Send, "m_glowColorOverride", GetColor("255 0 0"));
SetEntProp(physics, Prop_Send, "m_nGlowRange", 320);
SetEntProp(physics, Prop_Data, "m_usSolidFlags", 152);
SetEntProp(physics, Prop_Data, "m_CollisionGroup", 1);// Collides with nothing but world and static stuff
SetEntityMoveType(physics, MOVETYPE_NONE);
SetEntProp(physics, Prop_Data, "m_MoveCollide", 0);
SetEntProp(physics, Prop_Data, "m_nSolidType", 6);// solid vphysics object, get vcollide from the model and collide with that
DispatchKeyValue(physics, "ExplodeRadius", "10");
DispatchKeyValue(physics, "ExplodeDamage", "1");
Format(tmp, sizeof(tmp), "%s,Explode,,0,-1", mineExplosive);
DispatchKeyValue(physics, "OnBreak", tmp);
SetEntProp(physics, Prop_Data, "m_takedamage", 2);//DAMAGE_YES
}
int explosion = CreateEntityByName("env_explosion");
if (IsValidEntity(explosion) && IsValidEdict(explosion)){
TeleportEntity(explosion, Pos, NULL_VECTOR, NULL_VECTOR);
DispatchKeyValue(explosion, "targetname", mineExplosive);
DispatchKeyValue(explosion, "spawnflags", "1916"); // Random orientation
DispatchKeyValue(explosion, "iMagnitude", "1000");
DispatchKeyValue(explosion, "iRadiusOverride", "500");
SetEntProp(explosion, Prop_Data, "m_iHammerID", 1078682);
DispatchSpawn(explosion);
}
SDKHook(physics , SDKHook_StartTouch, OnTouch);
}
public OnTouch(physics, client)
{
// PrintToChatAll("client touched!");
if( IsValidEntity(physics) && IsValidEdict(physics))
{
if(IsValidClient(client) || IsWitchOrInfected(client))
{
AcceptEntityInput(physics, "Break");
}
}
}
The most quetion is i want to SetEntPropEnt(explosion, Prop_Data, "m_hLastAttacker", client), so player will get score when their mine kill infect / zombies;
But i can't get the client who deploy it. is there a better way to get the client?
Sorry for my poor English
Last edited by kazya3; 12-03-2022 at 11:10.
|
|