Hello, I am new to LUA and my code is having errors.
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
function GM:PlayerInitialSpawn( ply )
ply:SetGravity( 1 )
ply:SetWalkSpeed( 250 )
ply:StopSprinting()
ply:SetTeam( 1 )
end
function GM:PlayerSpawn( ply )
if ply:Team() == 1 then
ply:Give("weapons_357")
ply:SetModel("models/player/soldier_stripped*.mdl")
if ply:Team() == 2 then
ply:Give("weapons_357")
ply:SetModel("models/player/Kleiner.mdl")
if ply:Team() == 3 then
ply:Give("weapons_357")
ply:SetHealth(99999999)
ply:SetModel("models/player/gman_high.mdl")
end
function TeamT()
local RDM = math.random( 1, 2 )
if RDM == 1 then
ply:SetTeam( 1 )
elseif RDM == 2 then
ply:SetTeam( 2 )
end
Tea1 = team.NumPlayers( 1 )
Tea2 = team.NumPlayers( 2 )
if Tea1 > Tea2 then
ply:SetTeam( 2 )
elseif Tea2 > Tea1
then
ply:SetTeam( 1 )
end
//Console
concommand.Remove( "sv_cheats 1" )
end
I know I'm probably being stupid but I would greatly appreciate it if someone could correct it.
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
function GM:PlayerInitialSpawn( ply )
ply:SetGravity( 1 )
ply:SetWalkSpeed( 250 )
ply:SetTeam( 1 )
end
function GM:PlayerSpawn( ply )
if ply:Team() == 1 then
ply:Give("weapons_357")
ply:SetModel("models/player/soldier_stripped*.mdl")
end
if ply:Team() == 2 then
ply:Give("weapons_357")
ply:SetModel("models/player/Kleiner.mdl")
end
if ply:Team() == 3 then
ply:Give("weapons_357")
ply:SetHealth(99999999)
ply:SetModel("models/player/gman_high.mdl")
end
end
function TeamT()
local RDM = math.Round(math.random( 1, 2 ))
if RDM == 1 then
ply:SetTeam( 1 )
elseif RDM == 2 then
ply:SetTeam( 2 )
end
Tea1 = team.NumPlayers( 1 )
Tea2 = team.NumPlayers( 2 )
if Tea1 > Tea2 then
ply:SetTeam( 2 )
elseif Tea2 > Tea1 then
ply:SetTeam( 1 )
end
end
[/lua]
You didn't end a lot of the if statements and your probably not putting it in the right place.
Thank you, I can see where I went wrong.
A good tip to prevent your statments to go weird, always write the end (or else and end, or elseif, or whatever) directly after you write the if, so you got the statement done, then fill it with your code.
I am probably having the same problem here then.
[lua]
GM.Name = "GM13"
GM.Author = "N/A"
GM.Email = "N/A"
GM.Website = "N/A"
DeriveGamemode( "sandbox" )
function GM:Initialize()
self.BaseClass.Initialize( self )
//Teams
team.SetUp( 1, "Team1", Color(255,0,0))
team.SetUp( 2, "Team2", Color(0,0,255))
team.SetUp( 3, "Spec", Color(50,50,50))
end
//Models
util.PrecacheModel(models/player/Kleiner.mdl)
util.PrecacheModel(models/player/soldier_stripped*.mdl)
util.PrecacheModel(models/player/gman_high.mdl)
end
end
[/lua]
The last two ends aren't part of any function, statement or loop. Also you don't have quotes surrounding the models for util.PrecacheModel
Also I'm pretty sure you don't intend to end the function at line 15... Try this:
[lua]
GM.Name = "GM13"
GM.Author = "N/A"
GM.Email = "N/A"
GM.Website = "N/A"
DeriveGamemode( "sandbox" )
function GM:Initialize()
self.BaseClass.Initialize( self )
//Teams
team.SetUp( 1, "Team1", Color(255,0,0))
team.SetUp( 2, "Team2", Color(0,0,255))
team.SetUp( 3, "Spec", Color(50,50,50))
//Models
util.PrecacheModel(models/player/Kleiner.mdl)
util.PrecacheModel(models/player/soldier_stripped*.mdl)
util.PrecacheModel(models/player/gman_high.mdl)
end
[/lua]
Ok thank you. I think I get it now, you have to put end only when you are finished writing the whole function?
Yes and to end if statements, loops and such
[QUOTE=toby311;38601676]Ok thank you. I think I get it now, you have to put end only when you are finished writing the whole function?[/QUOTE]
Right, you can't write extra ends.
You use end to close functions, ifs and loops.
[url=http://www.lua.org/pil/5.html]Yes.[/url]
e: ninja'd
Still, read up on basic Lua syntax before starting on a gamemode — if [url=http://www.lua.org/pil/#online]Programming in Lua[/url] doesn't strike your fancy, there's always Google
Thanks for all the help so far! I am starting with a simple gamemode, I dont know what yet.
Ok so I watched a video about making a hud. When I went into gmod it came up with script errors, I am pretty sure this hud is made before gmod 13, can anyone tell me what is wrong with this please.
[lua]
function HUDHide(MyHud)
for k,v in pairs{"CHudHealth","CHudBattery"} do
if MyHud == v then return false end
end
end
hook.Add("HUDShouldDraw","HudHide",HUDHide)
function GM:HUDPaint()
self.BaseClass:HUDPaint()
local ply = LocalPlayer()
local HP = LocalPlayer():Health()
local Arm = LocalPlayer():Armor()
surface.CreateFont("ScoreboardText", 40, 250, false, false,"MyFont") //Name of font, size, intensity, AntiAliasing, ,Your Name for font
surface.SetTextColor(0 ,0 ,255, 255) //RGB, Transparency
surface.SetTextPos( 20, 20 )// x,y position
surface.SetFont( "MyFont" )// Name of your font
surface.DrawText( HP )
end
[/lua]
[QUOTE=toby311;38605979]it came up with script errors[/QUOTE]
And obviously you took note of these errors and pasted them in your post so people could help you with them, right?
Anyway, see this for converting scripts to gmod13 :
[url]https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit[/url]
Sorry, you need to Log In to post a reply to this thread.