Author Topic: Disabling Sweps for use in RP  (Read 3821 times)

0 Members and 1 Guest are viewing this topic.

Offline Bubonic

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Disabling Sweps for use in RP
« on: April 02, 2007, 01:20:45 PM »
OK, I have seen this thread: http://forums.ulyssesmod.net/index.php/topic,408.0.html

but it confuses me.  :-\


What I want to know is, is there a way to disable sents so that normal players cannot spawn them but still be able to grant the ability to say a gun store owner to spawn weapon sents?

Also is there a way to disable the swep menu but still have access to it as an admin without having to change Spawnable to false and AdminSpawnable to true for every weapon?


People Keep asking me about disabling sweps etc. on my rp server but I still want access to them as an admin.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Disabling Sweps for use in RP
« Reply #1 on: April 02, 2007, 03:37:58 PM »
Bubonic, ignore that thread.
Its out of date and was discussing items (mostly) dealing with GM9/ULib < 2/ULX < 3

I'm looking for answers to your questions, however, someone else much more knowledgeable than I will probably answer quicker.
(IOW, if you don't get an answer from me, it means I stopped looking after 15 minutes)

On another note, why reinvent the wheel?
Quote
Also is there a way to disable the swep menu but still have access to it as an admin without having to change Spawnable to false and AdminSpawnable to true for every weapon?
I believe it would be much easier to edit script already there, yes, even in multiple files, than for a programmer to write code that could then later conflict with the AdminSpawnable and Spawnable settings of someone elses Sents later.
Garry wrote that into SENTS to make it easier on Server admins.





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

Offline Avien

  • Full Member
  • ***
  • Posts: 168
  • Karma: 4
Re: Disabling Sweps for use in RP
« Reply #2 on: April 02, 2007, 06:25:02 PM »
Cant you just make SENTS under the admin menu = 0?

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Disabling Sweps for use in RP
« Reply #3 on: April 03, 2007, 06:35:14 AM »
Ok, this is completely untested (I just wrote it in 5 min), but you can try it out and see if it works.
Admins should be able to spawn anything from the list, and players can spawn anything that is in the SENTBlocker.defaultAllowed table, or anything that they have been allowed by another admin using the concommand.

Just paste the code into a file and save as lua in the autorun/server folder.
Code: [Select]
SENTBlocker = {}

SENTBlocker.defaultAllowed = {}
--Default table of allowed SENTs

--Commands:
--  allowSENT <player name> <SENT name>
--    Allow a player to spawn the specified SENT
--  denySENT <player name> <SENT name>
--    take away a player's ability to spawn the specified SENT

function SENTBlocker.BlockSENT( ply, name )
    if not ply:IsAdmin() then
        for _, v in ipairs( ply:GetTable().AllowedSENTs ) do
            if v == name then
                return true
            end
        end
        ply:PrintMessage( HUD_PRINTTALK, "You are not allowed to spawn this SENT." )
        return false
    end
end
hook.Add( "PlayerSpawnSENT", "SENTBlocker.BlockSENT", SENTBlocker.BlockSENT )

function SENTBlocker.PlayerInit( ply )
    ply:GetTable().AllowedSENTs = SENTBlocker.defaultAllowed
end
hook.Add( "PlayerInitialSpawn", "SENTBlocker.PlayerInit", SENTBlocker.PlayerInit )

function SENTBlocker.AllowSENT( ply, cmd, args )
    if not ply:IsAdmin() then
        ply:PrintMessage( HUD_PRINTCONSOLE, "You do not have access to this command." )
        return
    end
    if args.getn < 2 then
        ply:PrintMessage( HUD_PRINTCONSOLE, "Too few arguments spefified." )
    end
    found = false
    for _, v in pairs( player.GetAll() ) do
        if ply:Name():find( args[1] ) then
            if not table.HasValue( ply:GetTable().AllowedSENTs, args[2] ) then
                found = true
                table.insert( ply:GetTable().AllowedSENTs, args[2] )
            else
                ply:PrintMessage( HUD_PRINTCONSOLE, ply:Name() .. " already has access to " .. args[2] )
            end
        end
    end
    if not found then
        ply:PrintMessage( HUD_PRINTCONSOLE, "No targets found." )
    end
end
concommand.Add( "allowSENT", SENTBlocker.AllowSENT )
--Usage: allowSENT <player name> <SENT name>

function SENTBlocker.DenySENT( ply, cmd, args )
    if not ply:IsAdmin() then
        ply:PrintMessage( HUD_PRINTCONSOLE, "You do not have access to this command." )
        return
    end
    if args.getn < 2 then
        ply:PrintMessage( HUD_PRINTCONSOLE, "Too few arguments spefified." )
    end
    found = false
    for _, v in pairs( player.GetAll() ) do
        if ply:Name():find( args[1] ) then
            if table.HasValue( ply:GetTable().AllowedSENTs, args[2] ) then
                found = true
                table.remove( ply:GetTable().AllowedSENTs, args[2] )
            else
                ply:PrintMessage( HUD_PRINTCONSOLE, ply:Name() .. " doesn't have access to " .. args[2] )
            end
        end
    end
    if not found then
        ply:PrintMessage( HUD_PRINTCONSOLE, "No targets found." )
    end
end
concommand.Add( "denySENT", SENTBlocker.DenySENT )
--Usage: denySENT <player name> <SENT name>

Try it out, and let me know if it works.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Lt_Ryan

  • Guest
Re: Disabling Sweps for use in RP
« Reply #4 on: July 29, 2007, 09:47:23 AM »
Where i must save it ???
And what for a name need it!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Disabling Sweps for use in RP
« Reply #5 on: July 29, 2007, 12:58:20 PM »
Where i must save it ???
And what for a name need it!

Just paste the code into a file and save as lua in the autorun/server folder.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Lt_Ryan

  • Guest
Re: Disabling Sweps for use in RP
« Reply #6 on: July 30, 2007, 02:51:53 AM »
ok lol, but i havent a autorun folder!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Disabling Sweps for use in RP
« Reply #7 on: July 30, 2007, 06:52:23 AM »
ok lol, but i havent a autorun folder!

You do if you're running Gmod 10. Its in <gmod root>/lua/autorun

This script doesn't support gmod 9
"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: Disabling Sweps for use in RP
« Reply #8 on: July 31, 2007, 12:15:09 PM »
Actually he might not have it even if he has GM10. If you don't have it, create it.
Experiencing God's grace one day at a time.