Author Topic: ULibCommandCalled not being called?  (Read 5409 times)

0 Members and 4 Guests are viewing this topic.

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
ULibCommandCalled not being called?
« on: January 21, 2013, 02:40:59 PM »
Title says it all. Here's the full script.

Code: [Select]
-- Selective PVP
-- Both attackers and victims must have
-- PVP enabled to do damage.
-- Requires ULib
-- Made by: Adult

-- Chat command
-- !pvp on/off

if CLIENT then return end

local function playerSay( ply, text )
local args = string.Explode( " ", text )

if args[1] ~= "!pvp" then return end

local enabled = ply.pvp

if args[2] == "on" and enabled then
ULib.tsayError( ply, "You're already in PVP mode.", true )
return
end

if args[2] == "off" and not enabled then
ULib.tsayError( ply, "You're not in PVP mode.", true )
return
end

ply.pvp = ( args[2] == "on" and true ) or ( args[2] == "off" and false )
ulx.fancyLogAdmin( ply, false, "#A " .. ( ply.pvp and "entered" or "left" ) .. " PVP mode." )

if ply.ULXHasGod then
ply:GodDisable()
end
end

hook.Add( "PlayerSay", "PVP_Mod", playerSay )

-- Entity damage
local function takeDamage( target, dmgInfo )
if not target:IsPlayer() then return end
if not target.pvp then return end

local attacker = dmgInfo:GetAttacker()
if not attacker:IsPlayer() then return end
if not attacker.pvp then return end
end

hook.Add( "EntityTakeDamage", "PVP_Mod", takeDamage )

-- Modifies ulx god slightly, so it can't be abused.

local function commandCalled( ply, cmd, args )
print( "work please.")
if cmd ~= "ulx god" then return end

if ply.pvp then
ULib.tsayError( ply, "You're in PVP Mode!", true )
return false
end

if args[1].pvp then
ULib.tsayError( ply, "Target is in PVP Mode!", true )
return false
end
end


hook.Add( "ULibCommandCalled", "PVP_Mod", commandCalled )

I've spent almost two hours trying to get this working. I have no idea why it's not.
Thanks in advance.
« Last Edit: January 21, 2013, 03:07:13 PM by Adult »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULibCommandCalled not being called?
« Reply #1 on: January 21, 2013, 03:54:44 PM »
Quick overview, you have two hook add's with the same unique name.
One will overwrite the other, with only Lua knows what consequences.
"PVP_Mod" can't be applied to both hooks (playersay and ULibCommandCalled)
Maybe rename the playersay PVP_Mod_say and the ULibCommandCalled to PVP_Mod_ULXGodfix

Other than that, fix it, we'll go from there.
« Last Edit: January 21, 2013, 04:02:55 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #2 on: January 21, 2013, 04:05:39 PM »
hm, makes sense, but still didn't fix it. :L

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULibCommandCalled not being called?
« Reply #3 on: January 21, 2013, 04:09:32 PM »
Any server/console errors, at startup or command execution?
I take it you're not seeing 'please work' at all when running ULX commands (god or otherwise, you should see something)?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #4 on: January 21, 2013, 04:12:47 PM »
Any server/console errors, at startup or command execution?

None at all, really strange.

I take it you're not seeing 'please work' at all when running ULX commands (god or otherwise, you should see something)?

Correct, sir. ( I mean, no, I'm not seeing it. )
« Last Edit: January 21, 2013, 04:14:45 PM by Adult »

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: ULibCommandCalled not being called?
« Reply #5 on: January 21, 2013, 04:53:08 PM »
Code: [Select]
lua_run hook.Add( "ULibCommandCalled", "test", print )
> hook.Add( "ULibCommandCalled", "test", print )...
ulx slap sti
[NULL Entity]   ulx slap        table: 0x1b681f08

Worked fine for me when I made a simple hook in the server console.

Note from the ULib docs that this hook only gets called on the SERVER, so perhaps double-check and make sure your code is running on the server and not on the client?
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #6 on: January 21, 2013, 04:59:39 PM »
Code: [Select]
lua_run hook.Add( "ULibCommandCalled", "test", print )
> hook.Add( "ULibCommandCalled", "test", print )...
ulx slap sti
[NULL Entity]   ulx slap        table: 0x1b681f08

Worked fine for me when I made a simple hook in the server console.

Note from the ULib docs that this hook only gets called on the SERVER, so perhaps double-check and make sure your code is running on the server and not on the client?

Using this same command you did, I tried slapping myself several times. I noticed that the hook isn't called when the command is executed via chat, but it is when used in console.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: ULibCommandCalled not being called?
« Reply #7 on: January 21, 2013, 05:13:35 PM »
Code: [Select]
ServerLog: [ULX] [ULX]Stickly Man! slapped Themself with 0 damage
[ULX]Stickly Man!: !slap sti

Player [1][[ULX]Stickly Man!]   ulx slap        table: 0x1de60388
[ULX]Stickly Man! slapped Themself with 0 damage
ServerLog: [ULX] [ULX]Stickly Man! slapped Themself with 0 damage

ulx slap sti
[NULL Entity]   ulx slap        table: 0x21ac4d68
(Console) slapped [ULX]Stickly Man! with 0 damage
ServerLog: [ULX] (Console) slapped [ULX]Stickly Man! with 0 damage

Yup, it seems to work from client/server console, but not from chat. We'll see about getting that fixed. Does your code work when you use the command from console?
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #8 on: January 21, 2013, 05:14:00 PM »
Yes, it does.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: ULibCommandCalled not being called?
« Reply #9 on: January 21, 2013, 05:58:32 PM »
K, I just pushed a fix for this in ULib code! Test it and see if it works for you.

Also, you should note that this hook gets called when a user attempts the command from their console yet does not have access to the command (this doesn't seem to happen with the chat commands). So if you don't want the "You're in PVP Mode!" messages to show up when a user doesn't have access, you should add a ply:query( "ulx god" ) in your script.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #10 on: January 22, 2013, 07:39:14 AM »
Thanks, it works now. And it's not really a big deal, everyone has access to god on my server.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULibCommandCalled not being called?
« Reply #11 on: January 22, 2013, 05:28:33 PM »
Adult, now that we have our code fixed;
Suggestion -
Though I see you disable ulx god when a player enters pvp mode, perhaps you might make it easier for your players?
That is, set some player variable to remember what state they were in before going into pvp mode. ply.GStatus or something?
That way, if I'm in god mode and then turn on PVP, then a few minutes later, exit, your code will place me back in god mode.
:)
I'd hate to leave pvp mode and get killed while forgetting to enable god again or while typing it again.
I don't imagine having it be so complex as across server sessions. Just game.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Adult

  • Newbie
  • *
  • Posts: 15
  • Karma: 1
Re: ULibCommandCalled not being called?
« Reply #12 on: January 23, 2013, 09:52:03 AM »
Adult, now that we have our code fixed;
Suggestion -
Though I see you disable ulx god when a player enters pvp mode, perhaps you might make it easier for your players?
That is, set some player variable to remember what state they were in before going into pvp mode. ply.GStatus or something?
That way, if I'm in god mode and then turn on PVP, then a few minutes later, exit, your code will place me back in god mode.
:)
I'd hate to leave pvp mode and get killed while forgetting to enable god again or while typing it again.
I don't imagine having it be so complex as across server sessions. Just game.

that's a great idea, i'll put it now. thanks :D