LUA Help needed.

My code… is this correct gmod lua?

myName=“Bryce”
print( “Welcome aboard the cruise”…“MyName”…“We hope you enjoy!”

end

wanted to check

[editline]14th May 2014[/editline]

Oh… also… is this correct? ply:ConCommand( “Connect 192.168.1.225” )
if true then Connect()

end

Not quite; to concatenate a variable to a string, you end the string ( quote ), then use two periods … the variable and if that is it, leave it like that, but if you want to add another string or variable to it, double dots … string = open quote, variable = variable.

Here are some examples:

[lua]local _h = 100; // Assume we’re in HUDPaint and this is LocalPlayer( ):Health( );
local _a = 50; // Assume we’re in HUDPaint and this is LocalPlayer( ):Armor( );
local _w = “weapon_css_hk_usp”; // Assume we’re in HUDPaint and this is LocalPlayer( ):GetActiveWeapon( ):GetClass( ); and assume that LocalPlayer and the active weapon == IsValid,

print( "You’re holding " … _w ); // You’re holding weapon_css_hk_usp
print( “You’re holding " … _w … “!” ); // You’re holding weapon_css_hk_usp!
print( “Your health is at: " … _h … " and your armor is at: " … _a ); // Your health is at: 100 and your armor is at: 50
print( “Your health is at: " … _h … " and your armor is at: " … _a … “!” ); // Your health is at: 100 and your armor is at: 50!
print( _h … " is your current health!” ); // 100 is your current health!
print( _a … " is your current armor level!” ); // 50 is your current armor level!
print( _h … _a … _w ); // 10050weapon_css_hk_usp
print( _h … " " … _a … " " … _w ); // 100 50 weapon_css_hk_usp
print( “H: " … _h … " A:” … _a … " W:” … _w ); // H: 100 A: 50 W: weapon_css_hk_usp

LocalPlayer( ):ConCommand( “connect 10.0.0.2” );
[/lua]

Check out this thread for more help: http://forum.facepunch.com/showthread.php?t=1337945

  1. Capitalization matters.
  2. Variables don’t have to be in quotes.
  3. Parenthesis.
  4. end not needed if it’s not in a function.

myName="Bryce"
print( "Welcome aboard the cruise"..myName.."
We hope you enjoy!" ) -- 
 will move everything after it to the next line

  1. Correct console command is “connect” with a lowercase c.
  2. Is that in a function? Otherwise, it won’t work.
  3. Is Connect() a function?

Assuming you want to instantly redirect the player, use a PlayerConnect or PlayerInitialSpawn hook.


hook.Add( "PlayerConnect", "Redirect", function(ply) ply:ConCommand( "connect 192.168.1.225" ) end)