• Print

Author Topic: Can someone pease help with my lua problem  (Read 4955 times)

0 Members and 1 Guest are viewing this topic.

Offline Shadow Knight

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Can someone pease help with my lua problem
« on: May 21, 2017, 09:51:59 am »
I have a militaryRP server and i want staff and donators to spawn with phygun and toolgun but its working i put it in this dir garrysmod/lua/server/weapons.lua

Heres my code

function Custom_Loadout( ply )
//All Staff
   if ( ply:IsUserGroup( "owner" ) or ply:IsUserGroup( "community-manager" ) or ply:IsUserGroup( "staff-manager" ) or ply:IsUserGroup( "server-builder" ) or ply:IsUserGroup( "superadmin" ) or ply:IsUserGroup( "admin" ) or ply:IsUserGroup( "moderator" ) or ply:IsUserGroup( "trial-moderator" )) then
      
      ply:Give( "weapon_physgun" )
      ply:Give( "weapon_tool" )
 
   end

//Donators
   if ( ply:IsUserGroup( "donator" ) or ply:IsUserGroup( "donator+" ) or ply:IsUserGroup( "donator++" ))

      ply:Give( "weapon_physgun" )
      ply:Give( "weapon_tool" )


        end
end
hook.Add( "PlayerLoadout", "CustomGamemodeLoadoutFunction", Custom_Loadout )


Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Can someone pease help with my lua problem
« Reply #1 on: May 21, 2017, 10:23:34 am »
You could do a InitialSpawn hook and a group table to make it tidier and easier to look at like so.

Code: Lua
  1. local groups = {"owner", "community-manager", "staff-manager", "server-builder", "superadmin",
  2. "admin", "moderator", "trial-moderator", "donator", "donator+", "donator++"}
  3.  
  4. hook.Add( "PlayerInitialSpawn", "WepsStuff", function( ply )
  5.  
  6.         if ( table.HasValue( groups, ply:GetUserGroup() ) ) then
  7.        
  8.                 ply:Give( "weapon_physgun" )
  9.                 ply:Give( "weapon_tool" )
  10.                
  11.         end
  12.        
  13. end )
« Last Edit: May 21, 2017, 11:08:21 am by BlueNova »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Can someone pease help with my lua problem
« Reply #2 on: May 21, 2017, 11:06:29 am »
Is the problem that it's not being run?

things inside the lua/server folder aren't autorun.

You need to place your file in garrysmod/lua/autorun/server

The table thing that BlueNova posted is a much better way of doing it instead of an if statement though, but if you want the player to spawn with it each time, you still need to use the PlayerLoadout hook, InitialSpawn would only give it to them when they joined the server but not if they died and respawned.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Can someone pease help with my lua problem
« Reply #3 on: May 21, 2017, 01:16:36 pm »
You could also do a PlayerSpawn hook rather than initial spawn to give them the weapons each time they spawn. Loadout hook may work better though.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Can someone pease help with my lua problem
« Reply #4 on: May 21, 2017, 01:45:29 pm »
BlueNova: The Loadout hook is designed for giving weapons. Yes.. it might work in a PlayerSpawn hook, but the proper hook to use would be the Loadout hook.

  • Print