Ulysses
Ulysses Stuff => General Chat & Help and Support => Topic started by: Clone1B 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.
-
Maybe something like that:
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 :)
-
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.
-
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 :)
-
UTeam was written by spbogie, so it's up to him.
-
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?
-
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.
:)
-
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:
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:
"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
-
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!>
-
Thank you :)
-
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?
-
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
-
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?
-
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)
-
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...
"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
-
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?
I had set my email to private accidently, so I cannot see it. The address is geoff1505@yahoo.com if you wouldn't mind checking
Also kyzer, after looking over it again I see thats just what I did :P
-
Hmm, alright Tim. I went ahead and activated your account for you.
-
Thank you very much! I don't know why it didn't get to me, I made sure to check my spam box too. Thats wierd.
Anyway, Thanks again ;D
-
Well it works for me, but when I check teams in TAB, it is showing all yellow. The teams still work, it just will not showing. I will post my uteams txt and lua files.
TXT
"Out"
{
"teams"
{
"1"
{
"name" "Owner"
"group" "superadmin"
"armor" "2000"
"hp" "2000"
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
"4" "weapon_physcannon"
"5" "weapon_crowbar"
"6" "weapon_pistol"
"7" "weapon_shotgun"
"8" "weapon_smg1"
"9" "weapon_crossbow"
"10" "weapon_357"
"11" "weapon_ar2"
"12" "weapon_frag"
"13" "weapon_annabelle"
"14" "weapon_slam"
"15" "item_ar2_grenade"
"16" "item_ml_grenade"
}
"color"
{
"a" "255"
"B" "255"
"g" "255"
"r" "255"
}
"plytable"
{
"1" "SprintSpeed:1000"
"2" "WalkSpeed:500"
}
}
"2"
{
"name" "HIGHLY Respected"
"group" "admin"
"armor" "1000"
"hp" "1000"
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
"4" "weapon_physcannon"
"5" "weapon_crowbar"
"6" "weapon_pistol"
"7" "weapon_shotgun"
"8" "weapon_smg1"
"9" "weapon_crossbow"
"10" "weapon_357"
"11" "weapon_ar2"
"12" "weapon_frag"
}
"color"
{
"a" "255"
"B" "0"
"g" "240"
"r" "222"
}
}
"3"
{
"name" "Moderator Member"
"group" "moderator"
"armor" "500"
"hp" "500"
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
"4" "weapon_physcannon"
"5" "weapon_crowbar"
"6" "weapon_pistol"
"7" "weapon_shotgun"
"8" "weapon_smg1"
}
"color"
{
"a" "255"
"B" "50"
"g" "50"
"r" "255"
}
}
"4"
{
"name" "Members"
"group" "operator"
"armor" "0"
"hp" "150"
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
"4" "weapon_physcannon"
"5" "weapon_crowbar"
"6" "weapon_pistol"
}
"color"
{
"a" "255"
"B" "254"
"g" "172"
"r" "61"
}
}
"5"
{
"name" "N00b"
"group" "n00b"
"armor" "0"
"hp" "50"
"color"
{
"a" "255"
"B" "127"
"g" "127"
"r" "127"
}
"weapons"
{
"1" "weapon_physcannon"
"2" "gmod_camera"
}
}
"6"
{
"name" "Guest"
"group" "user"
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
}
"color"
{
"a" "255"
"B" "138"
"g" "0"
"r" "135"
}
}
}
"gamemodes"
{
"1" "Sandbox"
"2" "Spacebuild2"
}
}
I do not think it is this since the teams are working
Lua
if not SERVER then return end
UTeam = {}
UTeam.BASETEAMINDEX = 20
UTeam.CONFIG = "UTeam.txt"
if not file.Exists( UTeam.CONFIG ) then
Msg( "[UTeam Error] UTeam config file missing.\n" )
return
end
local t = util.KeyValuesToTable( file.Read( UTeam.CONFIG ) )
if not t.teams then
Msg( "[UTeam Error] UTeam config teams table missing.\n" )
return
end
UTeam.teams = {}
for k,v in pairs( t.teams ) do
UTeam.teams[tonumber(k)]=v
end
if not t.gamemodes then
Msg( "[UTeam Error] UTeam config gamemodes table missing.\n" )
return
end
UTeam.gamemodes = t.gamemodes
function UTeam.checkGamemode()
for _,v in pairs( UTeam.gamemodes ) do
if string.lower(GAMEMODE.Name) == string.lower(v) then return true end
end
hook.Remove( "PlayerSpawn", "UTeamSetTeam" )
hook.Remove( "PlayerInitialSpawn", "UTeamSetupTeams" )
return false
end
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 )
Thanks.
Edit: Ok well it will not let me do any admin things (like !menu), but the HP and things work.
-
Try moving the weapon part at the end of each groups
-
Well I can do admin things again, but still getting everyone as yellow, and does not show the team you are on. Does it affect that I am using a deticated server? Or maybe it is because I am putting slam under superadmin? That is the only things I can thing of. I will try it with getting rid of the slam and see what happens.
Edit:
It is still giving me yellow, I am still going to try a listen server, but it might take some time becuase I keep getting a invalid steam user ID ticket while starting the server.
-
I'm getting the exact same problem as Typo, any idea how to fix this?
-
What a coincidence.. I was about to ask how do I add weapon management to UTeam..
I've seen the code around here, if I remember correctly isn't it
"1"
{
"name" "Owner of [BS]"
"group" "superadmin"
"armor" "1000"
"hp" "1000"
"color"
{
"a" "255"
"B" "0"
"g" "179"
"r" "21"
}
"plytable"
{
"1" "SprintSpeed:1000"
"2" "WalkSpeed:500"
}
"model" "police"
}
"weapons"
{
"weapon_pistol"
}
}
EDIT: Found it:
http://forums.ulyssesmod.net/index.php/topic,1171.msg5586.html#msg5586
-
What have I done wrong here? I have 15 year olds running round with RPGs O.O
"6"
{
"name" "Member"
"group" "member"
"armor" ""
"hp" "100"
"model" "male16"
"color"
{
"a" "255"
"B" "255"
"g" "146"
"r" "86"
}
"weapons"
{
"1" "weapon_physgun"
"2" "weapon_phycannon"
"3" "gmod_tool"
"4" "gmod_camera"
}
}
-
Without knowing what errors your getting in console (always provide server console lua errors when reporting bugs), it's near impossible to tell why it's not working for you.
However, I do remember reading this looking over the posts of this topic. You do have model before weapons.
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
-
The problem with using player loadout restriction to restrict weapons on a build server is simply this...
Advanced Dupe > RPG... everyone has this saved on their machine.
If you are looking a more permanent solution Id dig a little deeper and go with a script that blocks the entity from even being spawned or existing on the server at all. Or there is the playerequip > player pickup hooks.
-
ULib/ULX SVN + URestrict
-
Without knowing what errors your getting in console (always provide server console lua errors when reporting bugs), it's near impossible to tell why it's not working for you.
However, I do remember reading this looking over the posts of this topic. You do have model before weapons.
I though having "model" there was ok, as Kyzer laid it out the same. There are no lua errors, the models work fine, the HP/Amour work fine..
-
Yeah, you should be able to set it up in any order you want as it's creating a table with keys and values. Having model before weapons shouldn't effect anything.
-
Not to worry, I looked into URestrict, and jobs a good'un. And I really approve of the new GUI =]