• Print

Author Topic: Materializing Players  (Read 4881 times)

0 Members and 1 Guest are viewing this topic.

Offline someone920

  • Newbie
  • *
  • Posts: 47
  • Karma: 3
Materializing Players
« on: April 06, 2010, 01:07:36 pm »
Our server has a serious issue with the material tool, while we don't want to kick and ban people for it, we also don't want to restrict it. Is there anyway to stop players from materializing or players?

Offline Kenny_

  • Newbie
  • *
  • Posts: 29
  • Karma: 3
Re: Materializing Players
« Reply #1 on: April 06, 2010, 01:52:31 pm »
I've had the same problem on my server and ended up restricting it to guests, I never thought of using a script to prevent it from being used on players. I've just started scripting so I'm not sure if this will work:
Code: [Select]
function UseTool( ply, trace, toolmode )
if toolmode == "material" or toolmode == "colour" then
if trace.Entity:IsPlayer() then
return false
else
return true
end
end
end
 
hook.Add( "CanTool", "UseTool", UseTool )

Edit by Megiddo: Oops, accidentally hit edit instead of quote. Sorry about that!
« Last Edit: April 06, 2010, 02:10:36 pm by Megiddo »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Materializing Players
« Reply #2 on: April 06, 2010, 02:09:45 pm »
Never ever return a non-nil value from a hook unless you absolutely have to in order to accomplish what you want. If you return a non-nil value, you block every other hook from getting a chance to execute. Hooks such as prop protection! So, to fix the code above, it would be:

Code: Lua
  1. function UseTool( ply, trace, toolmode )
  2.         if toolmode == "material" or toolmode == "colour" then
  3.                 if trace.Entity and trace.Entity:IsValid() and trace.Entity:IsPlayer() then
  4.                         return false
  5.                 end
  6.         end
  7. end
  8.  
  9. hook.Add( "CanTool", "UseTool", UseTool )

(I'm guessing that the IsValid check is necessary, haven't tested it)

If I remember right, a quirk with this is that the player using the color or material tool will still see the color/material change, but no one else on the server will.
Experiencing God's grace one day at a time.

Offline Kenny_

  • Newbie
  • *
  • Posts: 29
  • Karma: 3
Re: Materializing Players
« Reply #3 on: April 06, 2010, 02:37:01 pm »
Thanks, I'm glad I waited for a reply before adding that to the server.

Offline vader0146

  • Jr. Member
  • **
  • Posts: 63
  • Karma: 9
Re: Materializing Players
« Reply #4 on: April 07, 2010, 02:38:39 pm »
If I remember right, a quirk with this is that the player using the color or material tool will still see the color/material change, but no one else on the server will.

Code: [Select]
hook.Add("Think","Hi",function()
for k, v in ipairs( player.GetAll() ) do
v:SetMaterial("")
end
end )

Offline someone920

  • Newbie
  • *
  • Posts: 47
  • Karma: 3
Re: Materializing Players
« Reply #5 on: April 07, 2010, 05:51:24 pm »
Thanks for the help, I'll tell you if i have any problems :D

EDIT: Forgot to ask, where would i put this? in lua/autorun?
« Last Edit: April 07, 2010, 05:57:37 pm by someone920 »

  • Print