Kidd, is that all of the code? If so, you can't call vgui.Create instantly, try hooking it to Initialize.
Edit: Never mind for the question, didn't even realize there was another page. Try hooking it.
Works if I set up a concommand. Thanks for the help guys.
Hope I'm not posting in here too much, don't want to be greedy :v:
I had a round system but it failed to work (broken).
Does anybody have a round system that does this:
On round start, a 300 second countdown begins. The round can be forced to end if a certain team only has 1 player left in it. When this round ends, a 150 second break time begins. Players who were not in the round due to joining late will spawn here.
When the 150 second break timer ends, the 300 second countdown begins again.
I have been trying to do this all morning with no luck, so if anyone knows how to do anything here, please post! Many thanks.
I have a question on the net library.
I'm trying to send a table of data to the clients when a hook is called but I get an error saying the sendInfo function is nil. The tutorial on the wiki didn't show any good examples and I never used umsg before. So a good explanation would go a long way for me.
[lua]hook.Add("OnNPCKilled","Inform Murder Victims", sendInfo({"OnNPCKilled",victim, killer}))
util.AddNetworkString( "eventData" )
function sendInfo(tbl)
net.Start( "eventData" )
net.WriteTable(tbl)
net.Broadcast()
end[/lua]
[lua]
net.Receive( "eventData", addEvent )
function addEvent()
local tbl = net.ReadTable()
DermaListView:AddLine(tostring(os.date("%H:%M:%S")), myImage, tbl[2], tbl[2].." was killed by "..tbl[3],"123456789")
print("CALLED EVENT")
end
[/lua]
sendinfo has to be defined before the hook
[QUOTE=nick_9_8;37901735]Hope I'm not posting in here too much, don't want to be greedy :v:
I had a round system but it failed to work (broken).
Does anybody have a round system that does this:
On round start, a 300 second countdown begins. The round can be forced to end if a certain team only has 1 player left in it. When this round ends, a 150 second break time begins. Players who were not in the round due to joining late will spawn here.
When the 150 second break timer ends, the 300 second countdown begins again.
I have been trying to do this all morning with no luck, so if anyone knows how to do anything here, please post! Many thanks.[/QUOTE]
yes your in luck. Since fretta was deleted i had to write my own, its pretty simple to use.
shared:
[lua]
timeLeft = CreateConVar( "gmwc_roundtime", "300", FCVAR_NOTIFY )
preTime = CreateConVar( "gmwc_pretime", "10", FCVAR_NOTIFY )
endTime = CreateConVar( "gmwc_endtime", "10", FCVAR_NOTIFY )
reqPlayers = CreateConVar( "gmwc_minplayers", "2", FCVAR_NOTIFY )
local time
local shift
ROUND_PREP = -1
ROUND_ACTIVE = -2
ROUND_END = -3
ROUND_STATE = -4
PlayersReady = 0
local function AllPlayers()
local players = 0
for k,v in pairs(player.GetAll()) do
if ValidEntity(v) && v:Alive() && v:Team() < 3 then
players = players + 1
end
end
return players
end
function PreRound()
SetGlobalInt( "timeLeft", CurTime() + preTime:GetInt() ) // set the pretime
ROUND_STATE = ROUND_PREP
time = CurTime() + preTime:GetInt()
shift = ActiveRound
if timer.Exists("CheckForPlys") then
timer.Destroy("CheckForPlys")
timer.Create("CheckForPlys", 1, 0, function()
if AllPlayers() < reqPlayers:GetInt() then
EndGame()
end
end)
timer.Start("CheckForPlys")
end
hook.Call("GM_PreRound")
end
function ActiveRound()
SetGlobalInt( "timeLeft", CurTime() + timeLeft:GetInt() ) // set the round time
ROUND_STATE = ROUND_ACTIVE
time = CurTime() + timeLeft:GetInt()
shift = EndRound
hook.Call("GM_BeginRound")
end
function EndGame()
if timer.Exists("CheckForPlys") then
timer.Destroy("CheckForPlys")
end
ROUND_STATE = -4
timer.Create("CheckForPlys", 1, 0, function()
if AllPlayers() >= reqPlayers:GetInt() then
PreRound()
end
end)
timer.Start("CheckForPlys")
end
function EndRound()
SetGlobalInt( "timeLeft", CurTime() + endTime:GetInt() ) // set the end time
ROUND_STATE = ROUND_END
time = CurTime() + endTime:GetInt()
shift = PreRound
hook.Call("GM_EndRound")
end
timer.Create("CheckForPlys", 1, 0, function()
if ROUND_STATE == -4 && AllPlayers() >= reqPlayers:GetInt() then
PreRound()
end
end)
timer.Start("CheckForPlys")
function ShouldEndRound()
return false
end
function RoundSchedule()
if ShouldEndRound() then
EndRound()
end
if time && CurTime() >= time then
shift()
end
end
hook.Add("Think", "RoundSchedule", RoundSchedule)
function SetRound(rnd)
// Perform msgs about round change
if rnd == ROUND_PREP then
PreRound()
elseif rnd == ROUND_ACTIVE then
ActiveRound()
elseif rnd == ROUND_END then
EndRound()
end
end
function GetRound() return ROUND_STATE end
if SERVER then
end
if CLIENT then
local ply = LocalPlayer()
function msgActive()
LocalPlayer():ChatPrint("Round has begun:")
end
hook.Add("GM_BeginRound", "msgActive", msgActive)
function msgEnd()
LocalPlayer():ChatPrint("Round has ended:")
end
hook.Add("GM_EndRound", "msgEnd", msgEnd)
function msgPrep()
LocalPlayer():ChatPrint("Round has prepared:")
end
hook.Add("GM_PreRound", "msgPrep", msgPrep)
end
[/lua]
draw time like this (client):
[lua]
//CLOCK\\
local time = GetGlobalInt("timeLeft")
local aTime = time - CurTime()
local dTime = math.floor( aTime )
local Display = string.ToMinutesSeconds( dTime )
if GetRound() == -4 then
Display = "0:0"
end
draw.DrawText( Display, text_font, xpos, ypos, color )
[/lua]
and there ya go. set your convars and it will handle the rest. Also note that mine uses a minplayers convar, so the round wont begin until there are enough players, and the time will remain 0:0 until the round begins, i also included a few example hooks on how you would call functions on round changes. Good luck.
[QUOTE=M0dSe7en;37903131]yes your in luck. Since fretta was deleted i had to write my own, its pretty simple to use.
[lua] -code- [/lua]
[/QUOTE]
You're a champion. Many thanks.
haha no problem, it was a pain to test.
[editline]3rd October 2012[/editline]
OH, my bad replace ValidEntity() with IsValid(), I made an override so it will give you errors
-Snip- Late, didn't see last page
I am making a consolecommand to send money.
[code]
> for k, v in pairs(player.GetAll()) do print(v:UniqueID().." | "..v:Name().. " | "..v:GetNetworkedInt("Money")) end...
24024826 | »ßłâçĸƒįȓé« | 2000
] sendmoney 24024826 10
[gamemodes\skfm\gamemode\init.lua:117] attempt to index local 'rcv' (a boolean value)
[/code]
[lua]
local function SendMoney(ply, cmd, args)
local rcv = player.GetByUniqueID(tonumber(args[1]))
local amt = tonumber(args[2])
if amt < 1 then
return
elseif amt > ply:GetNetworkedInt("Money") then
return
else
rcv:SetNetworkedInt("Money", rcv:GetNetworkedInt("Money") + amt)
ply:SetNetworkedInt("Money", ply:GetNetworkedInt("Money") - amt)
rcv:Save()
ply:Save()
end
end
concommand.Add("sendmoney", SendMoney)
[/lua]
Make sure the receiver is a valid player.
[QUOTE=Leystryku;37869827]How stupid do you expect us to be ?
It's obvious that you are trying to code an aimbot, because you can't aim.
We have had enough problems with bots/hacks.
You should take another look at the lua pil.[/QUOTE]
i expect anyone to be stupid im just going thought every tut on [url]http://maurits.tv[/url] and try to break and perfect it to learn lua
not that im a little kid with his hand on an aimbot
[QUOTE=Chessnut;37904858]Make sure the receiver is a valid player.[/QUOTE]
If i do that it always returns false no matter what.
[lua]
function GM:Think()
surface.SetDrawColor(255,255,255)
surface.SetTexture(surface.GetTextureID("flmod/hijack_toggle/hijack_off"))
surface.DrawTexturedRect(25 + 10,ScrH() - 160,128,128)
end
[/lua]
What the hell.
It's not drawing either.
[QUOTE=Blackfire76;37905259]If i do that it always returns false no matter what.
[lua]
function GM:Think()
surface.SetDrawColor(255,255,255)
surface.SetTexture(surface.GetTextureID("flmod/hijack_toggle/hijack_off"))
surface.DrawTexturedRect(25 + 10,ScrH() - 160,128,128)
end
[/lua]
What the hell.
It's not drawing either.[/QUOTE]
Think is not a draw function. To make it support draw functions you need a 2D cam or a 3D2D cam.
[lua]
cam.Start2D()
--code
cam.End2D()
[/lua]
It is not recommended to do massive drawing in Think functions, though.
Use GM:HUDPaint() (or some other valid draw function) for this reason.
You do realise HUDPaint is called a lot faster than Think right?
you cant draw in think.
think is for thinking.
Draw/Paint/PaintOver/HUDPaint/RenderScreenspaceEffects is for painting
I'm having a problem in gmod 13:
the error message:
[code] 1. lua/includes/modules/hook.lua:83 (unknown)
Hook 'ChangeBuildMode' Failed: [gamemodes/test/gamemode/cl_init.lua:53] attempt to index global 'ply' (a nil value)
1. lua/includes/modules/hook.lua:83 (unknown)
[/code]
the problem area:
[lua]hook.Add( "Tick","ChangeBuildMode",function()
if ( ply:KeyPressed( IN_WALK )) then RunConsoleCommand("ChangeBuildMode") end
end)[/lua]
The rest of the code:
cl_init.lua:
[lua]AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
CurrentBuildMode = 1
local TestingForm = vgui.Create( "DForm", DermaPanel )
TestingForm:SetPos( 1060, 760 )
TestingForm:SetSize( 350, 60 )
TestingForm:SetSpacing( 10 )
TestingForm:SetName( "Current Sandbox Mode:" )
TestingForm.Paint = function()
surface.SetDrawColor( 255, 100, 15, 255 )
-- I draw a box here to show where the form is outlined
surface.DrawOutlinedRect( 0, 0, TestingForm:GetWide(), TestingForm:GetTall() )
end
local InfoPanel = vgui.Create( "DPanel", TestingForm )
InfoPanel:SetPos( 8 , 25 )
InfoPanel:SetSize( 120, 25)
InfoPanel.Paint = function()
surface.SetDrawColor( 50, 50, 50, 255 )
surface.DrawRect( 0, 0, InfoPanel:GetWide(), InfoPanel:GetTall() )
end
local BuildText = vgui.Create( "DLabel", InfoPanel )
BuildText:SetPos(15, 8)
BuildText:SetColor(Color(255,255,255,255))
BuildText:SetFont("default")
BuildText:SetText( "Build Mode" )
BuildText:SizeToContents()
local instructiontext = vgui.Create( "DLabel", TestingForm )
instructiontext:SetPos( 8, 52)
instructiontext:SetColor(Color(255,255,255,255))
instructiontext:SetFont("default")
instructiontext:SetText( "Press Alt (Walk) to switch" )
instructiontext:SizeToContents()
net.Receive( "ChangeBuildModeCl", function(len)
print( "received" )
if CurrentBuildMode == 1 then
CurrentBuildMode = 0
BuildText:SetText( "Fight Mode" )
elseif CurrentBuildMode == 0 then
CurrentBuildMode = 1
BuildText:SetText( "Build Mode" )
end
end )
hook.Add( "Tick","ChangeBuildMode",function()
if ( ply:KeyPressed( IN_WALK )) then RunConsoleCommand("ChangeBuildMode") end
end)[/lua]
init.lua:
[lua]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
local function PregameSetup()
util.AddNetworkString( "ChangeBuildModeCl" )
end
CurrentBuildMode = 1
local function SpawnWithWeapons(ply)
if CurrentBuildMode == 1 then
ply:RemoveAllItems()
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
ply:Give( "gmod_camera" )
return true
elseif CurrentBuildMode == 0 then
ply:Give( "weapon_crowbar" )
ply:Give( "weapon_physcannon")
ply:Give( "weapon_pistol" )
ply:Give( "weapon_357" )
ply:Give( "weapon_smg1" )
ply:Give( "weapon_ar2" )
ply:Give( "weapon_shotgun" )
ply:Give( "weapon_crossbow" )
ply:Give( "weapon_frag" )
ply:Give( "weapon_rpg" )
return true
end
end
local function ChangeBuildMode(ply)
net.Start( "ChangeBuildModeCl", ply )
net.Send(ply)
if CurrentBuildMode == 1 then
CurrentBuildMode = 0
ply:RemoveAllItems()
ply:Give( "weapon_crowbar" )
ply:Give( "weapon_physcannon")
ply:Give( "weapon_pistol" )
ply:Give( "weapon_357" )
ply:Give( "weapon_smg1" )
ply:Give( "weapon_ar2" )
ply:Give( "weapon_shotgun" )
ply:Give( "weapon_crossbow" )
ply:Give( "weapon_frag" )
ply:Give( "weapon_rpg" )
print("Build Mode changed to Fight")
elseif CurrentBuildMode == 0 then
CurrentBuildMode = 1
ply:RemoveAllItems()
ply:Give( "weapon_physgun" )
ply:Give( "gmod_tool" )
ply:Give( "gmod_camera" )
print("Build Mode changed to Build")
end
end
concommand.Add( "ChangeBuildMode", ChangeBuildMode )
hook.Add("PlayerLoadout", "Build Mode Special Weapon Spawns", SpawnWithWeapons)
hook.Add("Initialize", "Net String Precaching", PregameSetup)[/lua]
[QUOTE=Zyler;37907431]
the problem area:
[lua]hook.Add( "Tick","ChangeBuildMode",function()
if ( ply:KeyPressed( IN_WALK )) then RunConsoleCommand("ChangeBuildMode") end
end)[/lua][/QUOTE]
eek too much code to look through
so far every problem related to lua that i have seen recently is because people are trying to use variables that do NOT exist.
unless you have defined ply as a global (which is a stupid idea on the server) it will not exist.
also im pretty sure Tick is client side so just use LocalPlayer() instead of ply
Can someone give me a basic example on how net lib works? Show me what you would do serverside and clientside. Just need a small example. Like sending a table or whatever to the clients.
And how does receive work and how would I use a table or whatever that was sent.
I really want to learn to use net lib but kind of hard with a tutorial that is lacking on the wiki(unless I missed something.)
[QUOTE=Kidd;37910261]Can someone give me a basic example on how net lib works? Show me what you would do serverside and clientside. Just need a small example. Like sending a table or whatever to the clients.
And how does receive work and how would I use a table or whatever that was sent.
I really want to learn to use net lib but kind of hard with a tutorial that is lacking on the wiki(unless I missed something.)[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1b73.html[/url]
Would that help?
[QUOTE=Kidd;37910261]Can someone give me a basic example on how net lib works? Show me what you would do serverside and clientside. Just need a small example. Like sending a table or whatever to the clients.
And how does receive work and how would I use a table or whatever that was sent.
I really want to learn to use net lib but kind of hard with a tutorial that is lacking on the wiki(unless I missed something.)[/QUOTE]
[URL="http://wiki.garrysmod.com/page/Lua/Tutorials/Using_the_net_library"]http://wiki.garrysmod.com/page/Lua/Tutorials/Using_the_net_library[/URL]
serverside:
[lua]
util.AddNetworkString( "myMessage" )
function StartMessage(msg)
net.Start( "myMessage" )
net.WriteString(msg)
net.Send( pl )
end
[/lua]
client:
[lua]
net.Receive( "myMessage", function( length, client )
print( net.ReadString() )
end )
[/lua]
correct me if I'm wrong, i haven't used the net library.. yet, but it seems fairly simple to use.
I haven't done any Lua in a long time, and I want to get back into it. Is there any Lua bin website for Gmod13? Like the ones Foszor and Overv had a while back.
Also what's with the new wiki? It has almost no info and doesn't have a nice layout like the old one.
[QUOTE=CowThing;37910350]I haven't done any Lua in a long time, and I want to get back into it. Is there any Lua bin website for Gmod13? Like the ones Foszor and Overv had a while back.
Also what's with the new wiki? It has almost no info and doesn't have a nice layout like the old one.[/QUOTE]
your best bet is to install a gm13 SCRDS server, which includes all of the files of GM13, that's what i did
[QUOTE=Crap-Head;37910289][url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1b73.html[/url]
Would that help?[/QUOTE]
Thanks. I didn't think about checking the old wiki.
if you like kidd you can add me on steam and ill help you out :)
Anyone find out a way to fix the HTML.
whats wrong with it?
[QUOTE=G4MB!T;37913117]whats wrong with it?[/QUOTE]
Most MOTDs and such are blank now. Garry changed the libraries for HTML in an update as according to his blog.
after the html panel has been created, call UpdateHTMLMaterial() on the html element
What if it is OpenURL?
Will this work? [lua]local Admins = vgui.Create( "HTML")Admins:SetPos( 25, 50 )
Admins:SetSize( 250, 250 )
Admins:OpenURL("http://xenogamers.org/showthread.php?t=12333")
Admins:UpdateHTMLMaterial()[/lua]
Sorry, you need to Log In to post a reply to this thread.