ULX

Author Topic: Admin sounds, tools and other code chat.  (Read 55153 times)

0 Members and 4 Guests are viewing this topic.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #15 on: April 10, 2008, 07:05:25 PM »
I changed my goal, I just want it to disable trails for non-admins wich it does. I also want it to display when a non-admin uses dynamite wich is currently not working. Any suggestions?

Code: [Select]
function UseTool( ply, tr, toolmode )
    if toolmode == "trails" or toolmode == "ignite" then
          if ply:IsAdmin() then
          return true
                        else
          return false
                        end

        end
        if toomode ==  "dynamite" then
                        if ply:IsAdmin() then
                                return true
                        else
                                Msg( "Player " .. ply:Nick() .. " used " .. toolmode .. "\n" );
                                return true
                        end
        end
end
hook.Add( "CanTool", "UseTool", UseTool );
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #16 on: April 10, 2008, 07:36:31 PM »
Getting any errors in server console?
Also, You may already be aware, "Msg" will only print to the console of the system it is run on... since CanTool is a server side gamemode hook, I believe it will only print in server console. Make sure you're looking there.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #17 on: April 10, 2008, 07:40:44 PM »
No I didn't know that msg displayed in the server console, but still it didn't print the message there either, nor did it display an error.
**EDIT**
I change my script alittle, but still no different.
Code: [Select]
function UseTool( ply, tr, toolmode )
    if toolmode == "trails" or toolmode == "ignite" then
          if ply:IsAdmin() then
          return true
                        else
          return false
                        end

        end
        if toomode ==  "dynamite" then
                        if ply:IsAdmin() then
                                return true
                        else
                                ConCommand( "Player " .. ply:Nick() .. " used " .. toolmode .. "\n" );
                        end
        end
end
hook.Add( "CanTool", "UseTool", UseTool );
« Last Edit: April 10, 2008, 08:19:30 PM by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #18 on: April 11, 2008, 04:57:56 PM »
Sorry I didn't see this last night when I posted.
Syntax error in your code, misspelled variable - toomode in the dynamite check should be toolmode.

Also, ConCommand is for commands, not output of messages.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #19 on: April 11, 2008, 09:29:45 PM »
OMG thank you for seeing that lol, that's kind of sad :'(.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #20 on: April 11, 2008, 11:02:31 PM »
Ok, I got everything working. Here's the final code.

Code: [Select]
function UseTool( ply, tr, toolmode )
    if toolmode == "trails" or toolmode == "ignite" then
          if ply:IsAdmin() then
          return true
                        else
          return false
                        end

        end
        if toolmode ==  "dynamite" then
                        if ply:IsAdmin() then
                                return true
                        else
                                game.ConsoleCommand( "ulx asay Player " .. ply:Nick() .. " used " .. toolmode .. "\n" );
                        end
        end
end
hook.Add( "CanTool", "UseTool", UseTool );
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #21 on: April 12, 2008, 07:19:30 AM »
Next thing you need to know in Lua 101... returning anything but nil (leaving blank/no variable after return) prevents any other hooks of the same type in any other scripts from running.
So, any of the code lines you have that return "true", remove the true. Just use return by itself.

Though the lines of code you have might not affect much by preventing other CanTool hooks, if you ever tried making a text chat watcher of any kind, you could break lots of scripts that also use chat hooks, including ULX.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #22 on: April 12, 2008, 09:06:16 AM »
Oh, ok thanks for that. so you saying i should add
Code: [Select]
return true after
Code: [Select]
game.ConsoleCommand( "ulx asay Player " .. ply:Nick() .. " used " .. toolmode .. "\n" );
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #23 on: April 12, 2008, 09:35:35 AM »
nope.
Saying that any
Code: [Select]
return true
you have should be
Code: [Select]
return

I've forgotten the best way to prevent something from happening and not returning false.
MrPres, spbogie, Megiddo, Kyzer or any other lua folks out here... whats the best way to keep a hook from allowing that action, yet still not break other hooks?
« Last Edit: April 12, 2008, 09:39:06 AM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Admin sounds, tools and other code chat.
« Reply #24 on: April 12, 2008, 10:53:53 AM »
You return false but you still run the risk of breaking other hooks.
Experiencing God's grace one day at a time.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #25 on: April 12, 2008, 11:16:31 AM »
This is on a different subject, but I don't feel it's necessary to open a new topic.

Code: [Select]
WordD = { "", "ass", "" }
function WFilter( ply, text, toall )
         for _, v in pairs( WordD ) do
             if string.find( text, v) then
                WordC = string.Replace(text,V,"****")
                return ..WordC..
             else
                WordC = (text)
                return ..WordC..
             end
         end
end
hook.Add( "PlayerSay", "WFilter", WFilter );

I want this to replace the words in WordD when found in chat with **** , but I can't figure out how. Any help?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #26 on: April 12, 2008, 12:24:49 PM »
'return' will always end a loop.
Though your code _may_ find one word, it will stop looping.
Define a local variable before your for loop, such as local WordC = ""
than after the end of the for loop, -then- return WordC, and remove the other returns.

There is no need to use ".." before and after your WordC.

V does not equal v in lua.
Lua is case sensitive. You have the wrong case for one of you're variables.

« Last Edit: April 12, 2008, 12:32:02 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #27 on: April 12, 2008, 01:16:40 PM »
Ok, so is this what you're saying?

Code: [Select]
WordD = { "", "ass", "" }
local WordC = ""
function WFilter( ply, text, toall )
         for _, v in pairs( WordD ) do
             if string.find( text, v) then
                WordC = string.Replace(text,v,"****")
                else
                WordC = (text)
             end
         end
return WordC
end
hook.Add( "PlayerSay", "WFilter", WFilter );

BTW, thanks for the move, and all the help you've given me so far.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Admin sounds, tools and other code chat.
« Reply #28 on: April 12, 2008, 02:37:04 PM »
Yes, that should work.


To help make table loops faster, use ipairs instead of pairs when possible.
An experienced coder once taught me it was more efficient for the purpose your using it.

If you had a complex non-sequential numbered table, then you'd need pairs. Complex non-indexed example blah = { something = "else", old = "notnew" )
Since  you're using a simple table where WordD.1 = someword and WordD.2 = someotherword and WordD.3 = yetsomeotherword, you can use ipairs
i meaning indexed, 1, 2, 3...
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #29 on: April 12, 2008, 02:42:25 PM »
But, do you know why this script isn't working at all?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly