Author Topic: ULX Respawn  (Read 2216 times)

0 Members and 1 Guest are viewing this topic.

Offline Hatty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
ULX Respawn
« on: January 17, 2020, 05:08:00 PM »
So I am new to the lua field but I am trying to add a command and I pasted it in the Fun.lua in the ulx folder on my server but it is not working Here is the code:
Code: [Select]
function ulx.spawn( calling_ply, target_plys )
local affected_plys = {}
for k,v in pairs(target_plys) do
if !v:Alive() then
v:Spawn()
table.insert(affected_plys, v)
end
end
ulx.fancyLogAdmin( calling_ply, "#A spawned #T", affected_plys )
end
local spawn = ulx.command( Utility, "ulx spawn", ulx.spawn, "!spawn" )
spawn:addParam{ type=ULib.cmds.PlayersArg }
spawn:defaultAccess( ULib.ACCESS_ADMIN )
spawn:help( "Spawnd target(s)." )

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX Respawn
« Reply #1 on: January 18, 2020, 10:07:28 AM »
What happens when you try and run the command? Any error?

Offline Hatty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: ULX Respawn
« Reply #2 on: January 18, 2020, 12:30:37 PM »
Nope
just shows the command in chat with no errors as if I just said it in game

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: ULX Respawn
« Reply #3 on: January 18, 2020, 06:03:20 PM »
You need to create a variable for the ulx.command to link to. At the moment you have "Utility" in this parameter. Do you have a local variable called "Utility" at all in your code?

If not you would need to create one above the function ulx.spawn.

e.g. local Utility = "Extra ULX commands" -- this also creates a tab in the ulx menu called Extra ULX commands.

Unless of course you didn't include it in your code box??

Offline Hatty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: ULX Respawn
« Reply #4 on: January 19, 2020, 09:38:26 AM »
so where would I add that line of code again sorry Im newish to lua coding

Offline Hatty

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: ULX Respawn
« Reply #5 on: January 19, 2020, 09:52:16 AM »
Like this?

Code: [Select]
local CATEGORY_NAME = "Custom ULX Commands"

function ulx.spawn( calling_ply, target_plys )
local affected_plys = {}
for k,v in pairs(target_plys) do
if !v:Alive() then
v:Spawn()
table.insert(affected_plys, v)
end
end
ulx.fancyLogAdmin( calling_ply, "#A spawned #T", affected_plys )
end
local spawn = ulx.command ( "Custom ULX Commands" , "ulx spawn", ulx.spawn, "!spawn" )
spawn:addParam{ type=ULib.cmds.PlayersArg }
spawn:defaultAccess( ULib.ACCESS_ADMIN )
spawn:help( "Spawnd target(s)." )

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Respawn
« Reply #6 on: January 19, 2020, 10:29:06 AM »
It should work, but you have unnecessary  CATEGORY_NAME variable name above it.
You have now turned your utility variable into a string,
which ulx command set-up expects that first spot to be filled with. A variable containing a string, or as in your case now, an actual string.
While at same time, possibly overwriting previous category name variable defined much earlier in the file.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: ULX Respawn
« Reply #7 on: January 20, 2020, 01:27:48 AM »
What JamminR is saying is right.

There are 2 things you could do.

1. Delete the variable declaration at the beginning of the file and keep the string "Custom ULX Commands" in ulx.command

2.
Change your local variable (CATEGORY_NAME) to something unique - literally anything (lets just say SpawnCommand) -- local SpawnCommand = "Custom ULX Commands"
BUT you need to keep whatever you call that variable (in my case SpawnCommand) the same as what you put into the ulx.command so it would look like...
local spawn = ulx.command(SpawnCommand, "ulx spawn")..... and so on

Sorry if im repeating things. Its just because you said you were new to lua and I wanna make sure you understand.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Respawn
« Reply #8 on: January 20, 2020, 05:28:51 PM »
1) Don't do 1. (he's editing ULX files, all other 'fun' commands before his would break)
2) Now you're confusing things even more.
I basically said ulx.spawn ( "THIS CONTENT HERE", ...) is what goes in menu. Could be ulx.spawn ( variable_name, ...) and variable_name could literally be CATEGORY_NAME, already defined by us way up in the fun.lua file, or ulx.spawn ( "Custom ULX command", ...) and make thier own menu.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX Respawn
« Reply #9 on: January 20, 2020, 05:30:04 PM »
Code: [Select]
function ulx.spawn( calling_ply, target_plys )
local affected_plys = {}
for k,v in pairs(target_plys) do
if !v:Alive() then
v:Spawn()
table.insert(affected_plys, v)
end
end
ulx.fancyLogAdmin( calling_ply, "#A spawned #T", affected_plys )
end
local spawn = ulx.command ( "Custom ULX Commands" , "ulx spawn", ulx.spawn, "!spawn" )
spawn:addParam{ type=ULib.cmds.PlayersArg }
spawn:defaultAccess( ULib.ACCESS_ADMIN )
spawn:help( "Spawnd target(s)." )
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jacksop

  • Newbie
  • *
  • Posts: 17
  • Karma: 1
Re: ULX Respawn
« Reply #10 on: January 21, 2020, 04:31:11 PM »
Oops.

What you said just then is what i meant. Maybe i wasnt clear enough...?
For 2 i just felt like organising it slightly more but you are right over complicated it.
My bad  :-\
« Last Edit: January 21, 2020, 04:36:04 PM by jacksop »