Noob questions...

Hi, I’m very new to Lua coding (obviously) and I’m trying to make an RPG type gamemode. Please explain clearly to me what to change so that I can learn from my mistakes :slight_smile:

CURRENT PROBLEMS:

  1. I spawn with no weapons
  2. My player model is invisible
  3. My “different” classes are not at all different
  4. More of a question: How do you make it so that a variable changes whenever you kill another player? I’m trying to make it so that you get experience whenever you kill a player on another team.

Thanks.

cl_init.lua:

[lua]include( ‘shared.lua’ )

function set_team()

local frame = vgui.Create( “DFrame” )
frame:SetPos( ScrW() / 2, ScrH() / 2 )
frame:SetSize( 200, 210 )
frame:SetTitle( “Change Team” )
frame:SetVisible( true )
frame:SetDraggable( false )
frame:ShowCloseButton( true )
frame:MakePopup()

team_1 = vgui.Create( “DButton”, frame )
team_1:SetPos( frame:GetTall() / 4, 30 )
team_1:SetSize( 100, 25 )
team_1:SetText( “Combine” )
team_1.DoClick = function()
RunConsoleCommand( “team_1” )
end

team_2 = vgui.Create( “DButton”, frame )
team_2:SetPos( frame:GetTall() / 4, 60 )
team_2:SetSize( 100, 25 )
team_2:SetText( “Zombie” )
team_2.DoClick = function()
RunConsoleCommand( “team_2” )
end

team_3 = vgui.Create( “DButton”, frame )
team_3:SetPos( frame:GetTall() / 4, 90 )
team_3:SetSize( 100, 25 )
team_3:SetText( “Rebel” )
team_3.DoClick = function()
RunConsoleCommand( “team_3” )
end

team_4 = vgui.Create( “DButton”, frame )
team_4:SetPos( frame:GetTall() / 4, 120 )
team_4:SetSize( 100, 25 )
team_4:SetText( “Admin” )
team_4.DoClick = function()
if ply:IsAdmin() then
RunConsoleCommand( “team_4” )
end
end

end

concommand.Add( “team_menu”, set_team )[/lua]

init.lua:

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

function GM:PlayerInitialSpawn( ply )
RunConsoleCommand( “team_menu” )

if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome admin "…ply:Nick() )
else
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome "…ply:Nick() )
end

end

function GM:PlayerSetModel( ply )

if ply:Team() == 1 then

ply:SetModel( "models/player/combine_soldier.mdl" )

elseif ply:Team() == 2 then

ply:SetModel( "models/player/zombiefast.mdl" )

elseif ply:Team() == 3 then

ply:SetModel( "models/player/riot.mdl" )

elseif ply:Team() == 4 then

ply:SetModel( "models/player/gman_high.mdl" )

end

end

function GM:PlayerSpawn( ply )
ply:SetGravity( 0.90 )

if ply:Team() == 1 then

ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 375 )

elseif ply:Team() == 2 then

ply:SetMaxHealth( 150, true )
ply:SetWalkSpeed( 375 )
ply:SetRunSpeed( 450 )

elseif ply:Team() == 3 then

ply:SetMaxHealth( 75, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 400 )

elseif ply:Team() == 4 then

ply:SetMaxHealth( 1000, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 525 )

end

end

function GM:PlayerLoadout( ply )
ply:StripWeapons()
ply:RemoveAllAmmo()

if ply:Team() == 1 then

ply:GiveAmmo( 100, "ar2" )

ply:Give( "weapon_ar2" )
ply:Give( "weapon_crowbar" )

elseif ply:Team() == 2 then

ply:Give( "weapon_real_zps_zombieclaws" )

elseif ply:Team() == 3 then

ply:GiveAmmo( 256, "pistol" )
ply:Give( "weapon_pistol" )
ply:Give( "weapon_crowbar" )

elseif ply:Team() == 4 then

ply:GiveAmmo( 256, "pistol" )
ply:GiveAmmo( 256, "smg1" )
ply:GiveAmmo( 5, "grenade" )
ply:GiveAmmo( 32, "xbowbolt" )
ply:GiveAmmo( 64, "buckshot" )
ply:GiveAmmo( 32, "357" )
ply:GiveAmmo( 100, "ar2" )
ply:GiveAmmo( 6, "ar2altfire" )

ply:Give( "weapon_pistol" )
ply:Give( "weapon_smg1" )
ply:Give( "weapon_frag" )
ply:Give( "weapon_crossbow" )
ply:Give( "weapon_shotgun" )
ply:Give( "weapon_357" )
ply:Give( "weapon_ar2" )
ply:Give( "weapon_physgun" )
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_crowbar" )
ply:Give( "weapon_rpg" )

end

end

function team_1( ply )
ply:SetTeam( 1 )
ply:Spawn()
end

function team_2( ply )
ply:SetTeam( 2 )
ply:Spawn()
end

function team_3( ply )
ply:SetTeam( 3 )
ply:Spawn()
end

function team_4( ply )
ply:SetTeam( 4 )
ply:Spawn()
end

concommand.Add( “team_1”, team_1 )
concommand.Add( “team_2”, team_2 )
concommand.Add( “team_3”, team_3 )
if ply:IsAdmin() then
concommand.Add( “team_4”, team_4 )
end[/lua]

shared.lua:

[lua]GM.Name = “RPGMod”
GM.Author = “ZOMG”
GM.Email = “N/A”
GM.Website = “N/A”

team.SetUp( 1, “Combine”, Color( 0, 0, 255, 255 ) )
team.SetUp( 2, “Zombie”, Color( 225, 0, 0 , 225 ) )
team.SetUp( 3, “Rebel”, Color( 0, 255, 0, 255 ) )
team.SetUp( 4, “Admin”, Color( 0, 255, 255, 255 ) )[/lua]

Try adding the code in php tags ie [ php ] [ /php ] like this while asking, it shows it much nicer


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )

function GM:PlayerInitialSpawn( ply )

RunConsoleCommand( "team_menu" )

if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome admin "..ply:Nick )
else
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome "..ply:Nick )
end

end


function GM:PlayerSetModel( ply )

if ply:Team() == 1 then

ply:SetModel( "models/player/combine_soldier.mdl" )

elseif ply:Team() == 2 then

ply:SetModel( "models/player/zombiefast.mdl" )

elseif ply:Team() == 3 then

ply:SetModel( "models/player/riot.mdl" )

elseif ply:Team() == 4 then

ply:SetModel( "models/player/gman_high.mdl" )
end

end



function GM:PlayerSpawn( ply )

ply:SetGravity( 0.90 )

if ply:Team() == 1 then

ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 375 )

elseif ply:Team() == 2 then

ply:SetMaxHealth( 150, true )
ply:SetWalkSpeed( 375 )
ply:SetRunSpeed( 450 )

elseif ply:Team() == 3 then

ply:SetMaxHealth( 75, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 400 )

elseif ply:Team() == 4 then

ply:SetMaxHealth( 1000, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 525 )

end

end



function GM:PlayerLoadout( ply )

ply:StripWeapons()
ply:RemoveAllAmmo()

if ply:Team() == 1 then

ply:Give( "weapon_ar2" )
ply:GiveAmmo( 100, "ar2" )
ply:Give( "weapon_crowbar" )

elseif ply:Team() == 2 then

ply:Give( "weapon_real_zps_zombieclaws" )

elseif ply:Team() == 3 then

ply:Give( "weapon_pistol" )
ply:GiveAmmo( 256, "pistol" )
ply:Give( "weapon_crowbar" )

elseif ply:Team() == 4 then

ply:Give( "weapon_pistol" )
ply:GiveAmmo( 256, "pistol" )
ply:Give( "weapon_smg1" )
ply:GiveAmmo( 256, "smg1" )
ply:Give( "weapon_frag" )
ply:GiveAmmo( 5, "grenade" )
ply:Give( "weapon_crossbow" )
ply:GiveAmmo( 32, "xbowbolt" )
ply:Give( "weapon_shotgun" )
ply:GiveAmmo( 64, "buckshot" )
ply:Give( "weapon_357" )
ply:GiveAmmo( 32, "357" )
ply:Give( "weapon_ar2" )
ply:GiveAmmo( 100, "ar2" )
ply:GiveAmmo( 6, "ar2altfire" )
ply:Give( "weapon_physgun" )
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_crowbar" )
ply:Give( "weapon_rpg" )

end

end


function team_1( ply )
ply:SetTeam( 1 )
ply:Spawn()
end

function team_2( ply )
ply:SetTeam( 2 )
ply:Spawn()
end

function team_3( ply ) 
ply:SetTeam( 3 )
ply:Spawn()
end 

function team_4( ply ) 
ply:SetTeam( 4 )
ply:Spawn()
end 


concommand.Add( "team_1", team_1 )
concommand.Add( "team_2", team_2 )
concommand.Add( "team_3", team_3 )
if ply:IsAdmin() then
concommand.Add( "team_4", team_4 )
end

Here is the tabbed code.

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

function GM:PlayerInitialSpawn( ply )
RunConsoleCommand( “team_menu” )

if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome admin "…ply:Nick )
else
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome "…ply:Nick )
end
end

function GM:PlayerSetModel( ply )
if ply:Team() == 1 then
ply:SetModel( “models/player/combine_soldier.mdl” )
elseif ply:Team() == 2 then
ply:SetModel( “models/player/zombiefast.mdl” )
elseif ply:Team() == 3 then
ply:SetModel( “models/player/riot.mdl” )
elseif ply:Team() == 4 then
ply:SetModel( “models/player/gman_high.mdl” )
end
end

function GM:PlayerSpawn( ply )
ply:SetGravity( 0.90 )

if ply:Team() == 1 then
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 375 )
elseif ply:Team() == 2 then
ply:SetMaxHealth( 150, true )
ply:SetWalkSpeed( 375 )
ply:SetRunSpeed( 450 )
elseif ply:Team() == 3 then
ply:SetMaxHealth( 75, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 400 )
elseif ply:Team() == 4 then
ply:SetMaxHealth( 1000, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 525 )
end
end

function GM:PlayerLoadout( ply )
ply:StripWeapons()
ply:RemoveAllAmmo()

if ply:Team() == 1 then
ply:GiveAmmo( 100, “ar2” )
ply:Give( “weapon_ar2” )
ply:Give( “weapon_crowbar” )
elseif ply:Team() == 2 then
ply:Give( “weapon_real_zps_zombieclaws” )
elseif ply:Team() == 3 then
ply:Give( “weapon_pistol” )
ply:GiveAmmo( 256, “pistol” )
ply:Give( “weapon_crowbar” )
elseif ply:Team() == 4 then
ply:GiveAmmo( 256, “pistol” )
ply:GiveAmmo( 256, “smg1” )
ply:GiveAmmo( 5, “grenade” )
ply:GiveAmmo( 32, “xbowbolt” )
ply:GiveAmmo( 64, “buckshot” )
ply:GiveAmmo( 32, “357” )
ply:GiveAmmo( 100, “ar2” )
ply:GiveAmmo( 6, “ar2altfire” )

	ply:Give( "weapon_pistol" )
	ply:Give( "weapon_smg1" )
	ply:Give( "weapon_frag" )
	ply:Give( "weapon_crossbow" )
	ply:Give( "weapon_shotgun" )
	ply:Give( "weapon_357" )
	ply:Give( "weapon_ar2" )
	ply:Give( "weapon_physgun" )
	ply:Give( "weapon_physcannon" )
	ply:Give( "weapon_crowbar" )
	ply:Give( "weapon_rpg" )
end

end

function team_1( ply )
ply:SetTeam( 1 )
ply:Spawn()
end

function team_2( ply )
ply:SetTeam( 2 )
ply:Spawn()
end

function team_3( ply )
ply:SetTeam( 3 )
ply:Spawn()
end

function team_4( ply )
ply:SetTeam( 4 )
ply:Spawn()
end
concommand.Add( “team_1”, team_1 )
concommand.Add( “team_2”, team_2 )
concommand.Add( “team_3”, team_3 )
if ply:IsAdmin() then
concommand.Add( “team_4”, team_4 )
end[/lua]

Try checking your console for any errors first, and paste the codes of the other files. (cl_init.lua, shared.lua, etc) Those files could be causing the problem too.

Umm yeah, I couldn’t read that for some reason. Anyways, I added the two other files to the first post.

Why use php when we have [noparse][lua][/lua][/noparse]?

-snip-

Ok, I changed it to [lua]

I also fixed a bit by adding brackets after ply:Nick

[editline]10:01AM[/editline]

What’s snip mean? Oh yeah, I’ll be gone for the weekend BTW.

If people write something that was wrong, or they want removed - then they edit out what they said with a -snip-

Can anyone figure out what’s wrong with the code? I can’t find anything wrong except for the Nick() thing but I fixed that and it still doesn’t work.

Fixed
[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

function GM:PlayerInitialSpawn( ply )
ply:ConCommand( “team_menu” )

if ply:IsAdmin() then
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome admin "…ply:Nick() ) – Added missing Parentheses on the ply:Nick
else
ply:PrintMessage( HUD_PRINTTALK, "RPGMOD: Welcome "…ply:Nick() ) – Added missing Parentheses on the ply:Nick
end
end

function GM:PlayerSetModel( ply )
if ply:Team() == 1 then
ply:SetModel( “models/player/combine_soldier.mdl” )
elseif ply:Team() == 2 then
ply:SetModel( “models/player/zombiefast.mdl” )
elseif ply:Team() == 3 then
ply:SetModel( “models/player/riot.mdl” )
elseif ply:Team() == 4 then
ply:SetModel( “models/player/gman_high.mdl” )
end
end

function GM:PlayerSpawn( ply )
ply:SetGravity( 0.90 )

if ply:Team() == 1 then
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 375 )
elseif ply:Team() == 2 then
ply:SetMaxHealth( 150, true )
ply:SetWalkSpeed( 375 )
ply:SetRunSpeed( 450 )
elseif ply:Team() == 3 then
ply:SetMaxHealth( 75, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 400 )
elseif ply:Team() == 4 then
ply:SetMaxHealth( 1000, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 525 )
end
end

function GM:PlayerLoadout( ply )
ply:StripWeapons()
ply:RemoveAllAmmo()

if ply:Team() == 1 then
ply:GiveAmmo( 100, “ar2” )
ply:Give( “weapon_ar2” )
ply:Give( “weapon_crowbar” )
elseif ply:Team() == 2 then
ply:Give( “weapon_real_zps_zombieclaws” )
elseif ply:Team() == 3 then
ply:Give( “weapon_pistol” )
ply:GiveAmmo( 256, “pistol” )
ply:Give( “weapon_crowbar” )
elseif ply:Team() == 4 then
ply:GiveAmmo( 256, “pistol” )
ply:GiveAmmo( 256, “smg1” )
ply:GiveAmmo( 5, “grenade” )
ply:GiveAmmo( 32, “xbowbolt” )
ply:GiveAmmo( 64, “buckshot” )
ply:GiveAmmo( 32, “357” )
ply:GiveAmmo( 100, “ar2” )
ply:GiveAmmo( 6, “ar2altfire” )

	ply:Give( "weapon_pistol" )
	ply:Give( "weapon_smg1" )
	ply:Give( "weapon_frag" )
	ply:Give( "weapon_crossbow" )
	ply:Give( "weapon_shotgun" )
	ply:Give( "weapon_357" )
	ply:Give( "weapon_ar2" )
	ply:Give( "weapon_physgun" )
	ply:Give( "weapon_physcannon" )
	ply:Give( "weapon_crowbar" )
	ply:Give( "weapon_rpg" )
end

end

function team_1( ply )
ply:SetTeam( 1 )
ply:Spawn()
end

function team_2( ply )
ply:SetTeam( 2 )
ply:Spawn()
end

function team_3( ply )
ply:SetTeam( 3 )
ply:Spawn()
end

function team_4( ply )
if ply:IsAdmin() then – check if the player is admin
ply:SetTeam( 4 )
ply:Spawn()
else
ply:ChatPrint(“Pick another team please”)
ply:ConCommand( “team_menu”)
end
end
concommand.Add( “team_1”, team_1 )
concommand.Add( “team_2”, team_2 )
concommand.Add( “team_3”, team_3 )
concommand.Add( “team_4”, team_4 )[/lua]

The indentation is still pretty hideous.

Who cares people can code how they like to code so get the hell out of here.

Better showing a better example. You know, conform to the best style rather than giving them bad habits.

You hurt me… emotionally.

[editline]02:21PM[/editline]

Seriously though, you need to show examples with good coding practises so they don’t pick up bad habits.

Why are you being so harsh. Maker is just trying to help people and is very good at it so why dont you get the hell out of here?

I already got the Nick() problem but thanks for the admin team part. But I still have the weapons and model problems. No matter what team I’m on, I spawn with no weapons, 100 HP, same walk and run speeds and and if I kill myself, there is no body (meaning the models don’t work).

You need to update the model, and remove PlayerLoadOut and place it player spawn.

Shut up.

Thank you but I truly am a fail at coding… please explain to me how to update the model.

Also how would I create a simple RPG level up system?

Steelwatch I’m trying to figure out the same thing, I was using this guide:

That will help. It also uses SQLite for permanent storage of values (so if players come back they will have monez!)

Ok i coded you an xp when you get the xp you gain a lvl ect, if you want the script i will need your steam acc name so i can add you and send you it, sent you a pm.