ULX

Author Topic: Weapon restrictions - Possible or not?  (Read 18166 times)

0 Members and 1 Guest are viewing this topic.

Offline Clone1B

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Weapon restrictions - Possible or not?
« on: August 19, 2007, 06:54:34 AM »
By using Ulib, ULX, or UTeam is it possible to restrict the usage of weapons so that normal users only spawn with the physgun, gravity gun, camera and toolgun?

This is probably one of those things that is right out there in the open or that I'v overlooked, sorry if it sounds like a bit of a mingebag question.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Weapon restrictions - Possible or not?
« Reply #1 on: August 19, 2007, 09:30:37 AM »
Maybe something like that:

Code: [Select]
function GivePlayerSpawnWeapons( ply )

    ply:StripWeapons() -- remove his weapon first

    if ( team.GetName(ply:Team()) == "[Client]" ) then -- this is the team name for normal users, that i've defined in UTeam, change this to your own team name
        ply:Give("weapon_physcannon")
        ply:Give("weapon_physgun")
        ply:Give("gmod_camera")
        ply:Give("gmod_tool")

    elseif ( team.GetName(ply:Team()) == -- etc etc, for each team..

    end
end
hook.Add( "PlayerSpawn", "GivePlayerSpawnWeapons_Hook",  GivePlayerSpawnWeapons )

Look here for a list of weapons: http://www.garrysmod.com/wiki/?title=Player.Give

EDIT: Not tested, don't complain if it doesn't work, and search :)
« Last Edit: August 19, 2007, 09:35:30 AM by Kyzer »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Weapon restrictions - Possible or not?
« Reply #2 on: August 19, 2007, 10:48:32 AM »
There's a playerloadout hook (or something) that you should use instead of playerspawn.

You should probably use usergroups instead of team name too... just remember to do it top to bottom -> superadmin, admin, operator, user.
Experiencing God's grace one day at a time.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Weapon restrictions - Possible or not?
« Reply #3 on: August 19, 2007, 11:02:07 AM »
Yes, i was ignoring this hook, i have much to learn i see :)

http://www.garrysmod.com/wiki/?title=Gamemode.PlayerLoadout

But about usersgroups, what if we have special team as i do with UTeam (we have 7 teams) ?

Also, this should be easy enough to implement that in UTeam.  I'll do but not release it without permission :)
« Last Edit: August 19, 2007, 11:04:28 AM by Kyzer »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Weapon restrictions - Possible or not?
« Reply #4 on: August 19, 2007, 12:46:09 PM »
UTeam was written by spbogie, so it's up to him.
Experiencing God's grace one day at a time.

Offline Clone1B

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Weapon restrictions - Possible or not?
« Reply #5 on: August 19, 2007, 01:46:10 PM »
Sorry to sound like even more of a mingebag but I haven't dabbled with LUA at all. Would I just write this to a notepad and save it into /lua/autorun/ ? as something like strip_weapons.lua?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Weapon restrictions - Possible or not?
« Reply #6 on: August 19, 2007, 04:14:40 PM »
No worries Clone1B.
 Kyzer likes to get ahead of himself. He likes to make every question in ULX general help and support a development thread post. :D :P

We know that most questions here are regarding current ULX or its projects though.
Currently, ULX/ULib have no code written in to control player weapon loadout.

Now, with that being said, perhaps Kyzer will make a full blown tested and working module for ULX.
Then, after that, perhaps we'll finally make a full blown release of the next version of ULX that includes module support.
:)

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

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Weapon restrictions - Possible or not?
« Reply #7 on: August 20, 2007, 07:54:36 AM »
Well, it's not a module but a modification of uteam, it's working, but Megiddo i can't use the PlayerLoadout as i want :/

Anyway, into uteam.lua, replace the UTeam.setTeam function by this one:

Code: [Select]
function UTeam.setTeam( ply )
if not UTeam.checkGamemode() then return end

for k,v in ipairs( UTeam.teams ) do
if ply:IsUserGroup( v.group ) then
ply:SetTeam( UTeam.BASETEAMINDEX + k )
if v.hp then ply:SetHealth( v.hp ) end
if v.armor then ply:SetArmor( v.armor ) end
if v.model then timer.Simple( 0.1, ply.SetModel, ply, player_manager.TranslatePlayerModel( v.model ) )end
if v.weapons then
timer.Simple( 0.1, function(ply, v)
ply:StripWeapons()
for _,v in pairs(v.weapons) do
ply:Give( v )
end
ply:SelectWeapon(v.weapons[1])
end, ply, v)
end
if v.plytable then
timer.Simple( 0.1, function(ply, v)
for _,v in pairs(v.plytable) do
k = string.sub( v, 1, string.find( v, ":" ) - 1 )
v = string.sub( v, string.find( v, ":" ) + 1 )
ply:GetTable()[k] = tonumber(v) or v
end
end, ply, v)
end
break
end
end
end
hook.Add( "PlayerSpawn", "UTeamSetTeam", UTeam.setTeam )

Now you can add this in your UTeam.txt, for example:
Code: [Select]
"5"
{
"name" "[Client]"
"group" "user"
"model" "kleiner"
"color"
{
"r" "100"
"g" "100"
"b" "200"
"a" "255"
}
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
}
}

The first weapon is the one the player will spawn with. In this example, the player will spawn with the physgun as selected weapon. Hope that helps (i love coding)


JamminR, why "tested and working" in bold :) I test what i script :p

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Weapon restrictions - Possible or not?
« Reply #8 on: August 20, 2007, 09:55:54 AM »
Very good work Kyzer! Now if only we could talk spbogie into making configuration simpler somehow. :)

Maybe we could have something like... uteam_admin_color <r> <g> (b); uteam_admin_weapon <wep>; uteam_admin_weapon <wep>; uteam_admin_name <name!>
« Last Edit: August 20, 2007, 11:20:39 AM by Megiddo »
Experiencing God's grace one day at a time.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Weapon restrictions - Possible or not?
« Reply #9 on: August 20, 2007, 10:15:35 AM »
Thank you :)

Tim

  • Guest
Re: Weapon restrictions - Possible or not?
« Reply #10 on: August 21, 2007, 11:26:01 AM »
I just tried Kyzer's code, and replacing the default with it made everyone in my server appear as unassigned. I tried it some number of times making sure I didn't screw up anywhere, but stil failed to get it working. :(

Is there anything else that has to be done to get it to work? Or is it just me?

Tim

  • Guest
Re: Weapon restrictions - Possible or not?
« Reply #11 on: August 21, 2007, 12:55:49 PM »
Scratch that! I got it working!(and LOVE it)

It seems that if in UTeam.txt you set the players model BEFORE you put it what weapons they get, uteam.lua gets some load error:

RUN ERROR
File: autorun/UTeam.lua
Path: autorun
autorun/UTeam.lua:21 table index is nil

It was my fault after all I guess lol

ps: how long do registration emails usually take? Ive yet to get one for my account: rockonkenshin

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Weapon restrictions - Possible or not?
« Reply #12 on: August 21, 2007, 01:15:00 PM »
They don't take any time at all, is the email here http://forums.ulyssesmod.net/index.php?action=profile;u=767 correct? Also, did you check spam?
Experiencing God's grace one day at a time.

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: Weapon restrictions - Possible or not?
« Reply #13 on: August 21, 2007, 01:47:44 PM »
There is a problem with this code, i told that it choose the first weapon in the list you set, but it appear i was wrong and the table got mixed, and say i have 11 weapons for my team, v.weapons[1] is in fact the weapon #9 in the list :(. Any way to solve that Megiddo?

And Tim i don't have problems with the exact code i posted (setting weapons after their model). It sounds like you had something badly writted (a { or } was missing or something)

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Weapon restrictions - Possible or not?
« Reply #14 on: August 21, 2007, 02:04:09 PM »
There is a problem with this code, i told that it choose the first weapon in the list you set, but it appear i was wrong and the table got mixed, and say i have 11 weapons for my team, v.weapons[1] is in fact the weapon #9 in the list :(. Any way to solve that Megiddo?

And Tim i don't have problems with the exact code i posted (setting weapons after their model). It sounds like you had something badly writted (a { or } was missing or something)

Yes, use our ULib version of keyvalue parsing instead of garry's. I believe it's ULib.parseKeyValues( str ). It also drops the requirement for the "Out"{} wrapper and you can have it like this now...

Code: [Select]
"weapons"
{
"weapon_physgun"
"gmod_tool"
"gmod_camera"
}

ULib will automatically table.insert() stuff when there's only a value and no key. Neat, huh? :D
Experiencing God's grace one day at a time.