• Print

Author Topic: Ply:Give() -- non-default weapons  (Read 7091 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Ply:Give() -- non-default weapons
« on: September 22, 2014, 07:39:58 pm »
I really hate coming here every time I need help with something
It just feels weird
But I can't figure this one out


I installed an addon on to the server that added weapons using the CSS models for weapons
When I go to the ULX menu and spawn in an AK-47 from there, it'll work:


But when I put this in the code of the gamemode, it doesn't give me anything
ply:Give("ptp_cs_ak47")

ply is defined
The stuff around it works fine
I get no errors when I run the code

Here is "the stuff around it"
Code: Lua
  1. if ply:Team() == TEAM_PRISONER then
  2.         ply:SetHealth(ply:GetMaxHealth())
  3.         ply:StripWeapons()
  4.         ply:StripAmmo()
  5.         ply:SetWalkSpeed(230)
  6.         ply:SetRunSpeed(350)
  7.         ply:AllowFlashlight(true)
  8.         ply:SetArmor(0)
  9.     elseif ply:Team() == TEAM_GUARD then
  10.         ply:SetHealth(ply:GetMaxHealth())
  11.         ply:SetWalkSpeed(230)
  12.         ply:SetRunSpeed(350)
  13.         ply:AllowFlashlight(true)
  14.         ply:SetArmor(0)
  15.         ply:Give("ptp_cs_ak47")
  16.     end

I looked up Player.Give on the gmod wiki (the outdated one because it's better) and it told me that it only works with default items supplied by the game: https://maurits.tv/data/garrysmod/wiki/w...x61ee.html
That being said, how would I go about giving a player a non-default weapon



(and maybe if you know how to solve this, reply there) ;)

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Ply:Give() -- non-default weapons
« Reply #1 on: September 22, 2014, 10:02:11 pm »
If I remember right, I managed to use ply:Give() with gamemode weapons (in case it was in TTT - custom ones too). When it comes to addons, I'm not sure, but try installing the addon into the gamemode if possible?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Ply:Give() -- non-default weapons
« Reply #2 on: September 22, 2014, 11:45:09 pm »
Try putting the weapons in garrysmod/gamemodes/(gamemodename)/entities/weapons/.
Out of the Garry's Mod business.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ply:Give() -- non-default weapons
« Reply #3 on: September 23, 2014, 10:49:39 am »
nope
still not working

I put the "ptp_cs_ak47.lua" file in garrysmod/gamemodes/zjailbreak/entities/weapons
The player still isn't given the weapon
I still get no errors

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Ply:Give() -- non-default weapons
« Reply #4 on: September 23, 2014, 12:38:50 pm »
Hello there,
then it looks like something is wrong with the weapon, are you sure you are not getting ANY errors when the server starts?

Please do post your code of the weapon.

Avoid

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ply:Give() -- non-default weapons
« Reply #5 on: September 23, 2014, 01:06:31 pm »
There were no errors that have anything to do with the gun/gamemode

Here's the code for the gun
Code: Lua
  1. if ( SERVER ) then
  2.  
  3.         AddCSLuaFile( "ptp_cs_ak47.lua" )
  4.        
  5. end
  6.  
  7. if ( CLIENT ) then
  8.  
  9.         SWEP.PrintName                  = "AK-47"                      
  10.         SWEP.Author                             = "Fonix"
  11.         SWEP.Slot                               = 2
  12.         SWEP.SlotPos                    = 1
  13.         SWEP.IconLetterCSS              = "b"
  14.        
  15.         killicon.AddFont( "ptp_cs_ak47", "CSKillIcons", SWEP.IconLetterCSS, Color( 255, 80, 0, 255 ) )
  16.        
  17. end
  18.  
  19. SWEP.HoldType                   = "ar2"
  20. SWEP.Base                               = "ptp_weapon_base"
  21. SWEP.Category                   = "Counter-Strike: PTP"
  22. SWEP.ViewModelFlip              = false
  23. SWEP.ViewModelFOV               = 60
  24.  
  25. SWEP.Spawnable                  = true
  26. SWEP.AdminSpawnable             = true
  27. SWEP.UseHands                   = true
  28.  
  29. SWEP.ViewModel                  = "models/weapons/cstrike/c_rif_ak47.mdl"
  30. SWEP.WorldModel                 = "models/weapons/w_rif_ak47.mdl"
  31.  
  32. SWEP.Weight                             = 5
  33. SWEP.AutoSwitchTo               = true
  34. SWEP.AutoSwitchFrom             = true
  35.  
  36. SWEP.Primary.Sound                      = Sound( "weapon_ak47.single" )
  37. SWEP.Primary.Recoil                     = 3
  38. SWEP.Primary.Damage                     = 34
  39. SWEP.Primary.NumShots           = 1
  40. SWEP.Primary.Cone                       = 0.02
  41. SWEP.Primary.ClipSize           = 30
  42. SWEP.Primary.Delay                      = 0.1
  43. SWEP.Primary.DefaultClip        = 120
  44. SWEP.Primary.Automatic          = true
  45. SWEP.Primary.Ammo                       = "smg1"
  46.  
  47. SWEP.Secondary.ClipSize         = -1
  48. SWEP.Secondary.DefaultClip      = -1
  49. SWEP.Secondary.Automatic        = false
  50. SWEP.Secondary.Ammo                     = "none"
  51.  
  52. SWEP.IronSightsPos = Vector(-6.614, -11.551, 2.648)
  53. SWEP.IronSightsAng = Vector(2.275, 0, 0)
  54. SWEP.AimSightsPos = Vector(-6.614, -11.551, 2.648)
  55. SWEP.AimSightsAng = Vector(2.275, 0, 0)
  56. SWEP.DashArmPos = Vector(4.355, -7.206, -0.681)
  57. SWEP.DashArmAng = Vector(-10.965, 37.062, -10.664)
  58.  
  59.  
  60. --Extras
  61. SWEP.ReloadHolster              = 2.4
  62.  
  63. -- Accuracy
  64. SWEP.CrouchCone                         = 0.01 -- Accuracy when we're crouching
  65. SWEP.CrouchWalkCone                     = 0.02 -- Accuracy when we're crouching and walking
  66. SWEP.WalkCone                           = 0.025 -- Accuracy when we're walking
  67. SWEP.AirCone                            = 0.1 -- Accuracy when we're in air
  68. SWEP.StandCone                          = 0.015 -- Accuracy when we're standing still
  69. SWEP.Delay                              = 0.1
  70. SWEP.Recoil                             = 3
  71. SWEP.RecoilZoom                 = 0.7
  72. SWEP.IronSightsCone                     = 0.01

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Ply:Give() -- non-default weapons
« Reply #6 on: September 27, 2014, 01:28:27 pm »
oh boy
I found the problem
I feel dumb :C

The problem fell under my DPanel buttons that Neku and Decicus helped me with earlier
When I was typing it out, I accidentally typed 0 instead of 1 on the ply:SetGamemodeTeam in the guard section
Code: Lua
  1. net.Receive( "ChoiceIsGuard", function( len, ply )
  2.         ply:SetGamemodeTeam( 0 )
  3.         ply:KillSilent()
  4.         ply:SetModel("models/player/combine_soldier_prisonguard.mdl")
  5.         ply:Spawn()
  6. end )

In other words, the guard button set the client to the prisoner team
So whenever my GM:PlayerSpawn would check to see if the person is on the guard team to see if it should give them an AK47, they would always be a prisoner

Thanks for the help again, Neku and Decicus
You two are a great help

  • Print