ULX

Author Topic: Am I missing something?  (Read 226 times)

0 Members and 1 Guest are viewing this topic.

Offline I_AM_TOOD

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Am I missing something?
« on: March 04, 2019, 06:49:31 PM »
Trying to make a custom "nodeath" command so when the player reaches 5hp they are granted a god type function in which they no longer take damage.

Any idea what I am missing from the code below?
Thanks in advance.


Code: Lua
  1. function ulx.nodeath( calling_ply, target_ply )
  2.     if not target_ply:alive () then
  3.     target_ply:spawn ()
  4.     ulx.fancylogadmin( calling_ply, true, "#A granted nodeath on #T", target_ply )
  5.     end
  6. end
  7. local nodeath = ulx.command( CATEGORY_NAME, "ulx nodeath", ulx.nodeath, "!nodeath", true )
  8. nodeath:addparam{ type=ULib.cmds.PlayerArg }
  9. nodeath:defaultaccess( ULib.ACCESS_ADMIN )
  10. nodeath:help( "Player no longer takes damage once they reach 5hp" )

Offline BlueNova

  • Full Member
  • ***
  • Posts: 105
  • Karma: 11
  • The most powerful force in the universe.
Re: Am I missing something?
« Reply #1 on: March 04, 2019, 07:24:08 PM »
Well you don't seem to have anything that checks for a player's HP or anything that would give them god mode. Unless this was intentional, the command will only spawn the target player if they're not alive.

Offline I_AM_TOOD

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Am I missing something?
« Reply #2 on: March 05, 2019, 07:33:25 AM »
Updated version, still no luck.

Code: Lua
  1. function ulx.nodeath( calling_ply, target_ply )
  2.     if not target_ply:Alive() then target_ply:Spawn() end
  3.     if (not target_ply._ulxnodeath) then target_ply._ulxnodeath = true else return end
  4.     ulx.fancylogadmin( calling_ply, true, "#A granted nodeath on #T", target_ply )
  5. end
  6. local nodeath = ulx.command( CATEGORY_NAME, "ulx nodeath", ulx.nodeath, "!nodeath", true )
  7. nodeath:addparam{ type=ULib.cmds.PlayerArg }
  8. nodeath:defaultaccess( ULib.ACCESS_ADMIN )
  9. nodeath:help( "Player no longer takes damage once they reach 5hp" )
  10.  
  11. hook.Add("EntityTakeDamage", function(ply, dmg)
  12.     if not ply:IsPlayer() then return end
  13.     if (ply._ulxnodeath) then
  14.         if dmg:GetDamage() >= ply:GetHealth() then ply:SetHealth(5) return true end
  15.     end
  16. end

Offline BlueNova

  • Full Member
  • ***
  • Posts: 105
  • Karma: 11
  • The most powerful force in the universe.
Re: Am I missing something?
« Reply #3 on: March 05, 2019, 08:34:48 AM »
--snip--

For hooks wouldn't you need to add a unique identifier with it? You don't seem to have that

Code: Lua
  1. hook.Add("EntityTakeDamage", "no_death_hook", function(ply, dmg)
  2.      --Code here
  3. end)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7967
  • Karma: 373
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Am I missing something?
« Reply #4 on: March 05, 2019, 01:23:53 PM »
wouldn't you need to add a unique identifier
Yes, absolutely.
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2671
  • Karma: 417
    • |G4P| Gman4President
Re: Am I missing something?
« Reply #5 on: March 06, 2019, 06:18:25 AM »
Even with setting up the hook correctly, your hook doesn't check any kind of access assigned from your command.

You'll need your ULX command to flag the player in some way as having this "nodeath" effect and then your hook will need to check for it.

Offline I_AM_TOOD

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Am I missing something?
« Reply #6 on: March 07, 2019, 04:49:09 PM »
Third time lucky, I'm a Junior Dev so this is all new to me.

Code: Lua
  1. function ulx.nodeath( calling_ply, target_ply )
  2.     if not target_ply:Alive() then target_ply:Spawn() end
  3.     if (not target_ply._ulxnodeath) then target_ply._ulxnodeath = true else return end
  4.     ulx.fancylogadmin( calling_ply, true, "#A granted nodeath on #T", target_ply )
  5. end
  6. local nodeath = ulx.command( "CATEGORY_NAME", "ulx nodeath", ulx.nodeath, "!nodeath", true )
  7. nodeath:addParam{ type=ULib.cmds.PlayerArg }
  8. nodeath:defaultAccess( ULib.ACCESS_ADMIN )
  9. nodeath:help( "Player no longer takes damage once they reach 5hp" )
  10.  
  11. hook.Add("EntityTakeDamage", "NoDeathCheck", function(ply, dmg)
  12.     if not ply:IsPlayer() then return end
  13.     if (ply._ulxnodeath) then
  14.     if ply:Health() == 5 then
  15.         ply:ScaleDamage(0.00000000000001)
  16.     else return end
  17.  
  18.     end
  19. end )

Works but just need to add in usergroups I think, everytime I use it in-game no one has access to it, not even me and doesn't appear in the ULX menu so missing something else. Tried adding it into fun.lua then onto the server, nodeath.lua and using CATEGORY_NAME = "Nodeath" but nothing again.

Thinking it's something with category name here:
Code: Lua
  1. local nodeath = ulx.command( "CATEGORY_NAME", "ulx nodeath", ulx.nodeath, "!nodeath", true )
but might be wrong.
« Last Edit: March 07, 2019, 04:53:56 PM by I_AM_TOOD »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7967
  • Karma: 373
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Am I missing something?
« Reply #7 on: March 07, 2019, 07:17:31 PM »
Any console errors (client, or server, either way) when server starts, or client joins, or client takes damage?
Also, likely nothing to do with it not working, you'll probably want your health check to check less than 6, instead of == 5.
As is, it's quite possible someone could get hurt and hit 1, 2, 3, or 4 instead, which wouldn't help anyone with your current code needing to be exactly 5 health.

As a dev learning G-lua, those errors are extremely useful.
Learning to decode them can sometimes take a while though.
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline BlueNova

  • Full Member
  • ***
  • Posts: 105
  • Karma: 11
  • The most powerful force in the universe.
Re: Am I missing something?
« Reply #8 on: March 07, 2019, 11:25:05 PM »
Third time lucky, I'm a Junior Dev so this is all new to me.

--snip long code piece--

Works but just need to add in usergroups I think, everytime I use it in-game no one has access to it, not even me and doesn't appear in the ULX menu so missing something else. Tried adding it into fun.lua then onto the server, nodeath.lua and using CATEGORY_NAME = "Nodeath" but nothing again.

Thinking it's something with category name here:
Code: Lua
  1. local nodeath = ulx.command( "CATEGORY_NAME", "ulx nodeath", ulx.nodeath, "!nodeath", true )
but might be wrong.

You're trying to pass CATEGORY_NAME as a string when it's usually a variable. At the top of every ULX command file it'll have like
Code: Lua
  1. local CATEGORY_NAME = "some name here"

So just take the quotes off of category name.
As for access for the command you could do

Code: Lua
  1. nodeath:defaultAccess(ULib.ACCESS_ADMIN) --Access default to admin only

Alternatively you could just specifiy in your code specific access like
Code: Lua
  1. if not calling_ply:IsAdmin() then return end

In regards to the health thing that JamminR brought up, you are making it search for exactly 5. You could make it look for less than six but you could also do
Code: Lua
  1. ply:Health() =< 5

Just some speculation on my part

Offline Timmy

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 192
  • Karma: 152
  • Code monkey
    • ULX Unofficial Documentation
Re: Am I missing something?
« Reply #9 on: March 08, 2019, 01:37:35 AM »
...everytime I use [the command] in-game no one has access to it, not even me and doesn't appear in the ULX menu so missing something else.

The first time ULib’s Access Control List (UCL) is informed about the existence of a command, it will give the groups specified in cmd:defaultAccess access. After that, never again!

Sure, you corrected nodeath:defaultaccess( ULib.ACCESS_ADMIN ) to nodeath:defaultAccess( ULib.ACCESS_ADMIN ) later. But UCL already knew about the command, so default access was ignored.

Solution - Manually add to a group's access
Code: [Select]
ulx groupallow admin "ulx nodeath"
“When given the choice between being right or being kind, choose kind.”  —Dr. Wayne Dyer