• Print

Author Topic: ULX Stuck command  (Read 13271 times)

0 Members and 1 Guest are viewing this topic.

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
ULX Stuck command
« on: May 03, 2014, 11:31:28 pm »
Ok, so I found the very basic ULX unstuck command. I know to not edit the actual ULX files, so I put my lua in addons/myULXaddons/lua/ulx/modules/sh. Also copied the info file. It doesn't load it. That's the first problem.
So I've been experimenting, best way to learn right? I want to make it to where the server is alerted when people use the stuck command, and add a cooldown timer. Also, if it's possible, can the players spawn with only half health? Like linking the ULX hp command to it? If not, oh well. Also, I want to make it to where only players who are alive can use it.

here's the original code:
Code: Lua
  1. function ulx.stuck(calling_ply)
  2.         local pos = calling_ply:GetPos()
  3.         ULib.tsayColor(calling_ply, true, Color(189,236,182), "You will be respawned in 5 seconds. DONT MOVE YOUR MOUSE OR TRY TO WALK!")
  4.         timer.Simple(5, function()
  5.                 if IsValid(calling_ply) then
  6.                         if calling_ply:GetPos() == pos then
  7.                         calling_ply:Spawn()
  8.                         else
  9.                         ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You moved during respawn cool down. Respawning aborted.")
  10.                         end
  11.                 end
  12.         end)
  13. end
  14. local stuck = ulx.command( "Prophunt", "ulx stuck", ulx.stuck, "!stuck" )
  15. stuck:defaultAccess( ULib.ACCESS_ALL )
  16. stuck:help( "Respawns you after 5 seconds if you're stuck" )

Here is one that I've (attempted) to edit. Forgive me for my lack of LUA coding, trying to teach myself:
Code: Lua
  1. function ulx.stuck( calling_ply)
  2.         if not ply:Alive then
  3.         ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You can't do that!")
  4.         else
  5.         local pos = calling_ply:GetPos()
  6.         ULib.tsayColor(calling_ply, true, Color(189,236,182), "You will be respawned in 5 seconds. DONT MOVE YOUR MOUSE OR TRY TO WALK!")
  7.         timer.Simple(5, function()
  8.                 if IsValid(calling_ply) then
  9.                         if calling_ply:GetPos() == pos then
  10.                         calling_ply:Spawn()
  11.                         ulx.hp: 50
  12.                         ULib.tsayColor(ply:TeamColor(), plyNick(), Color(0, 0, 255), "has been unstuck!")
  13.                         timer.Simple(10)
  14.                         else
  15.                         ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You moved during respawn cool down. Respawning aborted.")
  16.                         end
  17.                 end
  18.         end)
  19. end
  20. end
  21. local stuck = ulx.command( "Prophunt", "ulx stuck", ulx.stuck, "!stuck" )
  22. stuck:defaultAccess( ULib.ACCESS_ALL )
  23. stuck:help( "Respawns you after 5 seconds if you're stuck" )

Is there any advice anyone can give me? I'd appreciate the help, in the form of suggestions please. I want to learn it, not have someone do it for me. Thanks!!

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: ULX Stuck command
« Reply #1 on: May 04, 2014, 12:35:47 am »
Well, did your code work?
Out of the Garry's Mod business.

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULX Stuck command
« Reply #2 on: May 04, 2014, 12:44:57 am »
Nope. The error I get is this:
"[ERROR] addons/ulx/lua/ulx/modules/sh/unstuck.lua:2: function arguments expected
  near 'then'
  1. unknown - addons/ulx/lua/ulx/modules/sh/unstuck.lua:0"
I have it in the actual ulx folder as a separate lua file, it won't read it from anywhere else.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX Stuck command
« Reply #3 on: May 04, 2014, 03:43:35 am »
Line 2 is:
Code: [Select]
if not ply:Alive thenChange that to "calling_ply:Alive()".

Now I have noticed a few mistakes. First of all, you forgot the parentheses in "ply:Alive", but you were also using "ply" which was never defined as anything ("calling_ply" was defined, and that's the correct one).
Further down in your code (line 11), you're trying to use "ulx.hp: 50", if you're trying to modify someone's health, use Entity/SetHealth.
On line 12, you're again using "ply" and you haven't defined who to print the message to. The first parameter of ULib.tsayColor should be a player entity or "nil", "nil" will print to everyone. Keep in mind you will have to modify "ply" to be "calling_ply" for both "TeamColor" and "Nick". And then add a colon between "calling_ply" and "Nick()".
If the message should print to everyone, use this instead:
Code: [Select]
ULib.tsayColor(nil, calling_ply:TeamColor(), calling_ply:Nick(), Color(0, 0, 255), "has been unstuck!")Line 13 there's a Timer, although you haven't used it for anything. You might as well just remove it.

All in all, if you combine all that, the code should look something like this:
Code: [Select]
function ulx.stuck( calling_ply )
if not calling_ply:Alive() then
ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You can't do that!")
else
local pos = calling_ply:GetPos()
ULib.tsayColor(calling_ply, true, Color(189,236,182), "You will be respawned in 5 seconds. DONT MOVE YOUR MOUSE OR TRY TO WALK!")
timer.Simple(5, function()
if IsValid( calling_ply ) then
if calling_ply:GetPos() == pos then
calling_ply:Spawn()
calling_ply:SetHealth( 50 )
ULib.tsayColor(nil, calling_ply:TeamColor(), calling_ply:Nick(), Color(0, 0, 255), "has been unstuck!")
else
ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You moved during respawn cool down. Respawning aborted.")
end
end
end)
end
end
local stuck = ulx.command( "Prophunt", "ulx stuck", ulx.stuck, "!stuck" )
stuck:defaultAccess( ULib.ACCESS_ALL )
stuck:help( "Respawns you after 5 seconds if you're stuck" )
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULX Stuck command
« Reply #4 on: May 05, 2014, 06:11:10 pm »
Alright, thanks! This one worked. However, I actually had to ditch TeamColor because it was not recognized, so I just replaced it with Color( 255, 0, 0).

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULX Stuck command
« Reply #5 on: May 08, 2014, 06:02:19 pm »
Okay, so the command works well. A little too well actually. Players use it often, to evade capture. Here is my code as it is:
Code: [Select]
function ulx.stuck( calling_ply )
if not calling_ply:Alive() then
ULib.tsayColor(calling_ply, _, Color(255, 0, 0), "You can't do that!")
else
local pos = calling_ply:GetPos()
ULib.tsayColor(calling_ply, true, Color(189,236,182), "You will be respawned in 5 seconds. DONT MOVE YOUR MOUSE OR TRY TO WALK!")
timer.Simple(5, function()
if IsValid( calling_ply ) then
if calling_ply:GetPos() == pos then
calling_ply:Spawn()
calling_ply:SetHealth( 50 )
ULib.tsayColor( _, Color( 255, 0, 0), calling_ply:Nick(), Color(0, 0, 255), " has been unstuck!")
else
ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You moved during respawn cool down. Respawning aborted.")
end
end
end)
end
end
local stuck = ulx.command( "Prophunt", "ulx stuck", ulx.stuck, "!stuck" )
stuck:defaultAccess( ULib.ACCESS_ALL )
stuck:help( "Respawns you after 5 seconds if you're stuck" )

I want some help adding a couple things. One (as you can see by my previous version) is a cooldown timer. I have attempted to add timer.Simple() and timer.Create(), but neither do a cooldown effect. Also the hunters abuse it because each time it gives them an extra smg grenade. Is there a way to block this, or change their weapons to exclude the smg on spawn?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: ULX Stuck command
« Reply #6 on: May 08, 2014, 10:45:24 pm »
Instead of using Spawn() which resets a players loadout and health (if I'm not mistaken), why don't you get the position of the spawn points and just do something like:

ply:SetPos( spawnpoint:GetPos() )
ply:SetAngles( spawnpoint:GetAngles() )

I have an unstuck command in my gamemode that does this. Here is the code. It may need to be tweaked a little to work with gamemodes that use spawnpoints other than info_player_start.

Code: Lua
  1. local spawnarea = ents.FindByClass( "info_player_start" )
  2. local random_entry = math.random( #spawnarea )
  3. local newpos = spawnarea[ random_entry ]:GetPos()
  4. local newang = spawnarea[ random_entry ]:GetAngles()
  5.        
  6. ply:SetPos( newpos )
  7. ply:SetAngles( newang )
  8.  

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Stuck command
« Reply #7 on: May 09, 2014, 07:40:16 am »
Additionally, if using  ULib dependent code (for instance, making it ULX commands), you may wish to see ULib.getSpawnInfo and ULib.spawn.
Stores/restores armor and health.
Pretty sure we don't store loadout.
Would have to look at the ULib code itself.
« Last Edit: June 18, 2016, 06:36:53 am by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline MattTheEmp

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: ULX Stuck command
« Reply #8 on: January 08, 2015, 07:10:54 pm »
Did anyone get this working? if so how is it working for you?

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULX Stuck command
« Reply #9 on: June 23, 2015, 09:56:27 pm »
I got it to work. However, instead of bouncing the user about, I used a respawn command. The drawback is the prop and hunters reset to spawn, but there is no way of exploiting through a wall or outside of the map.

Offline Aharon Tager

  • Newbie
  • *
  • Posts: 37
  • Karma: 0
    • Barely Legal Gaming
Re: ULX Stuck command
« Reply #10 on: June 24, 2015, 02:43:04 pm »
Why don't you make a command based off of "!tp" (modified with your 5-second timer), but add a timer that's long enough that the command can't be abused effectively?
Practically, if you are interested in making such a command you have to be ready for the trolls,  but that's really the same thing as RDM in TTT, job switching in DarkRP and things of that nature, you just have to have good admins to prevent too many people from abusing this.

Offline TheHyperDrive

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULX Stuck command
« Reply #11 on: July 01, 2015, 10:47:54 am »
Well here is mine:

Code: [Select]
function ulx.stuck( calling_ply )
if not calling_ply:Alive() then
ULib.tsayColor(calling_ply, _, Color(255, 0, 0), "You can't do that!")
else
local pos = calling_ply:GetPos()
ULib.tsayColor( calling_ply, true, Color( 255, 0, 0 ), "You will be respawned in 5 seconds. DONT MOVE YOUR MOUSE OR TRY TO WALK!" )
timer.Simple(5, function()
if IsValid( calling_ply ) then
if calling_ply:GetPos() == pos then
calling_ply:Spawn()
calling_ply:SetHealth( 50 )
calling_ply:StripWeapon("weapon_smg1")
calling_ply:Give("weapon_ar2")
calling_ply:GiveAmmo(250, "ar2")
                ULib.tsayColor( _, Color(255, 60, 60, 255), calling_ply:Nick(), Color(0, 0, 255), " has been unstuck!:")
else
ULib.tsayColor(calling_ply, _, Color(255, 127, 0), "You moved during respawn cool down. Respawning aborted.")
end
end
end)
        end
end
local stuck = ulx.command( "Prophunt", "ulx stuck", ulx.stuck, "!stuck" )
stuck:defaultAccess( ULib.ACCESS_ALL )
stuck:help( "Respawns you after 5 seconds if you're stuck" )

If anyone has suggestions for improvement, I'd love to hear it!

  • Print