Ulysses
General => Developers Corner => Topic started by: Adult on January 21, 2013, 02:40:59 PM
-
Title says it all. Here's the full script.
-- 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.
-
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.
-
hm, makes sense, but still didn't fix it. :L
-
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)?
-
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. )
-
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 (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) 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?
-
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 (http://ulyssesmod.net/docs/files/lua/ulib/shared/defines-lua.html#ULibCommandCalled) 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.
-
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?
-
Yes, it does.
-
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.
-
Thanks, it works now. And it's not really a big deal, everyone has access to god on my server.
-
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.
-
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