• Lua Errors?
    6 replies, posted
I have been staring at this code all day and I cannot find the lua errors! [ERROR] addons/join and leave message/lua/autorun/cl_player.lua:6: unexpected symbol near ',' 1. unknown - addons/join and leave message/lua/autorun/cl_player.lua:0 [CODE]// Coded by Sweepyoface // Connect function player_spawn( ply ) local name1 = ply:ReadString() local nickteamcolour1 = team.GetColor(ply:ReadShort()) chat.AddText( Color( 255, 0, 255 ), " [ ", Color( 48, 230, 200 ), " ImagineGaming", Color( 255, 0, 255 ), " ]", nickteamcolour1, name1, Color( 0, 183, 255 ), " has joined the server." ), steamid surface.PlaySound( "garrysmod/save_load1.wav" ) end usermessage.Hook("player_spawn", player_spawn) // Disconnect function player_disconnect( ply ) local name3 = ply:ReadString() local nickteamcolour3 = team.GetColor(ply:ReadShort()) local steamid = ply:SteamID() chat.AddText( Color( 255, 0, 255 ), " [ ", Color( 48, 230, 200 ), " ImagineGaming", Color( 255, 0, 255 ), " ]", nickteamcolour1, name1, Color( 0, 183, 255 ), " has disconnected from the server." ), steamid surface.PlaySound( "garrysmod/save_load2.wav" ) end usermessage.Hook("player_disconnect", player_disconnect)[/CODE] [url]http://puu.sh/8kRJX.png[/url]
[code]chat.AddText( Color( 255, 0, 255 ), " [ ", Color([/code] [code]" [ ", Color([/code]
At the end your chat.AddText you're closing off the arguements with a ')' and then you're putting steamid at the end, which is what's causing the error. To fix it, simply change [CODE] chat.AddText( Color( 255, 0, 255 ), " [ ", Color( 48, 230, 200 ), " ImagineGaming", Color( 255, 0, 255 ), " ]", nickteamcolour1, name1, Color( 0, 183, 255 ), " has joined the server." ), steamid [/CODE] to [CODE] chat.AddText( Color( 255, 0, 255 ), " [ ", Color( 48, 230, 200 ), " ImagineGaming", Color( 255, 0, 255 ), " ]", nickteamcolour1, name1, Color( 0, 183, 255 ), " has joined the server." , steamid ) [/CODE] edit: Also please ignore Kaillus, he's a dunce and has no idea what he's talking about
It's because you put "steamid" outside of the chat.AddText.
thanks guys [editline]24th April 2014[/editline] More errors: [CODE]// Coded by Sweepyoface // Connect function player_spawn( ply ) local name1 = ply:ReadString() local nickteamcolour1 = team.GetColor(ply:ReadShort()) local steamid = ply:SteamID() chat.AddText( Color( 255, 0, 255 ), "[", Color( 48, 230, 200 ), "ImagineGaming", Color( 255, 0, 255 ), "] ", nickteamcolour1, name1, Color( 0, 183, 255 ), " has joined the server.", steamid ) surface.PlaySound( "garrysmod/save_load1.wav" ) end usermessage.Hook("player_spawn", player_spawn) // Disconnect function player_disconnect( ply ) local name3 = ply:ReadString() local nickteamcolour3 = team.GetColor(ply:ReadShort()) local steamid = ply:SteamID() chat.AddText( Color( 255, 0, 255 ), "[", Color( 48, 230, 200 ), "ImagineGaming", Color( 255, 0, 255 ), "] ", nickteamcolour1, name1, Color( 0, 183, 255 ), " has disconnected from the server.", steamid ) surface.PlaySound( "garrysmod/save_load2.wav" ) end usermessage.Hook("player_disconnect", player_disconnect)[/CODE] [ERROR] addons/join and leave message/lua/autorun/cl_player.lua:6: attempt to call method 'SteamID' (a nil value) 1. Function - addons/join and leave message/lua/autorun/cl_player.lua:6 2. unknown - lua/includes/modules/usermessage.lua:87
[quote] local name1 = ply:ReadString() local nickteamcolour1 = team.GetColor(ply:ReadShort()) local steamid = ply:SteamID() [/quote] The usermessage data argument is not a player, so using the SteamID function is not going to work. You either need to send the steamID as well, or it'd probably be easier just to write the player/entindex by itself and get the name/team color/steamID clientside. Also you may want to look into using net messages instead. [url]http://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Look at these: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/game_event_listeners.lua.html[/url] I'm not sure when you're calling the user-message, but it may be the problem, or the chat.AddText may be trying to use SteamID as a table / Color. Use the pattern: chat.AddText( Color, String [, Color, String]* ); - * = 0-many You're using Color, String, String right at the end. Additionally you're using ply as the network getter by using ReadString, so that may be the umsg getter, you may need to pass it as an additional string.
Sorry, you need to Log In to post a reply to this thread.