General > Developers Corner

Admin sounds, tools and other code chat.

<< < (5/31) > >>

jay209015:
Ok, I got everything working. Here's the final code.


--- Code: ---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 );

--- End code ---

JamminR:
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.

jay209015:
Oh, ok thanks for that. so you saying i should add
--- Code: ---return true
--- End code ---
after

--- Code: ---game.ConsoleCommand( "ulx asay Player " .. ply:Nick() .. " used " .. toolmode .. "\n" );
--- End code ---

JamminR:
nope.
Saying that any

--- Code: ---return true

--- End code ---
you have should be

--- Code: ---return

--- End code ---

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?

Megiddo:
You return false but you still run the risk of breaking other hooks.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version