Ulysses

General => Developers Corner => Topic started by: Avien on May 11, 2007, 08:52:08 PM

Title: Groups, Props, and Tools
Post by: Avien on May 11, 2007, 08:52:08 PM
Before you say use the search function, i already have and included the threads i have found useful.  I am just unsure how to make the 3 things fit together.  I want to be able to make certain props and tools be blocked to certain groups.  Respectably, nothing limited to superadmins, and most of my things are directed toward clients.

I read the following threads:
http://forums.ulyssesmod.net/index.php/topic,682.0.html
http://forums.ulyssesmod.net/index.php/topic,858.0.html
http://forums.ulyssesmod.net/index.php/topic,721.0.html

My question is how do i put these things together in to one file, along with blocking ignite, paint, and other spammable tools to be blocked from regular clients?  I have no experience with lua and don't want to mess things up.

I know i am asking for someone to figure out what to do, but i included the threads in which the stuff i am looking for, i am just not sure how to go about putting them together and having them work the way they should

As for limiting props, do i just add the other things i want blocked after the comma in this code:
Code: [Select]
{ "models/Effects/splode.mdl", }
This is mainly to block TNT barrels to clients so people wont crash server with the bufferoverflow message.


I greatly appreciate any help given, as i am a total noob in lua.
Title: Re: Groups, Props, and Tools
Post by: JamminR on May 12, 2007, 09:24:02 AM

As for limiting props, do i just add the other things i want blocked after the comma in this code:
Code: [Select]
{ "models/Effects/splode.mdl", }
This is mainly to block TNT barrels to clients so people wont crash server with the bufferoverflow message.

Avien,
Look at page 2 of your first posted link regarding blocking larger props. It has more 'final' working code bits, and includes some example answer to your question.
Which, by the way, is yes. :)
Title: Re: Groups, Props, and Tools
Post by: Avien on May 12, 2007, 11:22:29 AM
I saw all of this, but i want to put all the code together in one file.  Having groups where i block props for clients, such as TNT barrels, phx explosive barrels, along with the ignite tool and paint tool.  But all the examples i have included are for either props, or groups, and i have no idea how to put them together.  So i am asking for help in doing that, since i know nothing about lua.


This would work:
Code: [Select]
if not SERVER then return end

local groups = { "superadmin", "admin", "opperator" } --Add your groups here

local function block_build( ply )
    for _,v in ipairs( groups ) do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "You are not allowed to build." )
    return false
end
hook.Add( "PlayerSpawnProp", "block_prop", block_build )
hook.Add( "PlayerSpawnEffect", "block_effect", block_build )
hook.Add( "PlayerSpawnVehicle", "block_vehicle", block_build )
hook.Add( "PlayerSpawnSENT", "block_sent", block_build )
hook.Add( "CanTool", "block_tool", block_build )

I see the block_prop, effect, vehicle, tool, etc... but i dont know where to put the things i want to block.  Do i replace the ply in
Code: [Select]
block_build( ply )with the location for props, and the tools?
Title: Re: Groups, Props, and Tools
Post by: JamminR on May 12, 2007, 05:29:56 PM
Avien, ply is the player passed to the function.
Replacing it will not help you reach your goal of banning certain players from certain props.
Adding on however might.

I'm sorry I don't have time to rewrite the code you wish.

I recommend attempting to teach yourself Lua.
www.lua.org and Google are great places to learn about lua, especially "for" loops and "tables", which, are much of what you're trying to work with for the player grouptables, and the prop list tables you don't want spawned.
Title: Re: Groups, Props, and Tools
Post by: Avien on May 13, 2007, 08:25:55 PM
I tried asking for help on the facepunch forums, but as of now noone seems to have any idea.
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 13, 2007, 10:38:59 PM
Tried combining some code, untested, see if it works.

Code: [Select]
if not SERVER then return end

local groups = { "superadmin", "admin", "opperator" } --Add your groups here
local models = { "models/Effects/splode.mdl", "crane_frame.mdl" } --All or part of model name.



local function block_build( ply, mdl )
for _, v in pairs( models ) do
if string.find( mdl, v ) then
    for _,v in ipairs( groups ) do
        if ply:IsUserGroup( v ) then
            return
        end
    end
end
    ULib.tsay( ply, "You are not allowed to spawn this prop." )
    return false
end
end
Title: Re: Groups, Props, and Tools
Post by: spbogie on May 14, 2007, 01:02:43 PM
GD you forgot your hook.
Title: Re: Groups, Props, and Tools
Post by: JamminR on May 14, 2007, 03:45:07 PM
GD you forgot your hook.

What? He's a pirate? Oh. Fisherman perhaps?
:P/me gives benefit of doubt and hopes that perhaps GD is leaving some code vague, and hoping that Avien will learn and place in some on his own.

In all honesty, Done right, I could really see a decent release module for ULib coming out of this.
The idea of combining did come to mind when I was making the 'Code Bits' posts.
Title: Re: Groups, Props, and Tools
Post by: Avien on May 14, 2007, 05:32:33 PM
Hopefully something like this will work in the future.  I would try this new code by GoldenDeath, but i am unsure how to put in the server and have it get called, plus someone said it is missing hooks.  Isn't it operator, not opperator?
Title: Re: Groups, Props, and Tools
Post by: JamminR on May 14, 2007, 06:17:15 PM
Avien.
Re: Missing hooks.
Think about it. Seriously.
Look at the code you posted.
Look at the code GD posted.
Then, look at the BIG CLUE that Spbogie said is missing.
Notice any key lua words missing from the first that aren't in the second?

You've been asking us to make it for you since you asked for 'help'.
If you'd placed your request in the suggestion forum, and left it there, we probably wouldn't have gone this far.
However, you asked for help. I moved the forum to developers corner.
We like helping. We like developing.
But, I don't think we're going to make it THAT easy on you.
I think most of us have gone farther than normal.

You're not dumb. You had a good idea.
Now, think about it, and learn to do it yourself. :)
Title: Re: Groups, Props, and Tools
Post by: Avien on May 14, 2007, 06:48:03 PM
Alright fine.  I start to use my brain a little.  I applicate all that you guys have done, don't get me wrong.  I get in a mood when i get home after fixing a game server all day, i just get tired of working.  I will start to work on it, and hopefully learn lua while i am at it.  Thanks for your help guys, i mean it.
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 14, 2007, 09:13:17 PM
Ok, here you go, tested.

Also made it come with a cvar you can use to turn it on and off, gd_propblock. Set to 1 for on, 0 for off.

Code: [Select]
--Prop Blocker by Golden-Death--


local groups = { "superadmin", "admin" } --These groups here are allowed to spawn anything, defined in gmod/settings/users.txt
local models = { ""} --All or part of model name that is to be banned



local function block_build( ply, mdl )
if GetConVarString("gd_propblock") == "0" then return; end
for _, v in pairs( models ) do
if string.find( mdl, v ) then
    for _,v in ipairs( groups ) do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "Non-admins are not allowed to spawn this prop. ("..mdl..")." )
    return false
end
    end
end


hook.Add( "PlayerSpawnProp", "block_prop", block_build )
ULib.convar("gd_propblock", 1, "1 = Prop Block On, 0 = Prop Block Off", ULib.ACCESS_ADMIN)
Title: Re: Groups, Props, and Tools
Post by: Avien on May 15, 2007, 02:04:04 PM
I am assuming we just put into a .lua and place that file in garrysmod/lua/includes/modules/?
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 15, 2007, 03:17:38 PM
addons/ulib/lua/ulib/modules or something to that effect, i dont remember exactly :P
Title: Re: Groups, Props, and Tools
Post by: Avien on May 16, 2007, 03:44:04 PM
Well i added it to where i said earlier and to the lua/ulib/modules but now i get an error when i start the server:


This server is running ULib version 2.04.
-- Error running file ------------------------------------
- File: ULib/modules/blocker.lua
- ULib/modules/blocker.lua:26: attempt to call field 'convar' (a nil value)
----------------------------------------------------------
ULX version 3.10 loaded.

Thought you should know.
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 16, 2007, 04:54:17 PM
Looks like your ULX or Ulib is broken. They're the ones that handle convars.

But if you want a version without the convar:

Code: [Select]
--Prop Blocker by Golden-Death--


local groups = { "superadmin", "admin" } --These groups here are allowed to spawn anything, defined in gmod/settings/users.txt
local models = { ""} --All or part of model name that is to be banned



local function block_build( ply, mdl )
for _, v in pairs( models ) do
if string.find( mdl, v ) then
    for _,v in ipairs( groups ) do
        if ply:IsUserGroup( v ) then
            return
        end
    end
    ULib.tsay( ply, "Non-admins are not allowed to spawn this prop. ("..mdl..")." )
    return false
end
    end
end


hook.Add( "PlayerSpawnProp", "block_prop", block_build )
Title: Re: Groups, Props, and Tools
Post by: Avien on May 16, 2007, 05:40:57 PM
How can it be broken?  I just installed the new version like last week or whenever it came out.
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 16, 2007, 07:09:59 PM
Dunno, but it's not seeing 'convar' as part of Ulib.
Title: Re: Groups, Props, and Tools
Post by: Avien on May 19, 2007, 10:31:49 AM
Well i reinstalled the files that contained the command convar, and i still get the error saying that convar is calling a nil value.
Title: Re: Groups, Props, and Tools
Post by: Golden-Death on May 19, 2007, 11:33:31 AM
I don't really know what the problem is