Hi!
Backstory:
So I used to play on a server with a joke command called !trainkill <player> and I thought it was great.
So now I am thinking of starting my own server but I want to get all my commands and stuff ready before I do. I googled it and found some old versions of !trainkill that don't work with gmod 13 so now I'm trying to fix them.
Problem is I have never touched lua and I'm trying to fix old sweps and addons as a way of teaching myself, as I can't find any tutorials.
SO-
Now I have some semi working code which kills the player maybe 40% of the time. I got desperate so I made it so it sets the players health to 0 too.
function SpawnTrain( Pos, Direction )
local train = ents.Create( "prop_physics" )
train:SetModel("models/props_trainstation/train001.mdl")
train:SetAngles( Direction:Angle() )
train:SetPos( Pos )
train:Spawn()
train:SetCollisionGroup( COLLISION_GROUP_WORLD )
train:Activate()
train:EmitSound( "ambient/alarms/train_horn2.wav", 100, 100 )
train:GetPhysicsObject():SetVelocity( Direction * 100000 )
timer.Create( "TrainRemove_"..CurTime(), 5, 1, function() if not IsValid(train) then return end train:Remove() end)
end
function ulx.trainkill( calling_ply, target_plys )
for _, ply in ipairs( target_plys, calling_ply ) do
local Hp = ply:Health()
local Dif = Hp - 0
local HpOut = Hp - Dif
local HpSur = Hp + Dif
ply:SetMoveType( MOVETYPE_WALK )
ply:GodDisable()
ply:SetHealth(HpOut)
SpawnTrain( ply:GetPos() + ply:GetForward() * 750 + Vector(0,100,0), ply:GetForward() * -1 )
ply:GodDisable()
ply:SetMoveType( MOVETYPE_WALK )
timer.Create( "trainKillNot_", 6.5, 1, function( target_plys )
if ply:Alive() then ply:SetHealth(HpSur) else end
end )
end
ulx.fancyLogAdmin( calling_ply, "#A trainkilled #T", target_plys )
end
local trainkill = ulx.command( "Fun", "ulx trainkill", ulx.trainkill, "!trainkill" )
trainkill:addParam{ type=ULib.cmds.PlayersArg }
trainkill:defaultAccess( ULib.ACCESS_ADMIN )
trainkill:help( "kill a player with a train." )
So the problems with this (flawless
) code is that:
- It (the train) clips inside the world and gets stuck. So I was thinking of ways to make it only collide with the player. I used train:SetCollisionGroup( COLLISION_GROUP_WORLD ) but the wiki lied and it doesnt collide with anything.
- Also, the train spawns on an angle instead of head on.
So I have some ideas on how to fix this - including using a timer to just make the player gib when the train would normally hit them. I don't really know how to though because I'm not too crash hot at LUA.
If anyone could help I would be super appreaciative. In the meantime I'll just be trying to get it working.
*Edit by MrPresident* : Removed profanities. I understand that the word is being used in context with your script, but irregardless, we have younger users who use these forums and we try and keep it at a PG-13 level or better.