Raised This Month: $51 Target: $400
 12% 

[HELP] Tripmines exolosions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 12-28-2014 , 20:37   [HELP] Tripmines exolosions
Reply With Quote #1

Hello. I have got Chaosxk's fixed tripmines plugin. It works, but mines are exoloding if the laser touched by a teammate or owner, and explosion hurts everyone. Can anyone help me to make following:
1. Lasers will only detonate the mine if it is touched by enemy;
2. Exoplosion will hurt only enemies and if enemy dies, than it will be like the owner killed the target, not like a suicide.
OR
1. Lasers will cause damage without exploding the mine (if possibly).
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0.0.5"

#define TRACE_START 24.0
#define TRACE_END 64.0

#define MDL_LASER "sprites/laser.vmt"

#define SND_MINEPUT "npc/roller/blade_cut.wav"
#define SND_MINEACT "npc/roller/mine/rmine_blades_in2.wav"

#define TEAM_T 2
#define TEAM_CT 3

#define COLOR_T "255 0 0"
#define COLOR_CT "0 0 255"
#define COLOR_DEF "0 255 255"

#define MAX_LINE_LEN 256

// globals
new gRemaining[MAXPLAYERS+1];    // how many tripmines player has this spawn
new gCount 1;
new 
String:mdlMine[256];

// convars
new Handle:cvNumMines INVALID_HANDLE;
new 
Handle:cvActTime INVALID_HANDLE;
new 
Handle:cvModel INVALID_HANDLE;
new 
Handle:cvTeamRestricted INVALID_HANDLE;

public 
Plugin:myinfo = {
    
name "Tripmines",
    
author "L. Duke fixed by Chaosxk",
    
description "Plant a trip mine",
    
version PLUGIN_VERSION,
    
url "http://www.lduke.com/"
};


public 
OnPluginStart() 
{
  
// events
  
HookEvent("player_death"PlayerDeath);
  
HookEvent("player_spawn",PlayerSpawn);
  
  
// convars
  
CreateConVar("sm_tripmines_version"PLUGIN_VERSION"Tripmines"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  
cvNumMines CreateConVar("sm_tripmines_allowed""3");
  
cvActTime CreateConVar("sm_tripmines_activate_time""2.0");
  
cvModel CreateConVar("sm_tripmines_model""models/props_lab/tpplug.mdl");
  
cvTeamRestricted CreateConVar("sm_tripmines_restrictedteam""0");

  
// commands
  
RegConsoleCmd("sm_tripmine"Command_TripMine);
}

public 
OnEventShutdown(){
    
UnhookEvent("player_death"PlayerDeath);
    
UnhookEvent("player_spawn",PlayerSpawn);
}

public 
OnMapStart()
{
  
// set model based on cvar
  
GetConVarString(cvModelmdlMinesizeof(mdlMine));
  
  
// precache models
  
PrecacheModel(mdlMinetrue);
  
PrecacheModel(MDL_LASERtrue);
  
  
// precache sounds
  
PrecacheSound(SND_MINEPUTtrue);
  
PrecacheSound(SND_MINEACTtrue);
}

// When a new client is put in the server we reset their mines count
public OnClientPutInServer(client){
  if(
client && !IsFakeClient(client)) gRemaining[client] = 0;
}

public 
Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client;
    
client GetClientOfUserId(GetEventInt(event"userid"));
    
gRemaining[client] = GetConVarInt(cvNumMines);
    return 
Plugin_Continue;
}

public 
Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){
    new 
client;
    
client GetClientOfUserId(GetEventInt(event"userid"));
    
gRemaining[client] = 0;
    return 
Plugin_Continue;
}

public 
Action:Command_TripMine(clientargs)
{  
  
// make sure client is not spectating
  
if (!IsPlayerAlive(client))
    return 
Plugin_Handled;
    
  
// check restricted team 
  
new team GetClientTeam(client);
  if(
team == GetConVarInt(cvTeamRestricted))
  { 
    
PrintHintText(client"Your team does not have access to this equipment.");
    return 
Plugin_Handled;
  }
  
  
// call SetMine if any remain in client's inventory
  
if (gRemaining[client]>0) {
    
SetMine(client);
  }
  else {
    
PrintHintText(client"You do not have any tripmines.");
  }
  return 
Plugin_Handled;
}

SetMine(client)
{
  
  
// setup unique target names for entities to be created with
  
new String:beam[64];
  new 
String:beammdl[64];
  new 
String:tmp[128];
  
Format(beamsizeof(beam), "tmbeam%d"gCount);
  
Format(beammdlsizeof(beammdl), "tmbeammdl%d"gCount);
  
gCount++;
  if (
gCount>10000)
  {
    
gCount 1;
  }
  
  
// trace client view to get position and angles for tripmine
  
  
decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3], Float:beamend[3];
  
GetClientEyePositionclientstart );
  
GetClientEyeAnglesclientangle );
  
GetAngleVectors(angleendNULL_VECTORNULL_VECTOR);
  
NormalizeVector(endend);

  
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(startendCONTENTS_SOLIDRayType_EndPointFilterAll0);
  
  if (
TR_DidHit(INVALID_HANDLE))
  {
    
// update client's inventory
    
gRemaining[client]-=1;
    
    
// find angles for tripmine
    
TR_GetEndPosition(endINVALID_HANDLE);
    
TR_GetPlaneNormal(INVALID_HANDLEnormal);
    
GetVectorAngles(normalnormal);
    
    
// trace laser beam
    
TR_TraceRayFilter(endnormalCONTENTS_SOLIDRayType_InfiniteFilterAll0);
    
TR_GetEndPosition(beamendINVALID_HANDLE);
    
    
// create tripmine model
    
new ent CreateEntityByName("prop_physics_override");
    
SetEntityModel(ent,mdlMine);
    
SetEntProp(entProp_Send"m_usSolidFlags"152);
    
SetEntProp(entProp_Send"m_CollisionGroup"1);
    
SetEntProp(entProp_Data"m_MoveCollide"0);
    
SetEntProp(entProp_Send"m_nSolidType"6);
    
SetEntPropEnt(entProp_Data"m_hLastAttacker"client);
    
DispatchKeyValue(ent"targetname"beammdl);
    
DispatchKeyValue(ent"ExplodeRadius""256");
    
DispatchKeyValue(ent"ExplodeDamage""400");
    
Format(tmpsizeof(tmp), "%s,Break,,0,-1"beammdl);
    
DispatchKeyValue(ent"OnHealthChanged"tmp);
    
Format(tmpsizeof(tmp), "%s,Kill,,0,-1"beam);
    
DispatchKeyValue(ent"OnBreak"tmp);
    
SetEntProp(entProp_Data"m_takedamage"2);
    
DispatchSpawn(ent);
    
ActivateEntity(ent);
    
TeleportEntity(entendnormalNULL_VECTOR);
    
AcceptEntityInput(ent"DisableMotion");
    
HookSingleEntityOutput(ent"OnBreak"mineBreaktrue);

    
    
// create laser beam
    
ent CreateEntityByName("env_beam");
    
TeleportEntity(entbeamendNULL_VECTORNULL_VECTOR);
    
SetEntityModel(entMDL_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""1.0");
    
DispatchKeyValue(ent"decalname""Bigshot");
    
DispatchKeyValue(ent"StrikeTime""0");
    
DispatchKeyValue(ent"TextureScroll""35");
    
Format(tmpsizeof(tmp), "%s,Break,,0,-1"beammdl);
    
DispatchKeyValue(ent"OnTouchedByEntity"tmp);   
    
SetEntPropVector(entProp_Data"m_vecEndPos"end);
    
SetEntPropFloat(entProp_Data"m_fWidth"4.0);
    
AcceptEntityInput(ent"TurnOff");

    new 
Handle:data CreateDataPack();
    
CreateTimer(GetConVarFloat(cvActTime), TurnBeamOndata);
    
WritePackCell(dataclient);
    
WritePackCell(dataent);
    
WritePackFloat(dataend[0]);
    
WritePackFloat(dataend[1]);
    
WritePackFloat(dataend[2]);
    
    
// play sound
    
EmitSoundToAll(SND_MINEPUTentSNDCHAN_AUTOSNDLEVEL_NORMALSND_NOFLAGSSNDVOL_NORMAL100entendNULL_VECTORtrue0.0);
    
    
// send message
    
PrintHintText(client"Tripmines remaining: %d"gRemaining[client]);
  }
  else
  {
    
PrintHintText(client"Invalid location for Tripmine");
  }
}

public 
Action:TurnBeamOn(Handle:timerHandle:data)
{
  
decl String:color[26];

  
ResetPack(data);
  new 
client ReadPackCell(data);
  new 
ent ReadPackCell(data);

  if (
IsValidEntity(ent))
  {
    new 
team GetClientTeam(client);
    if(
team == TEAM_Tcolor COLOR_T;
    else if(
team == TEAM_CTcolor COLOR_CT;
    else 
color COLOR_DEF;

    
DispatchKeyValue(ent"rendercolor"color);
    
AcceptEntityInput(ent"TurnOn");

    new 
Float:end[3];
    
end[0] = ReadPackFloat(data);
    
end[1] = ReadPackFloat(data);
    
end[2] = ReadPackFloat(data);

    
EmitSoundToAll(SND_MINEACTentSNDCHAN_AUTOSNDLEVEL_NORMALSND_NOFLAGSSNDVOL_NORMAL100entendNULL_VECTORtrue0.0);
  }

  
CloseHandle(data);
}

public 
mineBreak (const String:output[], calleractivatorFloat:delay)
{
  
UnhookSingleEntityOutput(caller"OnBreak"mineBreak);
  
AcceptEntityInput(caller,"kill");
}

public 
bool:FilterAll (entitycontentsMask)
{
  return 
false;

Thanks.
__________________

Last edited by uNg0veRNab1e; 01-04-2015 at 03:44.
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
Static2601
Senior Member
Join Date: Jun 2010
Old 12-28-2014 , 22:57   Re: Tripmines exolosions
Reply With Quote #2

Ive ran this plugin on my server a few years ago and we loved it except it show the player suicided rather then you killing them and there were some other issues. Id love to try and get this working right when I get time. I have a few ideas I'd like to try and see if they work. Ill post back if I do get it working.

Last edited by Static2601; 12-28-2014 at 22:58.
Static2601 is offline
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 12-29-2014 , 03:26   Re: Tripmines exolosions
Reply With Quote #3

Quote:
Originally Posted by Static2601 View Post
Ive ran this plugin on my server a few years ago and we loved it except it show the player suicided rather then you killing them and there were some other issues. Id love to try and get this working right when I get time. I have a few ideas I'd like to try and see if they work. Ill post back if I do get it working.
Thank you
__________________
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 01-02-2015 , 06:34   Re: Tripmines exolosions
Reply With Quote #4

bumping
__________________
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
Static2601
Senior Member
Join Date: Jun 2010
Old 01-02-2015 , 19:25   Re: Tripmines exolosions
Reply With Quote #5

Ok so I tryed to figure out why you didnt get credit for kills and I tryed some diffrent code but nothing I tryed worked. I dont know enough about how ent props work to get it working. So ill come back to it later. I did try and figure out how I could stop teams from triggering their own mines but, also had trouble. I started by creating 2 filter_activator_tfteam entities and setting the filtername in the env_beam ent, but it didnt want to work. I redid it all in hammer and it worked fine. I checked that everything was there but didnt want to work. My next option for this was to hookEntityOutput and run some code if you were touching the beam, then filter out the team name and have it find and set the OnBreak from there. One trouble Im having is once the beam is touched by a player, any player, it seems to be disabled, unhooked or whatever. Not too sure how to fix this right now. Ive been working on this all day and yesterday and Im gonna take a break and get back to work on my other stuff. I hope someone can help you out. Ill work on it again when I get time or a solution pops up. Heres the working code.
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0.0.5"

#define TRACE_START 24.0
#define TRACE_END 64.0

#define MDL_LASER "sprites/laser.vmt"

#define SND_MINEPUT "npc/roller/blade_cut.wav"
#define SND_MINEACT "npc/roller/mine/rmine_blades_in2.wav"

#define TEAM_T 2
#define TEAM_CT 3

#define COLOR_T "255 0 0"
#define COLOR_CT "0 0 255"
#define COLOR_DEF "0 255 255"

#define MAX_LINE_LEN 256

// globals
new gRemaining[MAXPLAYERS+1];    // how many tripmines player has this spawn
new gCount = 1;
new String:mdlMine[256];

// convars
new Handle:cvNumMines = INVALID_HANDLE;
new Handle:cvActTime = INVALID_HANDLE;
new Handle:cvModel = INVALID_HANDLE;
new Handle:cvTeamRestricted = INVALID_HANDLE;

public Plugin:myinfo = {
    name = "Tripmines",
    author = "L. Duke fixed by Chaosxk",
    description = "Plant a trip mine",
    version = PLUGIN_VERSION,
    url = "http://www.lduke.com/"
};


public OnPluginStart() 
{
  // events
  HookEvent("player_death", PlayerDeath);
  HookEvent("player_spawn",PlayerSpawn);
  HookEntityOutput("env_beam", "OnTouchedByEntity", BeamTouched);
  
  // convars
  CreateConVar("sm_tripmines_version", PLUGIN_VERSION, "Tripmines", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  cvNumMines = CreateConVar("sm_tripmines_allowed", "3");
  cvActTime = CreateConVar("sm_tripmines_activate_time", "2.0");
  cvModel = CreateConVar("sm_tripmines_model", "models/props_lab/tpplug.mdl");
  cvTeamRestricted = CreateConVar("sm_tripmines_restrictedteam", "0");

  // commands
  RegConsoleCmd("sm_tripmine", Command_TripMine);
}

public OnEventShutdown(){
    UnhookEvent("player_death", PlayerDeath);
    UnhookEvent("player_spawn",PlayerSpawn);
}

public OnMapStart()
{
  // set model based on cvar
  GetConVarString(cvModel, mdlMine, sizeof(mdlMine));
  
  // precache models
  PrecacheModel(mdlMine, true);
  PrecacheModel(MDL_LASER, true);
  
  // precache sounds
  PrecacheSound(SND_MINEPUT, true);
  PrecacheSound(SND_MINEACT, true);
}

// When a new client is put in the server we reset their mines count
public OnClientPutInServer(client){
  if(client && !IsFakeClient(client)) gRemaining[client] = 0;
}

public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client;
    client = GetClientOfUserId(GetEventInt(event, "userid"));
    gRemaining[client] = GetConVarInt(cvNumMines);
    return Plugin_Continue;
}

public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast){
    new client;
    client = GetClientOfUserId(GetEventInt(event, "userid"));
    gRemaining[client] = 0;
    return Plugin_Continue;
}

public Action:Command_TripMine(client, args)
{  
  // make sure client is not spectating
  if (!IsPlayerAlive(client))
    return Plugin_Handled;
    
  // check restricted team 
  new team = GetClientTeam(client);
  if(team == GetConVarInt(cvTeamRestricted))
  { 
    PrintHintText(client, "Your team does not have access to this equipment.");
    return Plugin_Handled;
  }
  
  // call SetMine if any remain in client's inventory
  if (gRemaining[client]>0) {
    SetMine(client);
  }
  else {
    PrintHintText(client, "You do not have any tripmines.");
  }
  return Plugin_Handled;
}

SetMine(client)
{
  
  // setup unique target names for entities to be created with
  new String:beam[64];
  new String:beammdl[64];
  new String:tmp[128];
  Format(beam, sizeof(beam), "tmbeam %d", gCount);
  Format(beammdl, sizeof(beammdl), "tmbeammdl %d", gCount);
  gCount++;
  if (gCount>10000)
  {
    gCount = 1;
  }
  
  // trace client view to get position and angles for tripmine
  
  decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3], Float:beamend[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))
  {
    // update client's inventory
    gRemaining[client]-=1;
    
    // find angles for tripmine
    TR_GetEndPosition(end, INVALID_HANDLE);
    TR_GetPlaneNormal(INVALID_HANDLE, normal);
    GetVectorAngles(normal, normal);
    
    // trace laser beam
    TR_TraceRayFilter(end, normal, CONTENTS_SOLID, RayType_Infinite, FilterAll, 0);
    TR_GetEndPosition(beamend, INVALID_HANDLE);
     
    // create tripmine model
    new ent = CreateEntityByName("prop_physics_override");
    new team = GetClientTeam(client);
    SetEntityModel(ent,mdlMine);
    SetEntProp(ent, Prop_Send, "m_usSolidFlags", 152);
    SetEntProp(ent, Prop_Send, "m_CollisionGroup", 1);
    SetEntProp(ent, Prop_Data, "m_MoveCollide", 0);
    SetEntProp(ent, Prop_Send, "m_nSolidType", 6);
    SetEntPropEnt(ent, Prop_Data, "m_hOwnerEntity", client);
    SetEntProp(ent, Prop_Data, "m_iTeamNum", team, 6, 0);     
    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);
    DispatchSpawn(ent);
    ActivateEntity(ent);
    TeleportEntity(ent, end, normal, NULL_VECTOR);
    AcceptEntityInput(ent, "DisableMotion");
    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);
    SetEntProp(ent, Prop_Data, "m_iTeamNum", team, 6, 0);
    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", "1.0");
    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_Data, "m_vecEndPos", end);
    SetEntPropFloat(ent, Prop_Data, "m_fWidth", 4.0);
    //AcceptEntityInput(ent, "TurnOff");

    new Handle:data = CreateDataPack();
    CreateTimer(GetConVarFloat(cvActTime), TurnBeamOn, data);
    WritePackCell(data, client);
    WritePackCell(data, ent);
    WritePackFloat(data, end[0]);
    WritePackFloat(data, end[1]);
    WritePackFloat(data, end[2]);
    
    // play sound
    EmitSoundToAll(SND_MINEPUT, ent, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, 100, ent, end, NULL_VECTOR, true, 0.0);
    
    // send message
    PrintHintText(client, "Tripmines remaining: %d", gRemaining[client]);
  }
  else
  {
    PrintHintText(client, "Invalid location for Tripmine");
  }
}

public Action:TurnBeamOn(Handle:timer, Handle:data)
{
  decl String:color[26];

  ResetPack(data);
  new client = ReadPackCell(data);
  new ent = ReadPackCell(data);

  if (IsValidEntity(ent))
  {
    new team = GetClientTeam(client);
    if(team == TEAM_T) color = COLOR_T;
    else if(team == TEAM_CT) color = COLOR_CT;
    else color = COLOR_DEF;

    DispatchKeyValue(ent, "rendercolor", color);
    AcceptEntityInput(ent, "TurnOn");

    new Float:end[3];
    end[0] = ReadPackFloat(data);
    end[1] = ReadPackFloat(data);
    end[2] = ReadPackFloat(data);

    EmitSoundToAll(SND_MINEACT, ent, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, 100, ent, end, NULL_VECTOR, true, 0.0);
  }

  CloseHandle(data);
}

public mineBreak (const String:output[], caller, activator, Float:delay)
{
  UnhookSingleEntityOutput(caller, "OnBreak", mineBreak);
  AcceptEntityInput(caller,"kill");
}

public bool:FilterAll (entity, contentsMask)
{
  return false;
}  
public BeamTouched(const String:output[], caller, activator, Float:delay)
{
    
    new beamOwner = GetEntProp(caller, Prop_Data, "m_iTeamNum"); 
    new team = GetClientTeam(activator);
    if (beamOwner != team)
    {
        decl String:entityName[32];
        decl String:entName[32];
        decl String:bit[2][64];
        decl String:bitt[2][64];
        new strNumber;
        new strNumber2;

        GetEntPropString(caller, Prop_Data, "m_iName", entityName, sizeof(entityName));
        ExplodeString(entityName, " ", bit, sizeof(bit), sizeof(bit[]));
        strNumber = StringToInt(bit[1], 10);
        
        new mine = -1;
        while ((mine = FindEntityByClassname(mine, "prop_physics")) != -1)
        {
            GetEntPropString(mine, Prop_Data, "m_iName", entName, sizeof(entName));
            ExplodeString(entName, " ", bitt, sizeof(bitt), sizeof(bitt[]));
            strNumber2 = StringToInt(bitt[1], 10);
            if (strNumber == strNumber2)
            {
                AcceptEntityInput(mine, "Break");
                AcceptEntityInput(caller, "Kill");
            }
        }
    }
}
Static2601 is offline
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 01-04-2015 , 02:59   Re: Tripmines exolosions
Reply With Quote #6

Thanks you for your work!
Maybe it's too stupid, but I done it this way:
Code:
    // create laser beam
    ...
    SetEntPropEnt(ent, Prop_Data, "m_hOwnerEntity", client); //m_hOwnerEntity sets to beam, not to mine.
    ...
and
Code:
    if (beamOwner != team)
    {
        new client = GetEntPropEnt(caller, Prop_Data, "m_hOwnerEntity"); 
        SDKHooks_TakeDamage( activator, client, client, 400.0, DMG_ENERGYBEAM, GetPlayerWeaponSlot( client, 1 ) );  
        ...
So now I think it's 1 less problem.

Also have (maybe stupid) idea:
Remove the mine when teammate activating it (without explosion, of corse) and then instantly place a new mine, which will work...
__________________

Last edited by uNg0veRNab1e; 01-04-2015 at 03:28.
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 01-11-2015 , 08:24   Re: [HELP] Tripmines exolosions
Reply With Quote #7

Ok, I found how to prevent the laser disabling after first touch:
Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2_stocks>

#define PLUGIN_VERSION "1.0.0.5"

#define TRACE_START 24.0
#define TRACE_END 64.0

#define MDL_LASER "sprites/laser.vmt"

#define SND_MINEPUT "npc/roller/blade_cut.wav"
#define SND_MINEACT "npc/roller/mine/rmine_blades_in2.wav"

#define TEAM_T 2
#define TEAM_CT 3

#define COLOR_T "255 0 0"
#define COLOR_CT "0 0 255"
#define COLOR_DEF "0 255 255"

#define MAX_LINE_LEN 256

// globals
new gRemaining[MAXPLAYERS+1];    // how many tripmines player has this spawn
new gCount = 1;
new String:mdlMine[256];

// convars
new Handle:cvNumMines = INVALID_HANDLE;
new Handle:cvActTime = INVALID_HANDLE;
new Handle:cvModel = INVALID_HANDLE;
new Handle:cvTeamRestricted = INVALID_HANDLE;

new Float:HitByLaserKillTime[MAXPLAYERS+1];

public Plugin:myinfo = {
    name = "Tripmines",
    author = "L. Duke fixed by Chaosxk",
    description = "Plant a trip mine",
    version = PLUGIN_VERSION,
    url = "http://www.lduke.com/"
};


public OnPluginStart() 
{
  // events
  HookEvent("player_death", PlayerDeath);
  HookEvent("player_spawn",PlayerSpawn);
  HookEntityOutput("env_beam", "OnTouchedByEntity", BeamTouched);
  
  // convars
  CreateConVar("sm_tripmines_version", PLUGIN_VERSION, "Tripmines", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  cvNumMines = CreateConVar("sm_tripmines_allowed", "10");
  cvActTime = CreateConVar("sm_tripmines_activate_time", "2.2");
  cvModel = CreateConVar("sm_tripmines_model", "models/props_lab/tpplug.mdl");
  cvTeamRestricted = CreateConVar("sm_tripmines_restrictedteam", "0");

  // commands
  RegConsoleCmd("sm_tripmine", Command_TripMine);
}

public OnEventShutdown(){
    UnhookEvent("player_death", PlayerDeath);
    UnhookEvent("player_spawn",PlayerSpawn);
}

public OnMapStart()
{
  // set model based on cvar
  GetConVarString(cvModel, mdlMine, sizeof(mdlMine));
  
  // precache models
  PrecacheModel(mdlMine, true);
  PrecacheModel(MDL_LASER, true);
  
  // precache sounds
  PrecacheSound(SND_MINEPUT, true);
  PrecacheSound(SND_MINEACT, true);
}

// When a new client is put in the server we reset their mines count
public OnClientPutInServer(client){
  if(client && !IsFakeClient(client)) gRemaining[client] = 0;
}

public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client;
    client = GetClientOfUserId(GetEventInt(event, "userid"));
    gRemaining[client] = GetConVarInt(cvNumMines);
    return Plugin_Continue;
}

public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    gRemaining[client] = 0;

    if(client > 0 && client <= client && IsClientInGame(client))
    {
        if(HitByLaserKillTime[client] != 0.0)
        {
            if(GetEngineTime() - HitByLaserKillTime[client] <= 0.1)
            {			
                new iDamageBits = GetEventInt(event, "damagebits");
                SetEventInt(event, "damagebits",  iDamageBits |= DMG_CRIT);
                SetEventString(event, "weapon_logclassname", "lasermine");
                SetEventString(event, "weapon", "world");
                SetEventInt(event, "customkill", TF_CUSTOM_PENETRATE_ALL_PLAYERS);
                SetEventInt(event, "playerpenetratecount", 1);
                HitByLaserKillTime[client] = 0.0;

                return Plugin_Continue;
            }
            HitByLaserKillTime[client] = 0.0;
        }
    }
	
    return Plugin_Continue;
}

public Action:Command_TripMine(client, args)
{
  //PrintToChatAll("%i", client);
  // make sure client is not spectating
  if (!IsPlayerAlive(client))
    return Plugin_Handled;
    
  // check restricted team 
  new team = GetClientTeam(client);
  if(team == GetConVarInt(cvTeamRestricted))
  { 
    PrintHintText(client, "Your team does not have access to this equipment.");
    return Plugin_Handled;
  }
  
  // call SetMine if any remain in client's inventory
  if (gRemaining[client]>0) {
    SetMine(client);
  }
  else {
    PrintHintText(client, "You do not have any tripmines.");
  }
  return Plugin_Handled;
}

SetMine(client)
{
  
  // setup unique target names for entities to be created with
  new String:beam[64];
  new String:beammdl[64];
  new String:tmp[128];
  Format(beam, sizeof(beam), "tmbeam %d", gCount);
  Format(beammdl, sizeof(beammdl), "tmbeammdl %d", gCount);
  gCount++;
  if (gCount>10000)
  {
    gCount = 1;
  }
  
  // trace client view to get position and angles for tripmine
  
  decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3], Float:beamend[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))
  {
    // update client's inventory
    gRemaining[client]-=1;
    
    // find angles for tripmine
    TR_GetEndPosition(end, INVALID_HANDLE);
    TR_GetPlaneNormal(INVALID_HANDLE, normal);
    GetVectorAngles(normal, normal);
    
    // trace laser beam
    TR_TraceRayFilter(end, normal, CONTENTS_SOLID, RayType_Infinite, FilterAll, 0);
    TR_GetEndPosition(beamend, INVALID_HANDLE);
     
    // create tripmine model
    new ent = CreateEntityByName("prop_physics_override");
    new team = GetClientTeam(client);
    SetEntityModel(ent,mdlMine);
    SetEntProp(ent, Prop_Data, "m_iMaxHealth", 1000);
    SetEntProp(ent, Prop_Data, "m_iHealth", 1000);
    SetEntityMoveType(ent, MOVETYPE_NONE);
    DispatchKeyValue(ent, "targetname", beammdl);
    DispatchKeyValue(ent, "ExplodeRadius", "256");
    DispatchKeyValue(ent, "ExplodeDamage", "0");
    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", 0);
    SetEntPropFloat(ent, Prop_Send, "m_flModelScale", 1.1);
    DispatchSpawn(ent);
    ActivateEntity(ent);
    TeleportEntity(ent, end, normal, NULL_VECTOR);
    SetEntProp(ent, Prop_Send, "m_CollisionGroup", 1);//1
    SetEntProp(ent, Prop_Send, "m_usSolidFlags", 152);
    SetEntProp(ent, Prop_Data, "m_MoveCollide", 0);
    SetEntProp(ent, Prop_Send, "m_nSolidType", 6);
    SetEntProp(ent, Prop_Data, "m_iTeamNum", team, 6, 0);     
    SetEntPropEnt(ent, Prop_Data, "m_hOwnerEntity", client);
    AcceptEntityInput(ent, "DisableMotion");
    //HookSingleEntityOutput(ent, "OnBreak", mineBreak, true);
    //SDKHook(ent, SDKHook_OnTakeDamage, OnEntDamaged);
    new Handle:pack = CreateDataPack();
    CreateTimer(GetConVarFloat(cvActTime), TurnPropOn, pack);
    WritePackCell(pack, client);
    WritePackCell(pack, ent);

    
    // create laser beam
    ent = CreateEntityByName("env_beam");
    TeleportEntity(ent, beamend, NULL_VECTOR, NULL_VECTOR);
    SetEntityModel(ent, MDL_LASER);
    DispatchKeyValue(ent, "texture", MDL_LASER);
    SetEntProp(ent, Prop_Data, "m_iTeamNum", team, 6, 0);
    SetEntPropEnt(ent, Prop_Data, "m_hOwnerEntity", client);
    DispatchKeyValue(ent, "targetname", beam);
    DispatchKeyValue(ent, "TouchType", "4");
    DispatchKeyValue(ent, "LightningStart", beam);
    DispatchKeyValue(ent, "BoltWidth", "16.0");
    DispatchKeyValue(ent, "life", "0");
    DispatchKeyValue(ent, "rendercolor", "0 0 0");
    DispatchKeyValue(ent, "renderamt", "0");
    DispatchKeyValue(ent, "HDRColorScale", "1.0");
    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_Data, "m_vecEndPos", end);
    SetEntPropFloat(ent, Prop_Data, "m_fWidth", 16.0);
    //AcceptEntityInput(ent, "TurnOff");

    new Handle:data = CreateDataPack();
    CreateTimer(GetConVarFloat(cvActTime), TurnBeamOn, data);
    WritePackCell(data, client);
    WritePackCell(data, ent);
    WritePackFloat(data, end[0]);
    WritePackFloat(data, end[1]);
    WritePackFloat(data, end[2]);
    
    // play sound
    EmitSoundToAll(SND_MINEPUT, ent, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, 100, ent, end, NULL_VECTOR, true, 0.0);
    
    // send message
    PrintHintText(client, "Tripmines remaining: %d", gRemaining[client]);
  }
  else
  {
    PrintHintText(client, "Invalid location for Tripmine");
  }
}

public Action:TurnPropOn(Handle:timer, Handle:pack)
{
  ResetPack(pack);
  new client = ReadPackCell(pack);
  new ent = ReadPackCell(pack);
  
  SetEntProp(ent, Prop_Send, "m_CollisionGroup", 0);  
  SetEntProp(ent, Prop_Data, "m_takedamage", 2);
  client+=0;//...
  CloseHandle(pack);
}

public Action:TurnBeamOn(Handle:timer, Handle:data)
{
  decl String:color[26];

  ResetPack(data);
  new client = ReadPackCell(data);
  new ent = ReadPackCell(data);

  if (IsValidEntity(ent))
  {
    new team = GetClientTeam(client);
    if(team == TEAM_T) color = COLOR_T;
    else if(team == TEAM_CT) color = COLOR_CT;
    else color = COLOR_DEF;

    DispatchKeyValue(ent, "rendercolor", color);
    AcceptEntityInput(ent, "TurnOn");

    new Float:end[3];
    end[0] = ReadPackFloat(data);
    end[1] = ReadPackFloat(data);
    end[2] = ReadPackFloat(data);

    EmitSoundToAll(SND_MINEACT, ent, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, 100, ent, end, NULL_VECTOR, true, 0.0);
  }

  CloseHandle(data);
}

public mineBreak (const String:output[], caller, activator, Float:delay)
{
  UnhookSingleEntityOutput(caller, "OnBreak", mineBreak);
  AcceptEntityInput(caller,"kill");
  //PrintToChatAll("OnBreak");
}

public bool:FilterAll (entity, contentsMask)
{
  return false;
}  
public BeamTouched(const String:output[], caller, activator, Float:delay)
{    
    new beamOwner = GetEntProp(caller, Prop_Data, "m_iTeamNum"); 
    new client = GetEntPropEnt(caller, Prop_Data, "m_hOwnerEntity"); 
    new team = GetClientTeam(activator);
    //PrintToChatAll("beamowner = %i, caller = %i, team = %i, activator = %i, client = %i", beamOwner, caller, team, activator, client);
    if (beamOwner != team)
    {
		HitByLaserKillTime[activator] = GetEngineTime();
		SDKHooks_TakeDamage( activator, client, client, 400.0, DMG_PREVENT_PHYSICS_FORCE );  
    }
    decl String:entityName[32];
    decl String:entName[32];
    decl String:bit[2][64];
    decl String:bitt[2][64];
    new strNumber;
    new strNumber2;

    GetEntPropString(caller, Prop_Data, "m_iName", entityName, sizeof(entityName));
    ExplodeString(entityName, " ", bit, sizeof(bit), sizeof(bit[]));
    strNumber = StringToInt(bit[1], 10);
    
    new mine = -1;
    while ((mine = FindEntityByClassname(mine, "prop_physics")) != -1)
    {
        GetEntPropString(mine, Prop_Data, "m_iName", entName, sizeof(entName));
        ExplodeString(entName, " ", bitt, sizeof(bitt), sizeof(bitt[]));
        strNumber2 = StringToInt(bitt[1], 10);
        if (strNumber == strNumber2)
        {
            AcceptEntityInput(caller, "TurnOff");
            AcceptEntityInput(caller, "TurnOn");
            //AcceptEntityInput(caller, "Kill");
        }
    }
}
 
/*public Action:OnEntDamaged(prop, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3], damagecustom)
{
	if (attacker <= 0 || attacker >= MaxClients)
		return Plugin_Continue;
	else if (!IsClientInGame(attacker))
		return Plugin_Continue;
	else if (!IsValidEntity(prop))
		return Plugin_Continue;
	else if (!IsPlayerAlive(attacker))
		return Plugin_Continue;

	new propOwner = GetEntProp(prop, Prop_Data, "m_iTeamNum"); 
	new client = GetEntProp(prop, Prop_Data, "m_hOwnerEntity"); 
	if (GetClientTeam(attacker) != propOwner || attacker == client)
	{
		damage = float(GetEntProp(prop, Prop_Data, "m_iMaxHealth") / 3); // 1 hit = 1/3 hp of mine
		return Plugin_Changed;
	}
	else if(GetClientTeam(attacker) == propOwner)
	{
		damage = float(GetEntProp(prop, Prop_Data, "m_iMaxHealth") / 6); // 1 hit = 1/6 hp of mine
		return Plugin_Changed;
	}
	return Plugin_Continue;
}*/
Now laser works fine.

Now the last question:
How to prevent the mine break on every hit and from teammates?
I tried to set hp for mine or hook OnTakeDamage, but nothing works.
__________________

Last edited by uNg0veRNab1e; 01-11-2015 at 08:25.
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
Horsedick
AlliedModders Donor
Join Date: Sep 2011
Old 01-11-2015 , 10:30   Re: [HELP] Tripmines exolosions
Reply With Quote #8

is the distance still the same on this version just posted of this to where you have to be lookign straight down to drop them or can that be expanded to place them where cross hairs are aiming?
Horsedick is offline
uNg0veRNab1e
Member
Join Date: Jan 2013
Location: Russia, Siberia
Old 01-14-2015 , 07:25   Re: [HELP] Tripmines exolosions
Reply With Quote #9

Quote:
Originally Posted by Horsedick View Post
is the distance still the same on this version just posted of this to where you have to be lookign straight down to drop them or can that be expanded to place them where cross hairs are aiming?
If I understand your question right - the mine places on the wall or ground where your crosshair is aiming.

Also bumping.
Quote:
How to prevent the mine break on every hit and from teammates?
I tried to set hp for mine or hook OnTakeDamage, but nothing works.
__________________

Last edited by uNg0veRNab1e; 01-14-2015 at 08:11.
uNg0veRNab1e is offline
Send a message via Skype™ to uNg0veRNab1e
Horsedick
AlliedModders Donor
Join Date: Sep 2011
Old 01-14-2015 , 19:27   Re: [HELP] Tripmines exolosions
Reply With Quote #10

Quote:
Originally Posted by uNg0veRNab1e View Post
If I understand your question right - the mine places on the wall or ground where your crosshair is aiming.

Also bumping.
Well they should go to a wall if you wanted I guess which would then beam from end to end so that is fine but my ideal situation would be sitting in a spot aiming across the map to spawn a mine way away from me. As it stands now you have to be looking straight down to place a mine.
Horsedick is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:58.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode