Basically what the title says. I am now scripting NPC's. And I am working on a new GM. I was wondering how would you make an item such has item_food_watermelon into a con command to buy the item? All I got is
[lua]
function Food1(ply)
if ply:HasWeapon("weapon_real_cs_knife2") or ply:HasWeapon("weapon_real_cs_knife2") or ply:HasWeapon("weapon_real_cs_knife2") or ply:HasWeapon("rgm_lclaws") then
ply:PrintMessage( HUD_PRINTTALK, "You can't buy weapons as Zombie!" ) return false end
if ply:HasWeapon("weapon_physgun") or ply:HasWeapon("weapon_toolgun") then
ply:PrintMessage( HUD_PRINTTALK, "You can't buy items while Building." ) return false end
file.Write(gmod.GetGamemode().Name .."/money/"..ply:UniqueID()..".txt", ply:GetNWInt( "money" ))
--
if ply:GetNWInt( "money" ) < 80 then ply:PrintMessage( HUD_PRINTTALK, "You cannot afford this item." ) return false end
ply:SetNWInt("money", ply:GetNWInt( "money" ) - 80)
ply:Give("item_food_watermelon");
ply:EmitSound("buymenu/buy.wav")
end
concommand.Add( "food1", Food1 )
[/lua]
Looks good to me.
ply:HasWeapon("weapon_real_cs_knife2") or ply:HasWeapon("weapon_real_cs_knife2") or ply:HasWeapon("weapon_real_cs_knife2")
you only need one of these
You should check using theyre teams, not theyre weapons.
ok but the point is. ply:Give("item_Water_melon") dosen't work. the file "Item_water_melon" is located in item/gamemode. But I didn't include it in the init.lua or cl_init.lua... Theres about 30 items I want to put into shops. Also, when I tried the the con command "Food1" nothing happened. I didn't receive the item in my inventory or I didn't use it..
I don't understand why you just don't use:
something like If ply Is:Team == ("zombie") then prnt
shizzy stuff
end
or something.
I think hes he wants to be able to buy item_water_melon through a concommand and he can't get it to spawn.
(I fail at lua) is right. But when I buy it I want it to go to the Inventory.
and team_zombie is NOT THE POINT -_-. Read the title
-snip-
I got a new code
[lua]
function Inventory()
local stuff = {}
stuff[1] = { model = "models/props_junk/garbage_milkcarton002a.mdl", desc = "Drink milk", command = "Drink1" }
stuff[2] = { model = "models/props_junk/garbage_milkcarton002a.mdl", desc = "Drink milk", command = "Drink2" }
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Inventory")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k,v in pairs(stuff) do
local icon = vgui.Create( "SpawnIcon", IconList )
icon:SetModel( tostring(v.model) )
icon:SetToolTip(tostring(v.desc))
IconList:AddItem( icon )
icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand(tostring(v.command)) end
end
end
[/lua]
How would you add the 2 drinks into a buy shop?
What errors are you getting?
what do you mean errors?. Im trying to get the items to a buy shop
Oh, my bad here.
[LUA]
function Store()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 200, 195 )
DermaPanel:SetTitle( "Mini-Mart" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false)
DermaPanel:MakePopup()
DermaPanel:Center( true )
gui.EnableScreenClicker(true)
local Icon = vgui.Create( "SpawnIcon", Frame);
Icon:SetPos( 10, 25 );
Icon:SetParent( DermaPanel )
Icon:SetModel( "models/props_junk/garbage_milkcarton002a.mdl" );
Icon.DoClick = function()
RunConsoleCommand("Drink1");
end
local Icon = vgui.Create( "SpawnIcon", Frame);
Icon:SetPos( 10, 90 );
Icon:SetParent( DermaPanel )
Icon:SetModel( "models/props_junk/garbage_milkcarton002a.mdl" );
Icon.DoClick = function()
RunConsoleCommand("Drink2");
end
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel )
DermaButton:SetText( "I'm done shoping for now." )
DermaButton:SetPos( 10, 155 )
DermaButton:SetSize( 180, 30 )
DermaButton.DoClick = function ()
DermaPanel:Close(gui.EnableScreenClicker(false))
end
end
concommand.Add("store", Store)
[/LUA]
Type store in console to open it up It runs drink1 for the first icon and drink 2 for the second one.
ok ok I c. How can we set a Price for an Item?
[editline]07:44PM[/editline]
Im getting an error
Lua initialized (Lua 5.1)
gamemodes\morph\gamemode\cl_init.lua:1: unexpected symbol near '#'
**********************************************
**********************************************
********** COULDN'T LOAD GAMEMODE!! **********
**********************************************
**********************************************
There was a problem opening the gamemode file 'Morph/gamemode/cl_init.lua'
post code?
Sorry, you need to Log In to post a reply to this thread.