• Funny Error
    5 replies, posted
Trying to make a player play a laugh sound when then type "lol" in chat -snip- cause tis mine' Got this in console: [code]My_GM/gamemode/init.lua:69: attempt to index global 'havealol' (a nil value)[/code] Any Suggestions as to how to fix this?
What is line 69 of init.lua?
I put it in a comment for you >:| function havealol( ply, arg ) -- line 69
[QUOTE=101kl;20264723]I put it in a comment for you >:| function havealol( ply, arg ) -- line 69[/QUOTE] Hang on a moment chuck, testing this on my server. [editline]08:55[/editline] I changed it a bit... I have this in a "Lol.lua" file: [lua]// Table the lol sounds. local LOLSounds = { // Table all the laughing sounds. { "vo/citadel/br_laugh", ".wav", 1, 1 }, { "vo/eli_lab/al_laugh", ".wav", 1, 2 }, { "vo/npc/barney/ba_laugh", ".wav", 1, 4 }, { "vo/ravenholm/madlaugh", ".wav", 1, 4 } } // Function called on PlayerChat. function DoSoundChat( pl, arg ) // Randomize based on the number in LOLSounds (so 4). local soundplay = LOLSounds[ math.random( #LOLSounds ) ]; // Get the sound id (basically take a random number from the table (1,1, 1,2, 1,4, 1,4) // This is used because the sounds have multiple numbers. local soundid = math.random( soundplay[ 3 ], soundplay[ 4 ] ); // Then get the actually sound to play. local sound = soundplay[ 1 ]; // If the soundid's are less than 10 then we only need one 0. if ( soundid < 10 ) then // Setup the sound variable. sound = sound .. "0" .. soundid; else // Setup the sound variable. sound = sound .. soundid; end // Add the soundplay table we want. sound = sound .. soundplay[ 2 ]; // Precache and emit the sound with default values. util.PrecacheSound( sound ); pl:EmitSound( sound, 100, 100 ); end[/lua] Then in my Commands.lua file I have: [lua]// Add the hook for players talking. hook.Add( "PlayerSay", "SF.ChatCommand", function( pl, arg ) // If "lol" are the first words of the said string. if ( string.find( arg, "lol" ) == 1 ) then // Run. DoSoundChat( pl, arg ); end end );[/lua]
-snip- [editline]09:09AM[/editline] Working now, thanks anyway elf.
[QUOTE=101kl;20265041]-snip- [editline]09:09AM[/editline] Working now, thanks anyway elf.[/QUOTE] No problem chap.
Sorry, you need to Log In to post a reply to this thread.