I've been working with gmod lua for a while and I know a bit but some of this stuff I don't even know like:
-would this (function something[B]()[/B]) inside the parenthesis be what it is calling, like ply, k, v
-how would I set a score limit to win a round?
-wtf is a hook and how do I use it?
-is there an alternative to RunConsoleCommand and concommand? I'm looking for something people can't use in the middle of the game
I think this is all I need to know.
[QUOTE=Carmine3777;22890122]I've been working with gmod lua for a while and I know a bit but some of this stuff I don't even know like:
-would this (function something[B]()[/B]) inside the parenthesis be what it is calling, like ply, k, v
-how would I set a score limit to win a round?
-wtf is a hook and how do I use it?
-is there an alternative to RunConsoleCommand and concommand? I'm looking for something people can't use in the middle of the game
I think this is all I need to know.[/QUOTE]
[lua]
function something(ply,cmd,args) --1 Would need to run on a hook to check on tick or think
if ply:Frags() > 4 then ply:ChatPrint("You wont now get out") end --2
end
[/lua]
[lua]
hook.Add("Something","Blarg", function() end)
[/lua]
[lua]
CreateConVar("toggle_zoom","",FCVAR_CHEAT)
[/lua]
1: I think you mean arguments, and no.
2: Put code into the playerdeath hook.
3: [url]http://wiki.garrysmod.com/?title=Gamemode_Hooks[/url]
4: I don't get what you mean.
[QUOTE=Cubar;22890703]function something(ply,cmd,args) --1 Would need to run on a hook to check on tick or think
if ply:Frags() > 4 then ply:ChatPrint("You wont now get out") end --2
end
hook.Add("Something","Blarg", function() end)
CreateConVar("toggle_zoom","",FCVAR_CHEAT)
[/QUOTE]
could you explain #1 more clearly please, and #4, would I still be able to do:
[lua]
function myfunction()
if something = # then
concommand("kill")
end
end [/lua]
Er.. no.. for one, what is # going to be.
[code]
function myfunction( pl )
c = 1
f = c + 2
if ( f == 3 ) then
pl:ConCommand("Kill")
end
end
[/code]
oh yeah, the score is a team score though, so how would I do that?
[editline]10:20PM[/editline]
how would I use a math.random to set a player model? does it just have to be a number?
Wiki.
[QUOTE=SchumacherAlt;22892416]Wiki.[/QUOTE]
I barely understand the wiki, how do I make the math.random get a number from a table?
table.Random
[QUOTE=SchumacherAlt;22892527]table.Random[/QUOTE]
oh, thanks, what are some different arguments? preferably one for team.
[editline]11:03PM[/editline]
would this work?
[lua]function teammodels(ply)
USteam={}
USteam[1]=("afgan_soldier1.mdl")
USteam[2]=("afgan_soldier2.mdl")
USteam[3]=("afgan_soldier3.mdl")
if ply:Team == 1 then
ply:SetModel( "models/mw2guy/rus/gassoldier.mdl" )
elseif ply:Team == 2 then
ply:SetModel( "models/"..table.random(USteam))
end
end[/lua]
should, yeah.
[QUOTE=SchumacherAlt;22893539]should, yeah.[/QUOTE]
one more question, can you give me some different arguments, or just one for team please.
[QUOTE=Carmine3777;22893684]one more question, can you give me some different arguments, or just one for team please.[/QUOTE]
Use 1 table for each team
[lua]
function teammodels(ply)
Team1={}
Team1[1]=("team1_model1.mdl")
Team1[2]=("team1_model2.mdl")
Team1[3]=("team1_model3.mdl")
Team2={}
Team2[1]=("team2_model1.mdl")
Team2[2]=("team2_model2.mdl")
Team2[3]=("team2_model3.mdl")
if ply:Team() == 1 then -- Don't forget to add () to call the function, and not reference it as a variable
ply:SetModel( "models/"..table.random(Team1) )
elseif ply:Team() == 2 then
ply:SetModel( "models/"..table.random(Team2) )
end
end[/lua]
This should work, but this code could do with some simple improvements
[lua]
-- We only need to define these tables ONCE and not every time we want to set a random player model
local Team1={} -- Make the table local to only this script, so we don't pollute the global table
Team1[1]=("team1_model1.mdl")
Team1[2]=("team1_model2.mdl")
Team1[3]=("team1_model3.mdl")
local Team2={}
Team2[1]=("team2_model1.mdl")
Team2[2]=("team2_model2.mdl")
Team2[3]=("team2_model3.mdl")
function teammodels(ply)
if ply:Team() == 1 then
ply:SetModel( "models/"..table.random(Team1) )
elseif ply:Team() == 2 then
ply:SetModel( "models/"..table.random(Team2) )
end
end[/lua]
[QUOTE=Jcw87;22895492]Use 1 table for each team
function teammodels(ply)
Team1={}
Team1[1]=("team1_model1.mdl")
Team1[2]=("team1_model2.mdl")
Team1[3]=("team1_model3.mdl")
Team2={}
Team2[1]=("team2_model1.mdl")
Team2[2]=("team2_model2.mdl")
Team2[3]=("team2_model3.mdl")
if ply:Team() == 1 then -- Don't forget to add () to call the function, and not reference it as a variable
ply:SetModel( "models/"..table.random(Team1) )
elseif ply:Team() == 2 then
ply:SetModel( "models/"..table.random(Team2) )
end
end
This should work, but this code could do with some simple improvements
-- We only need to define these tables ONCE and not every time we want to set a random player model
local Team1={} -- Make the table local to only this script, so we don't pollute the global table
Team1[1]=("team1_model1.mdl")
Team1[2]=("team1_model2.mdl")
Team1[3]=("team1_model3.mdl")
local Team2={}
Team2[1]=("team2_model1.mdl")
Team2[2]=("team2_model2.mdl")
Team2[3]=("team2_model3.mdl")
function teammodels(ply)
if ply:Team() == 1 then
ply:SetModel( "models/"..table.random(Team1) )
elseif ply:Team() == 2 then
ply:SetModel( "models/"..table.random(Team2) )
end
end[/QUOTE]
thanks, but I was wondering that because of this:
[lua]function scorelimit(ply)
if ply:Frags() > 75 then
RunConsoleCommand("gamewin")
end
end[/lua]
I have to have the entire team's score to win the round
[editline]11:22AM[/editline]
never mind, wouldn't this work?
[lua]function scorelimit(ply)
if team.GetScore(1) > 75 then
RunConsoleCommand("gamewin")
end
elseif team.GetScore(2) > 75 then
RunConsoleCommand("gamewin")
end [/lua]
You need to move that end down below the elseif block.
[lua]function scorelimit(ply)
if team.GetScore(1) > 75 then
RunConsoleCommand("gamewin")
elseif team.GetScore(2) > 75 then
RunConsoleCommand("gamewin")
end
end [/lua]
Also you would have to be calling that function every time they score, or on think.
[QUOTE=Jo The Shmo;22903748]You need to move that end down below the elseif block.
function scorelimit(ply)
if team.GetScore(1) > 75 then
RunConsoleCommand("gamewin")
elseif team.GetScore(2) > 75 then
RunConsoleCommand("gamewin")
end
end
Also you would have to be calling that function every time they score, or on think.[/QUOTE]
oh yeah, I just copied the first one and forgot to move the end down. how would I use think then?