So I'm setting up a think that gives players guns at the start of a round, I found this code somewhere cuz I'm still rly new to lua but its not giving them the guns or anything :/
it might be that I'm using ulx/ulib ranks and i don't know if this code is looking for ulx
Thanks for any help
[CODE]-------------------------------------VIP--------------------------------------------------
local vipRanks = {"Vip"}
local vipHealth = 10
local vipWeapon = "weapon_zm_revolver"
function vipPerks( ply )
if ( table.HasValue( vipRanks, ply:GetNWString( "UserGroup" ) ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + vipHealth )
--ply:Give("EQUIP_ARMOR")
ply:Give( vipWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", vipPerks )
-------------------------------------MVP--------------------------------------------------
local mvpRanks = {"Mvp"}
local mvpHealth = 20
local mvpWeapon = "weapon_ttt_flaregun"
function mvpPerks( ply )
if ( table.HasValue( mvpRanks, ply:GetNWString( "UserGroup" ) ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + mvpHealth )
ply:Give("EQUIP_ARMOR")
ply:Give( mvpWeapon )
ply:Give( vipWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", mvpPerks )
-------------------------------------pro--------------------------------------------------
local mvpRanks = {"Pro"}
local mvpHealth = 50
local mvpWeapon = "weapon_ttt_health_station"
function proPerks( ply )
if ( table.HasValue( proRanks, ply:GetNWString( "UserGroup" ) ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + mvpHealth )
ply:Give("EQUIP_ARMOR")
ply:Give( mvpWeapon )
ply:Give( vipWeapon )
ply:Give( proWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", proPerks )[/CODE]
First off: You could have labeled this how to completely turn off anyone legit from playing your server with donator perks such as this.
Second: Try changing the GetNWString with ply:GetUserGroup()
[QUOTE=Nookyava;44588432]First off: You could have labeled this how to completely turn off anyone legit from playing your server with donator perks such as this.
Second: Try changing the GetNWString with ply:GetUserGroup()[/QUOTE]
ok I'm trying it and yes ik I'm trying to make it not turn off any players thats why I gave pro the health station cuz now instead of being more powerful then other players they can help other players out, but ontill summer when I get a job I need a way to keep my server up
[editline]19th April 2014[/editline]
ok its set up like this
[CODE]
function vipPerks( ply )
if ( table.HasValue( vipRanks, ply:GetUserGroup( "UserGroup" ) ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + vipHealth )
--ply:Give("EQUIP_ARMOR")
ply:Give( vipWeapon )
end
end[/CODE]
but its still not working :/
[code]ply:GetUserGroup( "UserGroup" )[/code]
You have changed "UserGroup" to the actual name of the group, right?
[lua]-------------------------------------VIP--------------------------------------------------
local vipRanks = {
"Vip",
"Mvp",
"Pro"
}
local vipHealth = 10
local vipWeapon = "weapon_zm_revolver"
function vipPerks( ply )
if ( table.HasValue( vipRanks, ply:GetUserGroup("vip") and not ply:IsSpec() )
ply:SetHealth( ply:Health() + vipHealth )
--ply:Give("EQUIP_ARMOR")
ply:Give( vipWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", vipPerks )[/lua]
Set it out like that and follow it.
[lua]
if ( table.HasValue( vipRanks, ply:GetUserGroup ) and not ply:IsSpec() )
[/lua]
Isn't GetUserGroup is a function?
[lua]
if ( table.HasValue( vipRanks, ply:GetUserGroup() ) and not ply:IsSpec() )
[/lua]
[QUOTE=NiandraLades;44588750][code]ply:GetUserGroup( "UserGroup" )[/code]
You have changed "UserGroup" to the actual name of the group, right?[/QUOTE]
yes
[CODE]function vipPerks( ply )
if ( table.HasValue( vipRanks, ply:GetUserGroup( "Vip" ) ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + vipHealth )
--ply:Give("EQUIP_ARMOR")
ply:Give( vipWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", vipPerks )[/CODE]
Why are you using table.HasValue for that? Just do..
[lua]if (table.HasValue(vipRanks, ply:GetUserGroup()))[/lua]
[QUOTE=Nookyava;44588998]Why are you using table.HasValue for that? Just do..
[lua]if (table.HasValue(vipRanks, ply:GetUserGroup()))[/lua][/QUOTE]
ok this is what i have so far, still not working :/
[CODE]-------------------------------------VIP--------------------------------------------------
local vipRanks = {"Vip"}
local vipHealth = 10
local vipWeapon = "weapon_zm_revolver"
function vipPerks( ply )
if ( table.HasValue( vipRanks, ply:GetUserGroup() ) and not ply:IsSpec() )
ply:SetHealth( ply:Health() + vipHealth )
--ply:Give("EQUIP_ARMOR")
ply:Give( vipWeapon )
end
end
hook.Add( "TTTBeginRound", "Rank_Perks", vipPerks )[/CODE]
Oh. Just realized what you're doing wrong.
[lua]hook.Add( "TTTBeginRound", "Rank_Perks", function()
for _, ply in ipairs(players.GetAll()) do -- Gets every player
if !ply:IsTerror() or !ply:GetUserGroup("vip") then continue end -- If they aren't "alive" or in the VIP, then they're skipped over
ply:SetHealth(ply:Health() + vipHealth)
ply:Give(vipWeapon)
end
end)[/lua]
Ok this is what i have so far and its still doing nothing
/garrysmod/addons/ranks/lua/autorun/rank.lua :
[CODE]-------------------------------------VIP--------------------------------------------------
local vipRanks = {"Vip"}
local vipHealth = 10
local vipWeapon = "weapon_zm_revolver"
hook.Add( "TTTBeginRound", "Vip_Perks", function()
for _, ply in ipairs(players.GetAll()) do --superadmin for testing
if !ply:IsTerror() or !ply:GetUserGroup("superadmin") then continue end
ply:SetHealth(ply:Health() + vipHealth)
ply:Give(vipWeapon)
end
end)[/CODE]
I'm sure it's something obvious I'm just dumb and new to lua :P
Instead of everything above, why not just get URS for ULX, it's a pretty nifty addon that allows you to add custom loadouts and restrict certain tools and entities from ULX groups.
[QUOTE=Variety;44591467]Instead of everything above, why not just get URS for ULX, it's a pretty nifty addon that allows you to add custom loadouts and restrict certain tools and entities from ULX groups.[/QUOTE]
ok thanks but I don't see a way to give players armor/health with it :/
Avoid setting a table like that.
Do something like this:
[lua]//
// Give weapons in TTT at the start of round based on group - Josh 'Acecool' Moser
//
//
// SETUP TABLE - Make sure the group names are all lower-case.
// if you set a group value as true, it gives "default" weapons defined below
// if you set a group value as a table, it'll give each weapon in that table
// if you set a group value as a string, it'll give that weapon
// if you set a group as false, or don't put the group in this table, it'll give default weapons, or none at all depending on what you defined below
//
local BONUS_GUNS_GROUPS_TABLE = {
vip = true;
superadmin = { "weapon_one", "weapon_two" };
admin = true;
member = "weapon_pistol";
};
//
// Give weapons at the start of a round
//
hook.Add( "TTTBeginRound", "TTTBeginRound:BonusWeapons", function( )
for k, _p in pairs( player.GetAll( ) ) do
local _group = string.lower( _p:GetNWString( "UserGroup" ) );
local _data = BONUS_GUNS_GROUPS_TABLE[ _group ];
// Depending on how you want to do it, you could give weapons in different ways such as via table and giving that group each weapon in the table, or if you want to give only one weapon you can use a string, or you can give default if it's set to true, or you can give default weapons if the data is false or non-existant.
if ( type( _data ) == "table" ) then
// Give weapons in the table because this is a "table" field.
for i, _w in pairs( _data ) do
_p:Give( _w );
end
elseif( type( _data ) == "string" ) then
// Give specific weapon because this is a "string" field.
_p:Give( _data );
elseif( _data ) then
// Give default weapons because this is a "true" field.
_p:Give( "weapon_x" );
_p:Give( "weapon_y" );
_p:Give( "weapon_z" );
else
// Do something, or not, because the group isn't even in the list...
end
end
end[/lua]
This script can be extended to set health, armor, and other things. For example:
[lua]
//
// Give stuff in TTT at the start of round based on group - Josh 'Acecool' Moser
//
--[[
Avoid setting a table like that.
Do something like this:
]]
//
// SETUP TABLE - Make sure the group names are all lower-case.
// All require tables if you decide to set them. There are many options available such as health, armor, weapons....
//
// Notice that not all options are set for each group; set as much or as little as you want
//
local BONUS_GUNS_GROUPS_TABLE = {
vip = {
health = 125;
armor = 100;
};
superadmin = {
health = 75;
armor = 75;
weapon = { "weapon_one", "weapon_two" };
};
admin = {
armor = 75;
weapon = "weapon_one";
};
member = {
health = 100;
armor = 100;
weapon = "weapon_two";
};
};
//
// Give weapons at the start of a round
//
hook.Add( "TTTBeginRound", "TTTBeginRound:BonusWeapons", function( )
for k, _p in pairs( player.GetAll( ) ) do
local _group = string.lower( _p:GetNWString( "UserGroup" ) );
local _data = BONUS_GUNS_GROUPS_TABLE[ _group ];
// If the data isn't correct skip...
if ( type( _data ) != "table" ) then continue; end
//
// WEAPON STUFF
//
if ( _data.weapon ) then
// If we have weapon data.. do something, maybe?
// Depending on how you want to do it, you could give weapons in different ways such as via table and giving that group each weapon in the table, or if you want to give only one weapon you can use a string, or you can give default if it's set to true, or you can give default weapons if the data is false or non-existant.
if ( type( _data.weapon ) == "table" ) then
// Give weapons in the table because this is a "table" field.
for i, _w in pairs( _data ) do
_p:Give( _w );
end
elseif( type( _data.weapon ) == "string" ) then
// Give specific weapon because this is a "string" field.
_p:Give( _data );
elseif( _data.weapon ) then
// Give default weapons because this is a "true" field.
_p:Give( "weapon_x" );
_p:Give( "weapon_y" );
_p:Give( "weapon_z" );
end
else
// Do something, or not, because the group isn't even in the list...
end
//
// HEALTH STUFF
//
if ( _data.health && isnumber( _data.health ) ) then
_p:SetHealth( _data.health );
end
//
// ARMOR STUFF
//
if ( _data.armor && isnumber( _data.armor ) ) then
_p:SetArmor( _data.armor );
end
end
end
[/lua]
Sorry, you need to Log In to post a reply to this thread.