I've been making a buymenu from a tutorial and after adding
[lua]
local BuyMenu = nil
function GM:ShowBuyMenu()
if ( !IsValid( BuyMenu ) ) then
BuyMenu = vgui.CreateFromTable( vgui_Splash )
BuyMenu:SetHeaderText( "In-Game Shop" )
BuyMenu:SetHoverText( "Buy all your Ballistic needs here." )
local function = function() LocalPlayer():Give( "weapon_shotgun" ) end
local Button = BuyMenu:AddSelectButton( "Shotgun", function )
Button.m_colBackground = Color(255, 90, 90, 255)
local function2 = function() LocalPlayer():Giveammo( 30, "buckshot" ) end
local Button2 = BuyMenu:AddSelectButton( "Shotgun Ammo", function2 )
Button2.m_colBackground = Color(255, 90, 90, 255)
Button2.Think = function(self)
self:SetDisabled( !LocalPlayer():HasWeapon( "weapon_shotgun" ) )
end
BuyMenu:AddCancelButton()
end
BuyMenu:MakePopup()
end
concommand.Add("buymenu", GM:ShowBuyMenu() )
[/lua]
To my cl_init.lua and
[lua]
function GM:OnSpawnMenuOpen()
LocalPlayer():ConCommand("buymenu")
end
[/lua]
to my shared.lua my gamemode kills itself... and wont include random .luas
ideas?
I had the same problem with LocalPlayer I assume Garry's mod doesn't like it :|
Rather then making the button give the weapon make it do
RunConsoleCommand(whatever)
and set up a concommand for giving that weapon or whatever in the init
It's fretta and normally localplayer works fine :S
Yeah, i tried it in fretta also and it didnt work
cl_init.lua
[lua]
local function8 = function() RunConsoleCommand( "357takemoney" ) end
local Button8 = BuyMenu:AddSelectButton( "$15 - 357", function8 )
Button.m_colBackground = Color(255, 90, 90, 255)
[/lua]
init.lua
[lua]function give357(ply)
ply:Give("weapon_357")
ply:GiveAmmo( 30, "357" )
end
concommand.Add("357takemoney", give357)
[/lua]
How mine works. Of course removed the actual NWint parts
Sorry how would i change my script then?
cl_init.lua
[lua]
local BuyMenu = nil
function GM:ShowBuyMenu()
if ( !IsValid( BuyMenu ) ) then
BuyMenu = vgui.CreateFromTable( vgui_Splash )
BuyMenu:SetHeaderText( "In-Game Shop" )
BuyMenu:SetHoverText( "Buy all your Ballistic needs here." )
local function = function() RunConsoleCommand( "purchaseshotgun" ) end
local Button = BuyMenu:AddSelectButton( "Shotgun", function )
Button.m_colBackground = Color(255, 90, 90, 255)
BuyMenu:AddCancelButton()
end
BuyMenu:MakePopup()
end
concommand.Add( "Buy_Menu", function( ply, cmd, args ) hook.Call( "ShowBuyMenu", GAMEMODE ) end ) --Just how i like doing it..don't ask [/lua]
init.lua
[lua]function lolshotgunlolol(ply)
ply:Give("weapon_shotgun")
ply:GiveAmmo( 20, "buckshot" )
ply:ChatPrint("Bought Shotgun, and 20 shells!)
end
concommand.Add("purchaseshotgun", lolshotgunlolol) [/lua]
and i suggest doing something like this instead of what you did to open it
init.lua
[lua]function PlayerInitialSpawn( ply )
ply:ChatPrint("Bind a key to buy_menu to access the buy menu")
end[/lua]
or if you already have a initial spawn then add it on to it
After fixing missing things like " and changing a function name i had this.
[lua]
local BuyMenu = nil
function GM:ShowBuyMenu()
if ( !IsValid( BuyMenu ) ) then
BuyMenu = vgui.CreateFromTable( vgui_Splash )
BuyMenu:SetHeaderText( "In-Game Shop" )
BuyMenu:SetHoverText( "Buy all your Ballistic needs here." )
local functionshotg = function() RunConsoleCommand( "purchaseshotgun" ) end
local Button = BuyMenu:AddSelectButton( "Shotgun", functionshotg )
Button.m_colBackground = Color(255, 90, 90, 255)
BuyMenu:AddCancelButton()
end
BuyMenu:MakePopup()
end
concommand.Add( "buy_menu", function( ply, cmd, args ) hook.Call( "ShowBuyMenu", GAMEMODE ) end ) --Just how i like doing it..don't ask
[/lua]
and the init looks like
[lua]
function shotgbuy(ply)
ply:Give("weapon_shotgun")
ply:GiveAmmo( 20, "buckshot" )
ply:ChatPrint(..ply.." Bought Shotgun, and 20 shells!")
end
concommand.Add("purchaseshotgun", shotgbuy)
function PlayerInitialSpawn( ply )
ply:ChatPrint("Bind a key to buy_menu to access the buy menu")
end [/lua]
I get spawned with the smg and gamemode not working and no errors.
[QUOTE=DocDoomsday;19751300]cl_init.lua
local BuyMenu = nil
function GM:ShowBuyMenu()
if ( !IsValid( BuyMenu ) ) then
BuyMenu = vgui.CreateFromTable( vgui_Splash )
BuyMenu:SetHeaderText( "In-Game Shop" )
BuyMenu:SetHoverText( "Buy all your Ballistic needs here." )
local function = function() RunConsoleCommand( "purchaseshotgun" ) end
local Button = BuyMenu:AddSelectButton( "Shotgun", function )
Button.m_colBackground = Color(255, 90, 90, 255)
BuyMenu:AddCancelButton()
end
BuyMenu:MakePopup()
end
concommand.Add( "Buy_Menu", function( ply, cmd, args ) hook.Call( "ShowBuyMenu", GAMEMODE ) end ) --Just how i like doing it..don't ask
init.lua
function lolshotgunlolol(ply)
ply:Give("weapon_shotgun")
ply:GiveAmmo( 20, "buckshot" )
ply:ChatPrint("Bought Shotgun, and 20 shells!)
end
concommand.Add("purchaseshotgun", lolshotgunlolol)
and i suggest doing something like this instead of what you did to open it
init.lua
function PlayerInitialSpawn( ply )
ply:ChatPrint("Bind a key to buy_menu to access the buy menu")
end
or if you already have a initial spawn then add it on to it[/QUOTE]
Are you sure about using a language word as a function name? Holy fuck RTF edit box broke the tags
[QUOTE=noforgivin;19751524]After fixing missing things like " and changing a function name i had this.
[code]
function PlayerInitialSpawn( ply )
ply:ChatPrint("Bind a key to buy_menu to access the buy menu")
end [/code]
I get spawned with the smg and gamemode not working and no errors.[/QUOTE]
DOH!
[lua]
function PlayerInitialSpawn( ply )
ply:ChatPrint("Bind a key to buy_menu to access the buy menu")
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
[/lua]
Even though its the same still have to add hook, I forgot about it :|
Lol thanks, trying now.
[editline]06:32AM[/editline]
Ok well i tried and also changed the button name to something that wasn't language. Tried with and without, but here is the console log, and i spawned with a broken gamemode and smg etc.
[lua]
Connecting to 217.112.93.166:27015...
Connected to 217.112.93.166:27015
Ballistic
Map: gm_construct
Players: 1 / 20
Build: 3943
Server Number: 1
No pure server whitelist. sv_pure = 0
Lua initialized (Lua 5.1)
======== Beam NetVars Lib v0.71 Installed ========
======== Installing Table (De)Serialiser Module | ver: 1.4 ========
=== Loading Wire Menus ===
PCMod2: Loading BASE configuation file...
PCMod2: Loading ACTUAL configuation file...
PCMod2: Configuration file loaded!
PCMod2: Loaded plugin 'darkrp_235'!
PCMod2: >> DarkRP 2.3.5 PCMod Plugin 1.0.0 Pre-Loaded! <<
PCMod2: PCMod Version 2.0.4 Installed
PCMod2: Loading PCMod Core...
--- Missing Vgui material models/darksunrise/computer_ref
RunConsoleCommand blocked - sent before player spawned (sv_tags)
======== The Same Version of BeamNetVars Detected || Skipping ========
loading materials
loading material: cable/rope_icon
loading material: cable/cable2
loading material: cable/xbeam
loading material: cable/redlaser
loading material: cable/blue_elec
loading material: cable/physbeam
loading material: cable/hydra
loading material: arrowire/arrowire
loading material: arrowire/arrowire2
=== Loading Wire Model Packs ===
Loaded: PHXWireModels.txt
Loaded: default.txt
Loaded: expression2.txt
Loaded: cheeze_buttons2.txt
Loaded: wire_model_pack_1.txt
Loaded: wire_model_pack_1plus.txt
Adding Cheeze's Buttons Pack
Adding various Buttons from HL2 and Portal
Jaanus' Thruster Pack
Beer's Model pack
ERROR! Module 'zlib_b64' not found!
RunConsoleCommand blocked - sent before player spawned (ZLib_Installed)
==== Advanced Duplicator v.1.72 shared module installed! ====
==== Advanced Duplicator v.1.741 client module installed! ====
=== Loading Wire Model Packs ===
Loaded: PHXWireModels.txt
Loaded: default.txt
Loaded: expression2.txt
Loaded: cheeze_buttons2.txt
Loaded: wire_model_pack_1.txt
Loaded: wire_model_pack_1plus.txt
Adding Cheeze's Buttons Pack
Jaanus' Thruster Pack
loading materials
loading material: cable/rope_icon
loading material: cable/cable2
loading material: cable/xbeam
loading material: cable/redlaser
loading material: cable/blue_elec
loading material: cable/physbeam
loading material: cable/hydra
loading material: arrowire/arrowire
loading material: arrowire/arrowire2
loading material: cable/rope_icon
loading material: cable/cable2
loading material: cable/xbeam
loading material: cable/redlaser
loading material: cable/blue_elec
loading material: cable/physbeam
loading material: cable/hydra
loading material: arrowire/arrowire
loading material: arrowire/arrowire2
Registering gamemode 'fretta' derived from 'base'
Registering gamemode 'Ballistic' derived from 'fretta'
Couldn't include file 'weapons/gmod_tool/object.lua' (File not found)
Couldn't include file 'weapons/gmod_tool/ghostentity.lua' (File not found)
Couldn't include file 'weapons/gmod_tool/object.lua' (File not found)
Couldn't include file 'weapons/gmod_tool/ghostentity.lua' (File not found)
--- Missing Vgui material hudindicator/hi_fullcircle
--- Missing Vgui material hudindicator/hi_semicircle
Couldn't include file 'shared.lua' (File not found)
Folder = entities/mario_sent_atomic_bomb
AdminSpawnable = true
Spawnable = false
Couldn't register Scripted Entity mario_sent_atomic_bomb - the Type field is empty!
Couldn't include file 'shared.lua' (File not found)
Folder = entities/mk-82-fragile_sent_atomic_bomb
AdminSpawnable = true
Spawnable = false
Couldn't register Scripted Entity mk-82-fragile_sent_atomic_bomb - the Type field is empty!
ASS Plugin -> plugins/ass_afkkicker.lua
ASS Plugin -> plugins/ass_armor.lua
ASS Plugin -> plugins/ass_burn.lua
ASS Plugin -> plugins/ass_cleardecals.lua
ASS Plugin -> plugins/ass_disablekill.lua
ASS Plugin -> plugins/ass_exformat.lua
ASS Plugin -> plugins/ass_explode.lua
ASS Plugin -> plugins/ass_freeze.lua
ASS Plugin -> plugins/ass_gimp.lua
ASS Plugin -> plugins/ass_god.lua
ASS Plugin -> plugins/ass_health.lua
ASS Plugin -> plugins/ass_kill.lua
ASS Plugin -> plugins/ass_map.lua
ASS Plugin -> plugins/ass_motd.lua
ASS Plugin -> plugins/ass_mute.lua
ASS Plugin -> plugins/ass_noclip.lua
ASS Plugin -> plugins/ass_noplayercollision.lua
ASS Plugin -> plugins/ass_notice.lua
ASS Plugin -> plugins/ass_pickupplayers.lua
ASS Plugin -> plugins/ass_ragdoll.lua
ASS Plugin -> plugins/ass_rocket.lua
ASS Plugin -> plugins/ass_slap.lua
ASS Plugin -> plugins/ass_speed.lua
ASS Plugin -> plugins/ass_stopsounds.lua
ASS Plugin -> plugins/ass_team.lua
ASS Plugin -> plugins/ass_teleport.lua
ASS Plugin -> plugins/ass_voicemute.lua
AssVote Init
ASS Plugin -> plugins/ass_vote.lua
ASS Plugin -> plugins/ass_weapons.lua
Sending 32 'User Info' ConVars to server (cl_spewuserinfoconvars to see)
Hey 'noforgivin' - You're in the 'superadmin' group on this server.
AdvDupeShared: Server Compression: false
===============================
=== Wire 1877 Installed ===
===============================
Hook 'gmod_wire_hologram_shared' Failed: entities\gmod_wire_hologram\shared.lua:14: attempt to index field 'base_gmodentity' (a nil value)
Redownloading all lightmaps
PCMod2: >> DarkRP 2.3.5 PCMod Plugin 1.0.0 Post-Loaded! (NO DARKRP)<<
[MAD]Noforgivin spawned from London, London, United Kingdom
Unknown command: seensplash
] buy_menu
Unknown command: purchaseshotgun
[/lua]
Sorry, you need to Log In to post a reply to this thread.