Author Topic: Issues with killing entity  (Read 2022 times)

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Issues with killing entity
« on: April 27, 2015, 07:37:31 AM »
Hi guys,

Hoping you can help me out here - because for the life of me I can't figure out what's going on....

I've been working on a code for a tripmine.  This code works perfectly :)
It basically sets a tripmine that will explode after a period of time, or if an enemy comes in close proximity to it.
When the mine is 'tripped', it kills the entity, sets an explosion and sound, and damages nearby enemies.
http://pastebin.com/RYsJQduz - (Mine 1 - working)

However when i try to edit the code so that it can only detonate when you press ability1, it fails.
The code compiles fine, and it plays the sound at row 180, but doesn't kill the entity, call the explosion or do any damage.
http://pastebin.com/YpjYxuGr (Mine 2 - not working)

Can someone please help me to get this working? I really can't figure out why it shouldn't be working in Test2?

What am i doing wrong in Mine2?

Thanks heaps in advance for any help you can give :)

El Diablo

  • Hero Member
  • *****
  • Posts: 1126
    • View Profile
    • War3Evo
Re: Issues with killing entity
« Reply #1 on: April 27, 2015, 07:43:54 AM »
Which game?

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Issues with killing entity
« Reply #2 on: April 27, 2015, 07:48:06 AM »
Oh sorry - its CSS

El Diablo

  • Hero Member
  • *****
  • Posts: 1126
    • View Profile
    • War3Evo
Re: Issues with killing entity
« Reply #3 on: April 27, 2015, 07:55:04 AM »
If nobody answers you by the time I get home, I'll work on a solution for you.  It doesn't look hard.

Something I would change... Is to record the enitiy into a variable like:  into MineOwner[Maxclients+1]

MineOwner[client]=entity;


When they trigger the ability, no need for a timer, just create a public function TriggerMine(client). .. Then use the global variable you created for that entity.

If you allow more than one mine, then stuff gets complex.
« Last Edit: April 27, 2015, 07:57:25 AM by El Diablo »

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Issues with killing entity
« Reply #4 on: April 27, 2015, 08:00:31 AM »
Awesome mate thank you :)

I will want to have it so that only one mine can be planted at a time, and another one can't be planted until after the first has been blown up.

Im off to bed now (it's late here) so will check back in the morning.

Thanks heaps for your help :)

El Diablo

  • Hero Member
  • *****
  • Posts: 1126
    • View Profile
    • War3Evo
Re: Issues with killing entity
« Reply #5 on: April 27, 2015, 11:47:32 AM »
Untested, but this is how I would write it.

I would test it, but we do not have any CSS server going at this time.

When you write code, try not to use any timers unless you have to!

This code is setup so that the mine entity is attached to the owner.  If the entity is greater than -1 is then it was created.

There is a spot where you seem to be checking to see if the enemy is not equal to this race, which i am guessing if you are this race.. your immune to the tripmines?  This would cause a issue, if your test subjects are this race.  I left it in, because it seems that is what you want.

if(War3_GetRace(enemy)!=thisRaceID)

Wish you would tell us what version of sourcemod your compiling this for, cause I would have updated the code for 1.7 sourcemod.  The version you was writing in was version 1.6 or less.

Code: [Select]
#pragma semicolon 1

#include <sourcemod>
#include "W3SIncs/War3Source_Interface"

#define myLoopMaxClients(%1) for(new %1=1;%1<=MaxClients;++%1)

#define myLoopAlivePlayers(%1) for(new %1=1;%1<=MaxClients;++%1)\
if(IsClientInGame(%1) && IsPlayerAlive(%1))


new thisRaceID;

new SKILL_MINE;



// Mine
new String:MineModel[]="models/props_lab/tpplug.mdl";
new iMineOwner[MAXPLAYERS] = {-1, ...};
new Float:TripMineCD[]={0.0,60.0,50.0,40.0,30.0};
new Float:MineRange[]={0.0,150.0,175.0,200.0,250.0};
new Float:TripMineDuration[]={0.0,15.0,20.0,25.0,30.0};
new BeamSprite,HaloSprite,g_iExplosionModel,g_iSmokeModel;
new MineDamage[]={0,10,20,30,40};
new String:warningsnd[]="npc/roller/remote_yes.wav";
new String:explodesnd[]="weapons/explode5.wav";
#define TRACE_START 24.0
#define TRACE_END 64.0



public OnWar3PluginReady()
{
thisRaceID=War3_CreateNewRace("TripMine","Tripmine");

SKILL_MINE=War3_AddRaceSkill(thisRaceID, "Tripmine", "Plant a tripmine that enemies can trigger to blow up (+ability1)", false, 4 );

War3_CreateRaceEnd(thisRaceID);

}


public OnMapStart()
{
PrecacheModel(MineModel);
BeamSprite=PrecacheModel("materials/sprites/lgtning.vmt");
HaloSprite=PrecacheModel("materials/sprites/halo01.vmt");
g_iExplosionModel = PrecacheModel("materials/effects/fire_cloud1.vmt");
g_iSmokeModel = PrecacheModel("materials/effects/fire_cloud2.vmt");
War3_PrecacheSound(warningsnd);
War3_PrecacheSound(explodesnd);

myLoopMaxClients(client)
{
InitPassiveSkills(client);
}
}

public OnWar3EventSpawn(client)
{
if( War3_GetRace(client) == thisRaceID )
{
InitPassiveSkills(client);
}
}


public OnRaceChanged(client,oldrace,newrace)
{
if(newrace==thisRaceID)
{
InitPassiveSkills(client);
}
else if(oldrace==thisRaceID)
{
RemovePassiveSkills(client);
}

/*
if( newrace != thisRaceID )
{
War3_WeaponRestrictTo( client, thisRaceID, "" );
W3ResetAllBuffRace( client, thisRaceID );
}
else
{
iMineOwner[client]=-1;
}
*/
}

public InitPassiveSkills(client)
{
iMineOwner[client]=-1;
}

public RemovePassiveSkills(client)
{
KillMine(client);
iMineOwner[client]=-1;
War3_WeaponRestrictTo( client, thisRaceID, "" );
W3ResetAllBuffRace( client, thisRaceID );
}

public OnWar3Event(W3EVENT:event,client)
{
if(event == InitPlayerVariables)  // client put in server
{
InitPassiveSkills(client);
}
else if(event == ClearPlayerVariables)  // ondisconnect
{
RemovePassiveSkills(client);
}
}

/* *************************************** TripMine *************************************** */
public bool:CreateMine(client)
{
if(ValidPlayer(client))
{
new bool:MineCreated = false;
decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3];
GetClientEyePosition(client,start);
GetClientEyeAngles(client,angle);
GetAngleVectors(angle, end, NULL_VECTOR, NULL_VECTOR);
NormalizeVector(end, end);

start[0]=start[0]+end[0]*TRACE_START;
start[1]=start[1]+end[1]*TRACE_START;
start[2]=start[2]+end[2]*TRACE_START;

end[0]=start[0]+end[0]*TRACE_END;
end[1]=start[1]+end[1]*TRACE_END;
end[2]=start[2]+end[2]*TRACE_END;

TR_TraceRayFilter(start, end, CONTENTS_SOLID, RayType_EndPoint, FilterAll, 0);

if (TR_DidHit(INVALID_HANDLE))
{
TR_GetEndPosition(end, INVALID_HANDLE);
TR_GetPlaneNormal(INVALID_HANDLE, normal);
GetVectorAngles(normal, normal);

new mine = CreateEntityByName("prop_physics_override");
if(mine > -1)
{
SetEntityModel(mine, MineModel);
DispatchKeyValue(mine, "StartDisabled", "false");
DispatchSpawn(mine);
TeleportEntity(mine, end, normal, NULL_VECTOR);
SetEntProp(mine, Prop_Data, "m_usSolidFlags", 152);
SetEntProp(mine, Prop_Data, "m_CollisionGroup", 1);
SetEntityMoveType(mine, MOVETYPE_NONE);
SetEntProp(mine, Prop_Data, "m_MoveCollide", 0);
SetEntProp(mine, Prop_Data, "m_nSolidType", 6);
SetEntPropEnt(mine, Prop_Data, "m_hLastAttacker", client);
AcceptEntityInput(mine, "Enable");
iMineOwner[client]=mine;
MineCreated=true;
}
}
}
return MineCreated;
}


public OnAbilityCommand(client,ability,bool:pressed)
{
if(ValidPlayer(client,true) && War3_GetRace(client)==thisRaceID && pressed)
{
if(!Silenced(client))
{
if(ability==0)
{
// print Text If Not Ready = true
if(War3_SkillNotInCooldown(client,thisRaceID,SKILL_MINE,true))
{
if(War3_GetSkillLevel(client,thisRaceID,SKILL_MINE) > 0)
{
if (iMineOwner[client] > -1)
{
if(CreateMine(client))
{
PrintHintText(client, "Tripmine is planted!");
}
else
{
PrintHintText(client, "Tripmine planting unsuccessful!");
}
}
else
{
PrintHintText(client, "You already have a Tripmine planted");
}
}
else
{
PrintHintText(client, "Level your Tripmine first");
}
}
}
else if(ability==1)
{
if(!KillMine(client))
{
PrintHintText(client, "Plant a Landmine first");
}
}
}
else
{
War3_ChatMessage(client,"You can't lay a mine, your currently silenced!")
}
}
}

public bool:FilterAll(entity, contentsMask)
{
return false;
}

public bool:KillMine(client)
{
if(iMineOwner[client] > -1)
{
new mine = iMineOwner[client];
if(IsValidEdict(mine))
{
new Float:minepos[3];
new Float:enemypos[3];
new skill=War3_GetSkillLevel(client,thisRaceID,SKILL_MINE);
if(skill>0)
{
// Cooldown so it can't be placed again for 20 seconds
War3_CooldownMGR(client,20.0,thisRaceID,SKILL_MINE);
// now you can safely reset this variable:
iMineOwner[client] = -1;

GetEntPropVector(mine, Prop_Send, "m_vecOrigin", minepos);
TE_SetupExplosion(minepos, g_iExplosionModel, 20.0, 10, TE_EXPLFLAG_NONE, 300, 255);
TE_SendToAll();
TE_SetupSmoke(minepos, g_iExplosionModel, 100.0, 2);
TE_SendToAll();
TE_SetupSmoke(minepos, g_iSmokeModel, 100.0, 2);
TE_SendToAll();
AcceptEntityInput(mine, "Kill");
EmitSoundToAll(explodesnd,client);
// no reason to keep looping the client, when they client is always the same
new ClientTeam=GetClientTeam(client);
myLoopAlivePlayers(enemy)
{
if(GetClientTeam(enemy)==ClientTeam)
{
continue;
}
// I guess if the enemy is this race, then they are immune to mines?
// if this is true, try the mines against someone that is not this race for testing purposes
if(War3_GetRace(enemy)!=thisRaceID)
{
if(!W3HasImmunity(enemy,Immunity_Skills))
{
War3_CachedPosition(enemy,enemypos);
if(GetVectorDistance(minepos,enemypos)<=(MineRange[skill]*0.5))
{
War3_DealDamage( enemy, MineDamage[skill],client,DMG_BLAST,"Tripmine");
}
}
}
}
return true;
}
}
else
{
War3_ChatMessage(client,"Mine no longer is valid.");
}
iMineOwner[client] = -1;
}
return false;
}
« Last Edit: April 27, 2015, 12:04:57 PM by El Diablo »

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Issues with killing entity
« Reply #6 on: April 28, 2015, 03:50:36 AM »
You're an absolute legend Diablo :)

It didn't quite work as you'd coded, i just had to make a few small changes - changing the ability commands to call the functions directly, making the MineCreated bool global, and then setting it to false after explosion.
But now it works perfectly :)

Thanks  so much Diablo :)

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Issues with killing entity
« Reply #7 on: April 28, 2015, 05:15:58 PM »
Can I just ask one more question on this one please.
How can I give the mine 'health'?
Eg so that if someone shoots the mine or a nade explodes nearby, then the KillMine function gets automatically called?
I tried using SetEntityHealth which works, but when it runs out of health it just stays there - I can't even blow it up manually.
Is there another function I need to use with SetEntityHealth?

Cheers again

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Issues with killing entity
« Reply #8 on: May 11, 2015, 06:19:45 AM »
Sorry to bump here guys, but is someone able to help with the Entity Health?

Cheers :)

Remy Lebeau

  • Sr. Member
  • ****
  • Posts: 497
    • View Profile
Re: Issues with killing entity
« Reply #9 on: May 11, 2015, 04:50:18 PM »
Sorry to bump here guys, but is someone able to help with the Entity Health?

Cheers :)

Here's some of the tripmine code out of golden eye, might give you what you need:

Code: [Select]
    // create tripmine model
        new ent = CreateEntityByName("prop_physics_override");
        SetEntityModel(ent,mdlMine);
        DispatchKeyValue(ent, "StartDisabled", "false");
        DispatchSpawn(ent);
        TeleportEntity(ent, end, normal, NULL_VECTOR);
        SetEntProp(ent, Prop_Send, "m_usSolidFlags", 152);
        SetEntProp(ent, Prop_Send, "m_CollisionGroup", 1);
        SetEntityMoveType(ent, MOVETYPE_NONE);
        //    SetEntProp(ent, Prop_Send, "m_MoveCollide", 0);
        SetEntProp(ent, Prop_Send, "m_nSolidType", 6);
        SetEntPropEnt(ent, Prop_Data, "m_hLastAttacker", client);
        DispatchKeyValue(ent, "targetname", beammdl);
        DispatchKeyValue(ent, "ExplodeRadius", "256");
        DispatchKeyValue(ent, "ExplodeDamage", "400");
        Format(tmp, sizeof(tmp), "%s,Break,,0,-1", beammdl);
        DispatchKeyValue(ent, "OnHealthChanged", tmp);
        Format(tmp, sizeof(tmp), "%s,Kill,,0,-1", beam);
        DispatchKeyValue(ent, "OnBreak", tmp);
        SetEntProp(ent, Prop_Data, "m_takedamage", 2);
        AcceptEntityInput(ent, "Enable");
        HookSingleEntityOutput(ent, "OnBreak", mineBreak, true);
       
       
        // create laser beam
        ent = CreateEntityByName("env_beam");
        TeleportEntity(ent, beamend, NULL_VECTOR, NULL_VECTOR);
        SetEntityModel(ent, MDL_LASER);
        DispatchKeyValue(ent, "texture", MDL_LASER);
        DispatchKeyValue(ent, "targetname", beam);
        DispatchKeyValue(ent, "TouchType", "4");
        DispatchKeyValue(ent, "LightningStart", beam);
        DispatchKeyValue(ent, "BoltWidth", "4.0");
        DispatchKeyValue(ent, "life", "0");
        DispatchKeyValue(ent, "rendercolor", "0 0 0");
        DispatchKeyValue(ent, "renderamt", "0");
        DispatchKeyValue(ent, "HDRColorScale", "0.3");
        DispatchKeyValue(ent, "decalname", "Bigshot");
        DispatchKeyValue(ent, "StrikeTime", "0");
        DispatchKeyValue(ent, "TextureScroll", "35");
        Format(tmp, sizeof(tmp), "%s,Break,,0,-1", beammdl);
        DispatchKeyValue(ent, "OnTouchedByEntity", tmp);   
        SetEntPropVector(ent, Prop_Send, "m_vecEndPos", end);
        SetEntPropFloat(ent, Prop_Send, "m_fWidth", 4.0);
        AcceptEntityInput(ent, "TurnOff");

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Issues with killing entity
« Reply #10 on: May 12, 2015, 01:31:03 AM »
Sorry to bump here guys, but is someone able to help with the Entity Health?

Cheers :)

You set m_iHealth of the entity and hook OnBreak like in Remi's snippet - done  :)
#war3source on gamesurge