Raised This Month: $ Target: $400
 0% 

Help creating a "mine"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Remy Lebeau
Senior Member
Join Date: Dec 2009
Location: Sydney, Australia
Old 06-15-2013 , 00:33   Help creating a "mine"
Reply With Quote #1

So I'm creating a race for my war3 server, and I want it to be able to place "mines".

Pretty basic idea - you can attach an entity to a surface, then if someone comes near it, it blows up doing damage.

I've found a plugin that seems to be quite close to what I'm after (http://forums.alliedmods.net/showthread.php?t=70782) - I'd happily use that code, however that plugin doesn't work.

I've tried getting it working, however get the following error:
Quote:
L 06/13/2013 - 21:07:12: [SM] Native "SetEntProp" reported: Property "m_usSolidFlags" not safe to access (entity 79/prop_physics)
L 06/13/2013 - 21:07:12: [SM] Displaying call stack trace for plugin "w3s\w3s_custom_races\tripmines.smx":
L 06/13/2013 - 21:07:12: [SM] [0] Line 161, /home/groups/alliedmodders/forums/files/3/2/2/9/8/26520.attach::SetMine()
L 06/13/2013 - 21:07:12: [SM] [1] Line 101, /home/groups/alliedmodders/forums/files/3/2/2/9/8/26520.attach::Command_TripMine()
Is the way that this plugin goes about it still the best way?

I haven't really done much work with entities (beyond tempents) so far, so I'm pretty rookie in this area.

I'm envisioning simply placing an entity in a location, then running a timer that calculates player's distances from it and if they get to close blowing it up, however I'm not even really sure how to do that... (Also, what would the server load be if I'm tracking everyone's position constantly...)

Having a "trip" line that is an entity that breaks which sets off the explosion would also work, but I really have no idea how to do that!

Any and every help much appreciated.
Remy Lebeau is offline
Remy Lebeau
Senior Member
Join Date: Dec 2009
Location: Sydney, Australia
Old 06-15-2013 , 02:23   Re: Help creating a "mine"
Reply With Quote #2

So I've updated the entity code to the following:

Code:
        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_Send, "m_takedamage", 2);
        AcceptEntityInput(ent, "Enable");
        HookSingleEntityOutput(ent, "OnBreak", mineBreak, true);
Which now works perfectly! (and is really quite freaking cool). My remaining problem is friendly fire... Because this is a system environment, the explosion does damage indiscriminately (which is a problem!) Is there any way to get an entity explosion to respect the friend fire setting?
Remy Lebeau is offline
Remy Lebeau
Senior Member
Join Date: Dec 2009
Location: Sydney, Australia
Old 06-15-2013 , 04:11   Re: Help creating a "mine"
Reply With Quote #3

So I've worked out a way of making it friendly fire compliant, however I'd really prefer it so that my team mates can't actually set the mines off ... Is there a property I can set so that only a certain team can trigger the beam or is that asking too much ?
Remy Lebeau is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-15-2013 , 04:19   Re: Help creating a "mine"
Reply With Quote #4

Quote:
Originally Posted by Remy Lebeau View Post
So I've worked out a way of making it friendly fire compliant, however I'd really prefer it so that my team mates can't actually set the mines off ... Is there a property I can set so that only a certain team can trigger the beam or is that asking too much ?
Whatever your using to trigger the mines off, use GetClientTeam(client) before it is triggered.
Then just make sure that only the opposite team of client can trigger it.
__________________

Last edited by Chaosxk; 06-15-2013 at 04:19.
Chaosxk is offline
Remy Lebeau
Senior Member
Join Date: Dec 2009
Location: Sydney, Australia
Old 06-15-2013 , 05:52   Re: Help creating a "mine"
Reply With Quote #5

Quote:
Originally Posted by Chaosxk View Post
Whatever your using to trigger the mines off, use GetClientTeam(client) before it is triggered.
Then just make sure that only the opposite team of client can trigger it.
TBH, I don't really understand what's going on well enough to know where to do that...

Here's a fuller section of the code:

Code:
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");
        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");
        
        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;
}
Is it in the minebreak function that I check?

Last edited by Remy Lebeau; 06-15-2013 at 05:53.
Remy Lebeau is offline
API
Veteran Member
Join Date: May 2006
Old 06-15-2013 , 11:45   Re: Help creating a "mine"
Reply With Quote #6

Oh I see. The mine is just breakable.

Instead, you should give it unlimited health maybe and just check when it gets shot / stepped near. Then you can force your own trigger.

Since right now you just use OnBreak, you might need to rethink your strategy.

Edit: maybe also try a OnTakeDamage hook. Then you could stick with breakable
__________________

Last edited by API; 06-15-2013 at 14:12.
API is offline
Send a message via AIM to API
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 06-15-2013 , 15:15   Re: Help creating a "mine"
Reply With Quote #7

You could use SDKHook_StartTouch to detect when a player steps on the mine.

Then when StartTouch is called, force break the mine. Then check the owner of the mine and the player who stepped on it.

Then use something like this.
Quote:
new ownerTeam = GetClientTeam(owner);
new victimTeam = GetClientTeam(victim);
if(ownerTeam != victimTeam) {
//continue with code
}
You could also use what pimp said to blow up the mine when someone shoots it.
__________________

Last edited by Chaosxk; 06-15-2013 at 15:17.
Chaosxk is offline
moriss
Junior Member
Join Date: Dec 2011
Location: Hungary
Old 06-15-2013 , 18:00   Re: Help creating a "mine"
Reply With Quote #8

Maybe you should try to spawn an env_explosion and set m_hOwnerEntity and m_iTeamNum the same as the clients' so it won't hurt teammates when it explodes.
moriss is offline
Remy Lebeau
Senior Member
Join Date: Dec 2009
Location: Sydney, Australia
Old 06-16-2013 , 18:59   Re: Help creating a "mine"
Reply With Quote #9

Thanks for the suggestions guys.

I've already got it respecting FF - I just check on damage, verify the teams, and set the damage to 0 if necessary.

Ideally though I would love to set it up so that team mates don't trigger the mines at all (ie, can just run through the laser beam without tripping it). Since players have limited mines, it's pretty annoying when your own team keeps setting them off... Alternatively, if I leave FF damage on, then it effectively blocks off your own team as well as the opposition!
Remy Lebeau 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 23:08.


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