...usScript\gamemode\schemas/hl2rp/items/propaganda.lua:22: attempt to index global 'vgui' (a nil value)
-----------------------
ITEM.Name = "Propaganda";
ITEM.Class = "propaganda";
ITEM.Description = "Propaganda from Resistances";
ITEM.Model = "models/props_junk/garbage_newspaper001a.mdl";
ITEM.Purchaseable = true;
ITEM.Price = 1;
ITEM.ItemGroup = 1;
function ITEM:Drop(ply)
end
function ITEM:Pickup(ply)
self:Remove();
end
function ITEM:UseItem(ply)
HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")
end
-------------------
Line 22: HTMLTest = vgui.Create("HTML")
Wtf is wrong?
You need to create the vgui clientside.
Are you sure the vgui/visuals are only being called on the client?
If you run a script like that through shared or Server side vgui does not exist.
What SebSharpy said...
Ehhm, and how do i creat the client side thing? Could anyone send the code and tell me where i shold put it?
Guessing you script is being run shared. All that it should require is for you to place
[lua]if (CLIENT) then
--vgui.Create( "things_here" )
end
[/lua]
Right?
ITEM.Name = "Propaganda";
ITEM.Class = "propaganda";
ITEM.Description = "Propaganda from Resistances";
ITEM.Model = "models/props_junk/garbage_newspaper001a.mdl";
ITEM.Purchaseable = true;
ITEM.Price = 1;
ITEM.ItemGroup = 1;
function ITEM:Drop(ply)
end
function ITEM:Pickup(ply)
self:Remove();
end
function ITEM:UseItem(ply)
if (CLIENT) then
HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")
end
end
[editline]09:14AM[/editline]
Okey, it works no errors. but no Windows open. Nothihing happens.
That's because ITEM:UseItem is called on the server, and the server only.
[QUOTE=Lexic;17493536]That's because ITEM:UseItem is called on the server, and the server only.[/QUOTE]
Because of this, you would ([i]recommended[/i]) use a [b][url=http://wiki.garrysmod.com/?title=User_Messages]user message[/url][/b] from the server to the client, to tell the client to open it.
The wiki link provided should help you through the process.
The clientside code can be placed anywhere that is included by cl_init.lua
[QUOTE=Crazy Quebec;17495530]The clientside code can be placed anywhere that is included by cl_init.lua[/QUOTE]
Picking away at nothing here, but you don't specifically need to include things in cl_init. You can include files in separate scripts or even SendLua it.
ehm, now don't understand a shit xD
Okey, shold i add:
function my_message_hook( um )
Msg( "The text is " .. um:ReadString() .. "\n" )
Msg( "The number is " .. um:ReadLong() .. "\n" )
Msg( "The entity " .. tostring( um:ReadEntity() ) .. "\n" )
end
usermessage.Hook("my_message", my_message_hook)
In the item lua file.
and add
local rp = RecipientFilter() -- Grab a CRecipientFilter object
rp:AddAllPlayers() -- Send to all players!
umsg.Start("my_message", rp)
umsg.String( "Hello World! The answer to everything is")
umsg.Long( 42 )
umsg.Entity( ents.FindByClass("prop_physics")[1] )
umsg.End()
in another file in the gamemode?
No, it's the other way around and obviously you'd change it to your needs.
You should also learn of instances.
[url]http://wiki.garrysmod.com/?title=Client-Server_relationship_in_Lua[/url]
Basically the item is on the machine running the server, when it's used it will then send a message to the client's machine( with the usermessages ). The user's machine (the client) will read it and react on it. If you order the server itself to open a window it won't really do much, that kind of stuff has to be done per user on their machines.
um, Could you PLEASE Help me with this? I don't understand so much now.
Could you post the code/codes in pasterbin ?
Try this.
[lua]ITEM.Name = "Propaganda";
ITEM.Class = "propaganda";
ITEM.Description = "Propaganda from Resistances";
ITEM.Model = "models/props_junk/garbage_newspaper001a.mdl";
ITEM.Purchaseable = true;
ITEM.Price = 1;
ITEM.ItemGroup = 1;
function ITEM:Drop(ply)
end
function ITEM:Pickup(ply)
self:Remove();
end
function ITEM:UseItem(ply)
ply:SendLua( [[HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")]] )
end[/lua]
It's a shitty way of doing it, but I'm too lazy to use usermessages at the moment.
[QUOTE=Dlaor;17509531]Try this.
[lua]ITEM.Name = "Propaganda";
ITEM.Class = "propaganda";
ITEM.Description = "Propaganda from Resistances";
ITEM.Model = "models/props_junk/garbage_newspaper001a.mdl";
ITEM.Purchaseable = true;
ITEM.Price = 1;
ITEM.ItemGroup = 1;
function ITEM:Drop(ply)
end
function ITEM:Pickup(ply)
self:Remove();
end
function ITEM:UseItem(ply)
ply:SendLua( [[HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")]] )
end[/lua]
It's a shitty way of doing it, but I'm too lazy to use usermessages at the moment.[/QUOTE]
THX! It Works! :D But i got another problem now. I need a Close button so pp can close the window. also maybe if its possible. title.
Some thing along the lines of:
[lua]
local closeButton = vgui.Create("DButton")
closeButton:SetPos( 20, 20 )
closeButton:SetText( "Close" )
closeButton.DoClick = function()
HTMLTest:Remove()
closeButton:Remove()
end
[/lua]
:raise:
[QUOTE=Jamie Sharpe;17536304]Some thing along the lines of:
[lua]
local closeButton = vgui.Create("DButton")
closeButton:SetPos( 20, 20 )
closeButton:SetText( "Close" )
closeButton.DoClick = function()
HTMLTest:Remove()
closeButton:Remove()
end
[/lua]
:raise:[/QUOTE]
ITEM.Name = "Propaganda";
ITEM.Class = "propaganda";
ITEM.Description = "Propaganda from Resistances";
ITEM.Model = "models/props_junk/garbage_newspaper001a.mdl";
ITEM.Purchaseable = true;
ITEM.Price = 1;
ITEM.ItemGroup = 1;
function ITEM:Drop(ply)
end
function ITEM:Pickup(ply)
self:Remove();
end
function ITEM:UseItem(ply)
ply:SendLua( [[HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")]] )
local closeButton = vgui.Create("DButton")
closeButton:SetPos( 20, 20 )
closeButton:SetText( "Close" )
closeButton.DoClick = function()
HTMLTest:Remove()
closeButton:Remove()
end
end
Didn't work, No close button.
...usScript\gamemode\schemas/hl2rp/items/propaganda.lua:26: attempt to index global 'vgui' (a nil value)
Why not use a usermessage?
Place this in cl_init.lua
[lua]function htmlthing()
HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")
local closeButton = vgui.Create( "DButton", HTMLTest ) --parent it to the frame
closeButton:SetPos( 20, 20 ) -- I don't know the exact position but watev, if this doesn't appear, try doing to values your self.
closeButton:SetText( "Close" )
closeButton.DoClick = function()
HTMLTest:Remove()
closeButton:Remove()
end
end
usermessage.Hook( "HTML", htmlthing )[/lua]
in the function ITEM:UseItem(ply) do
[lua]
umsg.Start( "HTML", ply ) umsg.End() [/lua]
You did the close button again on serverside, that is why you're getting that error, anything VGUI should be done clientside( cl_init or what ever ).
[QUOTE=l3monm@ster;17547940]Why not use a usermessage?
Place this in cl_init.lua
[lua]function htmlthing()
HTMLTest = vgui.Create("HTML")
HTMLTest:SetPos(50,50)
HTMLTest:SetSize(ScrW() - 100, ScrH() - 100)
HTMLTest:OpenURL("http://www.garrysmod.com")
local closeButton = vgui.Create( "DButton", HTMLTest ) --parent it to the frame
closeButton:SetPos( 20, 20 ) -- I don't know the exact position but watev, if this doesn't appear, try doing to values your self.
closeButton:SetText( "Close" )
closeButton.DoClick = function()
HTMLTest:Remove()
closeButton:Remove()
end
end
usermessage.Hook( "HTML", htmlthing )[/lua]
in the function ITEM:UseItem(ply) do
[lua]
umsg.Start( "HTML", ply ) umsg.End() [/lua]
You did the close button again on serverside, that is why you're getting that error, anything VGUI should be done clientside( cl_init or what ever ).[/QUOTE]
Thanks!!
Sorry, you need to Log In to post a reply to this thread.