[QUOTE=Science;39266923]That would make complete sense. Im an idiot.
Thank you.
[editline]18th January 2013[/editline]
I now tried
print("Start Run") function OpenMenu() local DermaPanel = vgui.Create("DFrame") DermaPanel:SetPos( 100, 100 ) DermaPanel:SetSize( 300, 200 ) DermaPanel:SetTitle( data ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() end OpenMenu() print("End Run")
Only to return
[code]] lua_openscript menu.lua
Running script menu.lua...
Start Run
[ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value)
1. OpenMenu - lua/menu.lua:7
2. unknown - lua/menu.lua:18
Unhandled Lua Refresh: [NAME:lua/menu.lua] [TYPE:!UNKNOWN]
] lua_openscript menu.lua
Running script menu.lua...
Start Run
[ERROR] lua/menu.lua:7: attempt to index global 'vgui' (a nil value)
1. OpenMenu - lua/menu.lua:7
2. unknown - lua/menu.lua:18
] lua_openscript_cl menu.lua
[/code][/QUOTE]
[B]lua_openscript_cl[/B]
[I]fairy you mother fucker[/I]
Hello guys I'm currently trying to make it so when ever a certain team wins they get 150 points on the gamemode.
These are the hooks here. It should work, but for some reason it's only giving the person who got the kill the points instead of the whole team.
[CODE]hook.Add("PlayerDeath", "PS_StalkerPlayerDeath", function( victim, _, attacker )
if (#player.GetAll() > 4) then
if ( victim:Team() == TEAM_HUMAN and attacker:IsPlayer() and attacker:Team() == TEAM_STALKER ) then
attacker:PS_GivePoints( 10 )
attacker:PrintMessage( HUD_PRINTTALK, "10 points for killing an innocent human." )
end
if ( victim:Team() == TEAM_STALKER and attacker:IsPlayer() and attacker:Team() == TEAM_HUMAN ) then
attacker:PS_GivePoints( 150 )
attacker:PrintMessage( HUD_PRINTTALK, "150 points for killing the stalker!" )
end
end
end)
hook.Add("RoundEnd", "PS_StalkerRoundEnd", function( team )
if (#player.GetAll() > 4) then
for _, v in pairs( player.GetAll() ) do
if v:Team() == team then
v:PS_GivePoints( 150 )
v:PrintMessage( HUD_PRINTTALK, "150 points for winning that round." )
end
end
end
end)[/CODE]
I don't get any errors or anything so I'm assuming it's just set up wrong.
RoundEnd doesn't output the winning team.
You'd have to check who is alive and who isn't I believe.
[QUOTE=fairy;39267500]RoundEnd doesn't output the winning team.
You'd have to check who is alive and who isn't I believe.[/QUOTE]
Could you help me a bit with that? I'm new to lua :L
[QUOTE=Hyper Iguana;39266362]If you want both a Vector and an Angle in your variable, you'll have to use a table.
[lua]
carpos = {
[1] = {
vec = Vector(2086.941650, 843.956665, -131.968750),
ang = Angle(0,180,0)
}
}
local car = ents.Create("yourcar")
car:SetPos(carpos[1].vec)
car:SetAngle(carpos[1].ang)
car:Spawn()
car:Activate()
[/lua][/QUOTE]
For some reason it gives error for the SetAngle to be nil, here is the code.
[LUA]carpos = {
[1] = {
vec = Vector(2086.941650, 843.956665, -131.968750),
ang = Angle(0, -180, 0)
}
}
local function chevroletred( ply ) -- CHEAP CAR
if not ply:CanAfford(5000) then
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else
ply:AddMoney(-5000)
chevroletred= ents.Create("prop_vehicle_jeep")
chevroletred:SetModel("models/tdmcars/spark.mdl")
chevroletred:SetColor(Color(255,0,0,255))
chevroletred:SetKeyValue("vehiclescript", "scripts/vehicles/TDMCars/spark.txt")
chevroletred:SetPos(carpos[1].vec)
chevroletred:SetAngle(carpos[1].ang)
chevroletred:Spawn()
chevroletred:Activate()
end
end
concommand.Add("_chevroletcar1", chevroletred)[/LUA]
[URL="http://www.facepunch.com/showthread.php?t=1240237"]http://www.facepunch.com/showthread.php?t=1240237[/URL]
Didn't want to bump twice
[QUOTE=Vilusia;39267635]Could you help me a bit with that? I'm new to lua :L[/QUOTE]
[lua]
hook.Add("RoundEnd", "imgay", function()
local t = {}
for k,v in pairs(player.GetAll()) do
if v:Alive() and v:Health > 0 then
if not(table.HasValue(t, v:Team()) then
table.insert(t, v:Team())
end
end
if #t > 1 then return end
for k,v in pairs(player.GetAll()) do
if t[v:Team()] or table.HasValue(t, v:Team()) then
-- add points
end
end
end)[/lua]
that's really sloppy and probably wouldnt work tbh
[editline]18th January 2013[/editline]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf975.html[/url]
[QUOTE=fairy;39267828][lua]
hook.Add("RoundEnd", "imgay", function()
local t = {}
for k,v in pairs(player.GetAll()) do
if v:Alive() and v:Health > 0 then
if not(table.HasValue(t, v:Team()) then
table.insert(t, v:Team())
end
end
if #t > 1 then return end
for k,v in pairs(player.GetAll()) do
if t[v:Team()] or table.HasValue(t, v:Team()) then
-- add points
end
end
end)[/lua]
that's really sloppy and probably wouldnt work tbh
[editline]18th January 2013[/editline]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf975.html[/url][/QUOTE]
Yeah that didnt work, thanks for trying though :S
[QUOTE=_Undefined;39267260][B]lua_openscript_cl[/B]
[I]fairy you mother fucker[/I][/QUOTE]
Tried it many times. Nothing is returned.
[lua]
TOOL.Category = "Render"
TOOL.Name = "Get Material"
TOOL.Command = nil
TOOL.ConfigName = ""
matty = "models/wireframe"
function TOOL:RightClick( trace )
matty = trace.HitTexture
Msg(matty.."\n")
return true
end
function TOOL:LeftClick( trace )
if !( trace.Entity && -- Hit an entity
trace.Entity:IsValid() && -- And the entity is valid
trace.Entity:EntIndex() != 0 -- And isn't worldspawn
) then return end
Msg(matty.."\n")
trace.Entity:SetMaterial( matty )
return true
end
[/lua]
Why doesn't this work? It's purpose is to right click to grab the material of anything... Which works. Then left click to set the material on a prop. But the result is that it sets the prop back to its normal texture while printing in console that it has the right material?
Edit:
Apparently it needs to be a model texture... A texture on a brush cannot be applied to a model? Is there anyway around this?
[QUOTE=Science;39268157]Tried it many times. Nothing is returned.[/QUOTE]
[code]sv_allowcslua 1[/code]
[QUOTE=DJarthas;39267654]For some reason it gives error for the SetAngle to be nil, here is the code.
[LUA]carpos = {
[1] = {
vec = Vector(2086.941650, 843.956665, -131.968750),
ang = Angle(0, -180, 0)
}
}
local function chevroletred( ply ) -- CHEAP CAR
if not ply:CanAfford(5000) then
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.cant_afford, "car")) return "" else
ply:AddMoney(-5000)
chevroletred= ents.Create("prop_vehicle_jeep")
chevroletred:SetModel("models/tdmcars/spark.mdl")
chevroletred:SetColor(Color(255,0,0,255))
chevroletred:SetKeyValue("vehiclescript", "scripts/vehicles/TDMCars/spark.txt")
chevroletred:SetPos(carpos[1].vec)
chevroletred:SetAngle(carpos[1].ang)
chevroletred:Spawn()
chevroletred:Activate()
end
end
concommand.Add("_chevroletcar1", chevroletred)[/LUA][/QUOTE]
use this instead
[lua]chevroletred:SetAngles(carpos[1].ang)[/lua]
[QUOTE=Hyper Iguana;39268190][code]sv_allowcslua 1[/code]
use this instead
[lua]chevroletred:SetAngles(carpos[1].ang)[/lua][/QUOTE]
You sir.
Are a god send.
Can anyone link me to some documentation on how to create an HTTP request in LUA? I don't know a lot about LUA but I understand that it differs greatly between each setup, so it might run the same in GMod.
A POST request would be ideal, but I'll happily settle for GET. I also need it to return the HTML from the webpage
[QUOTE=Orgy;39271950]Can anyone link me to some documentation on how to create an HTTP request in LUA? I don't know a lot about LUA but I understand that it differs greatly between each setup, so it might run the same in GMod.
A POST request would be ideal, but I'll happily settle for GET. I also need it to return the HTML from the webpage[/QUOTE]
[url]http://wiki.garrysmod.com/page/http[/url]
[QUOTE=Orgy;39271950]Can anyone link me to some documentation on how to create an HTTP request in LUA? I don't know a lot about LUA but I understand that it differs greatly between each setup, so it might run the same in GMod.
A POST request would be ideal, but I'll happily settle for GET. I also need it to return the HTML from the webpage[/QUOTE]
1[img]http://i.imgur.com/7YSFQ1X.png[/img]
2[img]http://i.imgur.com/H9pzH0C.png[/img]
3[img]http://i.imgur.com/33Ore9p.png[/img]
Right. I'm an idiot. Gotcha.
Thanks, guys.
[editline]18th January 2013[/editline]
This is going to be dumb, but any chance you could also give a small example of using it? I'm not sure how onSuccess works.
[QUOTE=Orgy;39272115]Right. I'm an idiot. Gotcha.
Thanks, guys.
[editline]18th January 2013[/editline]
This is going to be dumb, but any chance you could also give a small example of using it? I'm not sure how onSuccess works.[/QUOTE]
[lua]
http.Fetch("http://google.com",
function onSuccess(body, length, headers, returncode)
print("Message returned with HTTP Code: "..returncode)
print("Contents:"..body)
end,
function onFailure(returncode)
print("Page returned error code: "..returncode)
end
)
[/lua]
[QUOTE=Hyper Iguana;39272454][lua]
http.Fetch("http://google.com",
function onSuccess(body, length, headers, returncode)
print("Message returned with HTTP Code: "..returncode)
print("Contents:"..body)
end,
function onFailure(returncode)
print("Page returned error code: "..returncode)
end
)
[/lua][/QUOTE]
Ah, alright. I understand now. Thanks, man.
Hey,
Anyone know whats up with this?
[CODE]
runconcommand.Add( "This", Function )
for k,v in pairs(player.GetAll()) do
if v:KeyReleased( KEY_G ) then
v:ConCommand("This")
end
end
[/CODE]
the command "This" is connected to a function above, but this is the part that I am having trouble with. For some reason when pressing G. It just won't work. Any suggestions guys?
Next question: say I hook into PlayerSay and do an action based on what they say. How can I prevent the message from going to everyone's screen? Would returning something be enough to stop that? (I'm basing this assumption on "Returning the text, even the original text, will stop this from being called in any other hooks.")
return ""
[QUOTE=.\\Shadow};39273117]return ""[/QUOTE]
Excellent. Thanks, a lot!
[editline]18th January 2013[/editline]
[QUOTE=Hyper Iguana;39272454][lua]
http.Fetch("http://google.com",
function onSuccess(body, length, headers, returncode)
print("Message returned with HTTP Code: "..returncode)
print("Contents:"..body)
end,
function onFailure(returncode)
print("Page returned error code: "..returncode)
end
)
[/lua][/QUOTE]
error: `(' expected;
last token read: `onSuccess'
[QUOTE=Orgy;39273159]Excellent. Thanks, a lot!
[editline]18th January 2013[/editline]
error: `(' expected;
last token read: `onSuccess'[/QUOTE]
I never worked with it so my mistake. I tested it this time though so it should work.
[lua]
http.Fetch("http://google.com",
function(body, length, headers, returncode)
print("Message returned with HTTP Code: "..returncode)
print("Contents:"..body)
end,
function(returncode)
print("Page returned error code: "..returncode)
end
)
[/lua]
[QUOTE=Hyper Iguana;39273310]I never worked with it so my mistake. I tested it this time though so it should work.
[lua]
http.Fetch("http://google.com",
function(body, length, headers, returncode)
print("Message returned with HTTP Code: "..returncode)
print("Contents:"..body)
end,
function(returncode)
print("Page returned error code: "..returncode)
end
)
[/lua][/QUOTE]
ah okay. that makes sense, too.
no script error now until I trigger it.
[code]
[ERROR] lua/includes/util.lua:184: attempt to index local 'object' (a number value)
1. IsValid - lua/includes/util.lua:184
2. unknown - lua/includes/modules/hook.lua:90[/code]
Thanks for all your help thus far.
That sounds like a hook is erroring (possibly running IsValid on a number?)
[QUOTE=pilot;39272765]Hey,
Anyone know whats up with this?
[CODE]
runconcommand.Add( "This", Function )
for k,v in pairs(player.GetAll()) do
if v:KeyReleased( KEY_G ) then
v:ConCommand("This")
end
end
[/CODE]
the command "This" is connected to a function above, but this is the part that I am having trouble with. For some reason when pressing G. It just won't work. Any suggestions guys?[/QUOTE]
>runconcommand.Add
[url]http://wiki.garrysmod.com/page/Libraries/concommand/Add[/url]
[QUOTE=Banana Lord.;39273404]That sounds like a hook is erroring (possibly running IsValid on a number?)[/QUOTE]
Indeed. Didn't realize I couldn't use 0 as the second argument in hook.Add. I've seen it used in examples, why wouldn't it work for me?
Oh well, I changed it to a string and it worked.
Thanks!
[url]http://wiki.garrysmod.com/page/gui[/url]
What happened to [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2c41.html]OpenURL[/url]?
[HR][/HR]
Also,
I've asked this 3 times in the past 5 days with [b]no response what-so-ever[/b].
Does anyone know how I can change the color of the background in a [url=http://wiki.garrysmod.com/page/Lua/Tutorials/VGUI/DCollapsibleCategory]DCollapsibleCategory[/url]?
It's some weird color of blue by default. Is there a way to change it without making a skin?
[QUOTE=fairy;39273471][url]http://wiki.garrysmod.com/page/gui[/url]
What happened to [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2c41.html]OpenURL[/url]?
[HR][/HR]
Also,
I've asked this 3 times in the past 5 days with [b]no response what-so-ever[/b].
Does anyone know how I can change the color of the background in a [url=http://wiki.garrysmod.com/page/Lua/Tutorials/VGUI/DCollapsibleCategory]DCollapsibleCategory[/url]?
It's some weird color of blue by default. Is there a way to change it without making a skin?[/QUOTE]
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index5b3b.html[/url]
?
[QUOTE=fairy;39273408]>runconcommand.Add
[url]http://wiki.garrysmod.com/page/Libraries/concommand/Add[/url][/QUOTE]
That was a mistake I put on Facepunch.
FIX:
[CODE]
concommand.Add( "This", Function )
for k,v in pairs(player.GetAll()) do
if v:KeyReleased( KEY_G ) then
v:ConCommand("This")
end
end[/CODE]
Although it is still broken.
Sorry, you need to Log In to post a reply to this thread.