• Print

Author Topic: Kill by an Alt Fire  (Read 8877 times)

0 Members and 1 Guest are viewing this topic.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Kill by an Alt Fire
« on: November 08, 2015, 07:09:41 am »
Mainly the title, but I can't give a good explanation about what Im trying to do in a title. So heres this, is there a way to kill an entity via something else besides suicide when you do entity:Kill(). So if you were trying to kill an Entity with a combine ball from the AR2 and give it the dissolve effect when it dies (which is what happens when an entity or player dies with an AR2 combine ball). And if so, make the death in the top right silent, so it doesn't show up.

EDIT: Someone pointed out !teleport to me before I fully knew what it was so I started making something like it and came up with this. This is why Im trying to get the death, the sneakily teleport away and leave a dead corpse beside them so it looks like they're fully gone. I looked at the teleport code and its no where near what I could think of or do, so if this isn't even close to something that would work (the teleporting part) then please let me know :D
Another edit: Added GetEyeTrace().HitPos to get the hit position, suggestion from Timmy
Code: Lua
  1. local CATEGORY_NAME = "Admin Suite"
  2.  
  3. function ulx.jump( ply )
  4.         local entity = ents.Create( "npc_combine_s" ) -- Entity can change, just using combine till I get a duplicate entity of the player model that works
  5.         entity:SetModel( ply:GetModel() )
  6.         entity:SetPos( ply:GetPos() ) -- Tells the entity to spawn where the player is before they jump away
  7.         entity:Spawn()
  8.         ply:SetPos( ply:GetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) ) ) -- Vector to raise the player so they aren't stuck in the ground :D
  9.         -- Add in the entity death by combine ball here (dissolve I think)
  10. end
  11. local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, "!jump" )
  12. jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
  13. jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )
« Last Edit: November 12, 2015, 01:34:51 pm by WispySkies »

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #1 on: November 08, 2015, 05:45:37 pm »
Final code works here:
Code: Lua
  1. local CATEGORY_NAME = "Admin Suite"
  2.  
  3. function ulx.jump( ply )
  4.         -- Create player dummy
  5.         local entity = ents.Create( "npc_combine_s" )
  6.         entity:SetModel( ply:GetModel() )
  7.         entity:SetPos( ply:GetPos() )
  8.  
  9.         -- Teleport player
  10.         ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
  11.  
  12.         -- Spawn dummy
  13.         entity:Spawn() -- Entity interferes with EyeTrace so spawn it after
  14.        
  15.         -- Dissolve dummy
  16.         local info = DamageInfo()
  17.         info:SetDamageType( DMG_DISSOLVE )
  18.         info:SetDamage( entity:Health() )
  19.         info:SetAttacker( entity )
  20.         info:SetInflictor( entity )
  21.         entity:TakeDamageInfo( info )
  22.  
  23.         -- Broadcast the command to the ply.
  24.         ply:ChatPrint( "You have dissolved and have been jumped to your crosshair!" )
  25. end
  26. local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, { "!jump", "!launch" } )
  27. jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
  28. jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )
TODO:
Figure out how to hide the death (currently shows a suiciding #npc_combine_s in the top right) Please tell me if you know how!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Kill by an Alt Fire
« Reply #2 on: November 08, 2015, 08:03:14 pm »
Just guessing, try commenting out the setattacker and setinflictor lines.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #3 on: November 09, 2015, 04:09:31 am »
Just guessing, try commenting out the setattacker and setinflictor lines.
Some of this I don't understand, but me and Timmy message a lot and he grabbed stuff from TTT code to prevent the death.
Code: Lua
  1. local CATEGORY_NAME = "Admin Suite"
  2.  
  3. function ulx.jump( ply )
  4.     -- Create ragdoll (Extracted from the TTT gamemode)
  5.     local rag = ents.Create( "prop_ragdoll" )
  6.     rag:SetPos( ply:GetPos() )
  7.     rag:SetModel( ply:GetModel() )
  8.     rag:SetAngles( ply:GetAngles() )
  9.     rag:SetColor( ply:GetColor() )
  10.  
  11.     rag:Spawn()
  12.     rag:Activate()
  13.  
  14.     rag:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )
  15.     rag:SetKeyValue( "targetname", "cleanser_dissolve" )
  16.  
  17.     for i=0, rag:GetPhysicsObjectCount() - 1 do
  18.       local bone = rag:GetPhysicsObjectNum( i )
  19.       if IsValid( bone ) then
  20.          local bp, ba = ply:GetBonePosition( rag:TranslatePhysBoneToBone(i ) )
  21.          if bp and ba then bone:SetPos( bp ) bone:SetAngles( ba ) end
  22.       end
  23.    end
  24.  
  25.     -- Dissolve ragdoll (https://facepunch.com/showthread.php?t=1378865&p=44333364&viewfull=1#post44333364)
  26.     local dissolver = ents.Create( "env_entity_dissolver" )
  27.     dissolver:Spawn()
  28.     dissolver:Activate()
  29.     dissolver:SetKeyValue( "target", "cleanser_dissolve" )
  30.     dissolver:SetKeyValue( "magnitude", 100 )
  31.     dissolver:SetKeyValue( "dissolvetype", 0 )
  32.     dissolver:Fire( "Dissolve" )
  33.     timer.Simple( 0.1, function() dissolver:Remove() end )
  34.  
  35.     ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
  36.     ply:ChatPrint( "You have dissolved and have been jumped to your crosshair!" )
  37. end
  38. local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, { "!jump", "!launch" } )
  39. jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
  40. jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )
Edit: Is there any way that I can make it so that I don't get stuck in a wall using this command? When I get stuck I have to run it again
« Last Edit: November 09, 2015, 04:37:24 am by WispySkies »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Kill by an Alt Fire
« Reply #4 on: November 09, 2015, 03:15:38 pm »
Check out ULX's teleport/goto/bring code. It has some wall/ceiling/floor checks in it somewhere.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #5 on: November 09, 2015, 05:42:42 pm »
After reading through it, I don't really understand how it works D:
Mind pointing me in some direction?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Kill by an Alt Fire
« Reply #6 on: November 09, 2015, 07:04:56 pm »
After reading through it, I don't really understand how it works D:
Mind pointing me in some direction?
https://github.com/Nayruden/Ulysses/blob/5f2d3cd9a0cda728fef17851eba421c6f6ae0dd4/ulx/lua/ulx/modules/sh/teleport.lua#L4
playerSend - that _entire_ function is dedicated to moving player from point A to point B without getting stuck, UNLESS, 'force' is true.
You're welcome to use the code, as long as proper credit is given matching ULX's licensing.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #7 on: November 10, 2015, 04:42:04 am »
https://github.com/Nayruden/Ulysses/blob/5f2d3cd9a0cda728fef17851eba421c6f6ae0dd4/ulx/lua/ulx/modules/sh/teleport.lua#L4
playerSend - that _entire_ function is dedicated to moving player from point A to point B without getting stuck, UNLESS, 'force' is true.
You're welcome to use the code, as long as proper credit is given matching ULX's licensing.
Aye! Thanks, I just went to the code for the command and saw some stuff on angles but I knew it was more than that! I'll put in credit when adding it in :D

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #8 on: November 10, 2015, 06:31:07 am »
I think I wrote the License stuff fine, but is this what you're supposed to do? (Line 85 to 90, and the playerSend function)
Code: Lua
  1. local CATEGORY_NAME = "Admin Suite"
  2.  -- Local function playerSend is taken from ULX source code, ulyssesmod.net, and is licensed under the MIT license. A copy can be found here, https://github.com/TeamUlysses/ulx4/blob/master/LICENSE.
  3. local function playerSend( from, to, force )
  4.         if not to:IsInWorld() and not force then return false end -- No way we can do this one
  5.  
  6.         local yawForward = to:EyeAngles().yaw
  7.         local directions = { -- Directions to try
  8.                 math.NormalizeAngle( yawForward - 180 ), -- Behind first
  9.                 math.NormalizeAngle( yawForward + 90 ), -- Right
  10.                 math.NormalizeAngle( yawForward - 90 ), -- Left
  11.                 yawForward,
  12.         }
  13.  
  14.         local t = {}
  15.         t.start = to:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  16.         t.filter = { to, from }
  17.  
  18.         local i = 1
  19.         t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47 -- (33 is player width, this is sqrt( 33^2 * 2 ))
  20.         local tr = util.TraceEntity( t, from )
  21.         while tr.Hit do -- While it's hitting something, check other angles
  22.                 i = i + 1
  23.                 if i > #directions then  -- No place found
  24.                         if force then
  25.                                 from.ulx_prevpos = from:GetPos()
  26.                                 from.ulx_prevang = from:EyeAngles()
  27.                                 return to:GetPos() + Angle( 0, directions[ 1 ], 0 ):Forward() * 47
  28.                         else
  29.                                 return false
  30.                         end
  31.                 end
  32.  
  33.                 t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47
  34.  
  35.                 tr = util.TraceEntity( t, from )
  36.         end
  37.  
  38.         from.ulx_prevpos = from:GetPos()
  39.         from.ulx_prevang = from:EyeAngles()
  40.         return tr.HitPos
  41. end
  42.  
  43. function ulx.jump( ply )
  44.     if not ply:IsAlive() then
  45.         ply:ChatPrint( "You're dead!" )
  46.     end
  47.     if not ply:IsValid() then
  48.         Msg( "The land of the console can not be moved.\n" )
  49.     end
  50.     if ply:IsInVehicle() then
  51.         ply:ExitVehicle()
  52.     end
  53.    
  54.     -- Create ragdoll (Extracted from the TTT gamemode)
  55.     local rag = ents.Create( "prop_ragdoll" )
  56.     rag:SetPos( ply:GetPos() )
  57.     rag:SetModel( ply:GetModel() )
  58.     rag:SetAngles( ply:GetAngles() )
  59.     rag:SetColor( ply:GetColor() )
  60.  
  61.     rag:Spawn()
  62.     rag:Activate()
  63.  
  64.     rag:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )
  65.     rag:SetKeyValue( "targetname", "cleanser_dissolve" )
  66.  
  67.     for i=0, rag:GetPhysicsObjectCount() - 1 do
  68.       local bone = rag:GetPhysicsObjectNum( i )
  69.       if IsValid( bone ) then
  70.          local bp, ba = ply:GetBonePosition( rag:TranslatePhysBoneToBone(i ) )
  71.          if bp and ba then bone:SetPos( bp ) bone:SetAngles( ba ) end
  72.       end
  73.    end
  74.  
  75.     -- Dissolve ragdoll
  76.     local dissolver = ents.Create( "env_entity_dissolver" )
  77.     dissolver:Spawn()
  78.     dissolver:Activate()
  79.     dissolver:SetKeyValue( "target", "cleanser_dissolve" )
  80.     dissolver:SetKeyValue( "magnitude", 100 )
  81.     dissolver:SetKeyValue( "dissolvetype", 0 )
  82.     dissolver:Fire( "Dissolve" )
  83.     timer.Simple( 0.1, function() dissolver:Remove() end )
  84.  
  85.     ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
  86.     local newpos = playerSend( ply, ply:GetMoveType() == MOVETYPE_NOCLIP )
  87.         if not newpos then
  88.                 ULib.tsayError( ply, "Can't find a place to put you!", true )
  89.                 return
  90.         end
  91.     ply:ChatPrint( "You have dissolved and have jumped to your crosshair!" )
  92. end
  93. local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, { "!jump", "!launch" } )
  94. jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
  95. jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )
« Last Edit: November 10, 2015, 06:33:14 am by WispySkies »

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Kill by an Alt Fire
« Reply #9 on: November 10, 2015, 08:34:59 am »
I think I wrote the License stuff fine, but is this what you're supposed to do? (Line 85 to 90, and the playerSend function)
Code: Lua
  1. local CATEGORY_NAME = "Admin Suite"
  2.  -- Local function playerSend is taken from ULX source code, ulyssesmod.net, and is licensed under the MIT license. A copy can be found here, https://github.com/TeamUlysses/ulx4/blob/master/LICENSE.
  3. local function playerSend( from, to, force )
  4.         if not to:IsInWorld() and not force then return false end -- No way we can do this one
  5.  
  6.         local yawForward = to:EyeAngles().yaw
  7.         local directions = { -- Directions to try
  8.                 math.NormalizeAngle( yawForward - 180 ), -- Behind first
  9.                 math.NormalizeAngle( yawForward + 90 ), -- Right
  10.                 math.NormalizeAngle( yawForward - 90 ), -- Left
  11.                 yawForward,
  12.         }
  13.  
  14.         local t = {}
  15.         t.start = to:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
  16.         t.filter = { to, from }
  17.  
  18.         local i = 1
  19.         t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47 -- (33 is player width, this is sqrt( 33^2 * 2 ))
  20.         local tr = util.TraceEntity( t, from )
  21.         while tr.Hit do -- While it's hitting something, check other angles
  22.                 i = i + 1
  23.                 if i > #directions then  -- No place found
  24.                         if force then
  25.                                 from.ulx_prevpos = from:GetPos()
  26.                                 from.ulx_prevang = from:EyeAngles()
  27.                                 return to:GetPos() + Angle( 0, directions[ 1 ], 0 ):Forward() * 47
  28.                         else
  29.                                 return false
  30.                         end
  31.                 end
  32.  
  33.                 t.endpos = to:GetPos() + Angle( 0, directions[ i ], 0 ):Forward() * 47
  34.  
  35.                 tr = util.TraceEntity( t, from )
  36.         end
  37.  
  38.         from.ulx_prevpos = from:GetPos()
  39.         from.ulx_prevang = from:EyeAngles()
  40.         return tr.HitPos
  41. end
  42.  
  43. function ulx.jump( ply )
  44.     if not ply:IsAlive() then
  45.         ply:ChatPrint( "You're dead!" )
  46.     end
  47.     if not ply:IsValid() then
  48.         Msg( "The land of the console can not be moved.\n" )
  49.     end
  50.     if ply:IsInVehicle() then
  51.         ply:ExitVehicle()
  52.     end
  53.    
  54.     -- Create ragdoll (Extracted from the TTT gamemode)
  55.     local rag = ents.Create( "prop_ragdoll" )
  56.     rag:SetPos( ply:GetPos() )
  57.     rag:SetModel( ply:GetModel() )
  58.     rag:SetAngles( ply:GetAngles() )
  59.     rag:SetColor( ply:GetColor() )
  60.  
  61.     rag:Spawn()
  62.     rag:Activate()
  63.  
  64.     rag:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )
  65.     rag:SetKeyValue( "targetname", "cleanser_dissolve" )
  66.  
  67.     for i=0, rag:GetPhysicsObjectCount() - 1 do
  68.       local bone = rag:GetPhysicsObjectNum( i )
  69.       if IsValid( bone ) then
  70.          local bp, ba = ply:GetBonePosition( rag:TranslatePhysBoneToBone(i ) )
  71.          if bp and ba then bone:SetPos( bp ) bone:SetAngles( ba ) end
  72.       end
  73.    end
  74.  
  75.     -- Dissolve ragdoll
  76.     local dissolver = ents.Create( "env_entity_dissolver" )
  77.     dissolver:Spawn()
  78.     dissolver:Activate()
  79.     dissolver:SetKeyValue( "target", "cleanser_dissolve" )
  80.     dissolver:SetKeyValue( "magnitude", 100 )
  81.     dissolver:SetKeyValue( "dissolvetype", 0 )
  82.     dissolver:Fire( "Dissolve" )
  83.     timer.Simple( 0.1, function() dissolver:Remove() end )
  84.  
  85.     ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
  86.     local newpos = playerSend( ply, ply:GetMoveType() == MOVETYPE_NOCLIP )
  87.         if not newpos then
  88.                 ULib.tsayError( ply, "Can't find a place to put you!", true )
  89.                 return
  90.         end
  91.     ply:ChatPrint( "You have dissolved and have jumped to your crosshair!" )
  92. end
  93. local jump = ulx.command( CATEGORY_NAME, "ulx jump", ulx.jump, { "!jump", "!launch" } )
  94. jump:defaultAccess( ULib.ACCESS_SUPERADMIN )
  95. jump:help( "Jump to where you are looking, and leave a dissolving body in the background." )
Code: Lua
  1. ply:SetPos( ply:GetEyeTrace().HitPos + Vector( 0, 0, 32 ) )
  2.     local newpos = playerSend( ply, ply:GetMoveType() == MOVETYPE_NOCLIP )
You don't actually send them to the position newpos, only store it. Move your SetPos call to just above the ChatPrint call, and pass it the newpos variable instead.
bw81@ulysses-forums ~ % whoami
Homepage

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #10 on: November 10, 2015, 01:58:48 pm »
Changing the code to extractions of !tp, I'll post again when its completed.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: Kill by an Alt Fire
« Reply #11 on: November 11, 2015, 03:04:15 pm »
Mainly the title, but I can't give a good explanation about what Im trying to do in a title.

Actually is the reason why I clicked this topic, was because of such an odd title.


And if so, make the death in the top right silent, so it doesn't show up.

Didn't read anything after the original post, but there is something called ply:KillSilent() and it will not display the death of any player on the top right. I don't even think console knows they "died".
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #12 on: November 11, 2015, 04:42:10 pm »
Actually is the reason why I clicked this topic, was because of such an odd title.


Didn't read anything after the original post, but there is something called ply:KillSilent() and it will not display the death of any player on the top right. I don't even think console knows they "died".
After this "prank" some kid pulled on my laptop I'm currently not able to access the code, but I figured it out how to get the death silent (thanks Timmy) in which I'll post soon when my editor is fixed. I'll give you a general to do list of what I'm doing:
- The ragdoll does not stand up, it just falls and dissolves (should copy player angles)
- The ragdoll does not change colour based on the player.
- Wall checks if you're stuck in it. !teleport didn't reveal much (Jammin, that function was for bring, goto, and send, tp code was about targets, position etc.)

Miscellaneous:
- I noticed in the teleport code it sets the player vector by 0, 0, 32 before you move, this causes a jump look when you perform the command so it moves you up and down when moving. ply:SetPos( ply:GetPos().HitPos + Vector( 0, 0, 32 ) ) moves you to where you are and up smoothly.

Edit: I em ah grammer en inglesh pru. Meh, grammar edits
« Last Edit: November 11, 2015, 04:44:50 pm by WispySkies »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Kill by an Alt Fire
« Reply #13 on: November 11, 2015, 06:10:30 pm »
... Wispy, I know that.
I meant more as a learning experience for checks to do as player is spawning at new position to avoid getting stuck.
Though the function may not be what you need, the checks within most likely are.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline WispySkies

  • Full Member
  • ***
  • Posts: 144
  • Karma: 0
  • I make random commands and Lua errors.
Re: Kill by an Alt Fire
« Reply #14 on: November 12, 2015, 04:03:42 am »
... Wispy, I know that.
I meant more as a learning experience for checks to do as player is spawning at new position to avoid getting stuck.
Though the function may not be what you need, the checks within most likely are.
Oh, then we'll thank you! I just got confused around when you said the whole function earlier. My bad. :D

  • Print