Author Topic: Trying to recreate an old command  (Read 1934 times)

0 Members and 1 Guest are viewing this topic.

Offline rejax

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Trying to recreate an old command
« on: May 08, 2013, 02:20:57 AM »
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.
Code: [Select]
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  :D) 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.
« Last Edit: May 08, 2013, 04:37:43 AM by rejax »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Trying to recreate an old command
« Reply #1 on: May 08, 2013, 05:58:53 AM »
rejax, we can't be of much help here. This is one of those problems you're just going to have to try a lot of different options on until you find one that works. On collisions, try this or this. On the angle, you're just going to have to apply whatever rotation is necessary manually.
Experiencing God's grace one day at a time.