• player.GetAll() Causing issues?
    5 replies, posted
I am trying to create a script that find s a random player. I have been having problems with player.GetAll() recently and am wondering If I am just being an idiot somewhere... [CODE]function ScareRandom() PrintMessage(HUD_PRINTTALK, "ScareTimerRan") local victim = table.Random(player.GetAll()) PrintMessage(HUD_PRINTTALK,"Victim chosen: "..victim) local scares = {1,2} local scarechoice = table.Random(scares) PrintMessage(HUD_PRINTTALK,"Scare chosen: "..scarechoice) if(scarechoice == 1)then dropWeapon(victim) end end timer.Create("ScareRandomly", 10, 0, ScareRandom) scaredvoicesMale = {"vo/npc/male01/help01.wav", "vo/npc/male01/moan01.wav", "vo/npc/male01/no01.wav", "vo/npc/male01/no02.wav", "vo/npc/male01/ohno.wav", "vo/npc/male01/uhoh.wav", "vo/npc/male01/wetrustedyou01.wav", "vo/npc/male01/wetrustedyou02.wav"} function dropWeapon(victim) victim:StripWeapons() victim:EmitSound(table.Random(scaredvoicesMale)) end[/CODE] It stops printing after "ScareTimerRan" -What could be the issue?
Because it is throwing an error - attempt to concatenate a userdata value. I think you meant to do this: [code]PrintMessage( HUD_PRINTTALK, "Victim chosen: " .. victim:Nick( ) )[/code]
Tabs help tremendously: [lua]if ( SERVER ) then // This doesn't need to be global local scaredvoicesMale = { "vo/npc/male01/help01.wav"; "vo/npc/male01/moan01.wav"; "vo/npc/male01/no01.wav"; "vo/npc/male01/no02.wav"; "vo/npc/male01/ohno.wav"; "vo/npc/male01/uhoh.wav"; "vo/npc/male01/wetrustedyou01.wav"; "vo/npc/male01/wetrustedyou02.wav"; }; function dropWeapon( victim ) victim:StripWeapons( ); victim:EmitSound( table.Random( scaredvoicesMale ), 100, 100 ); -- Audio volume needed end function ScareRandom( ) PrintMessage( HUD_PRINTTALK, "ScareTimerRan" ); local victim = table.Random( player.GetAll( ) ); PrintMessage( HUD_PRINTTALK, "Victim chosen: " .. ( IsValid( victim ) && victim:Nick( ) || "NO_NAME" ) ); -- Ternary operation to ensure no errors local scarechoice = math.random( 1, 2 ); -- No need to do table.Random when math.random uses whole numbers... PrintMessage( HUD_PRINTTALK,"Scare chosen: " .. scarechoice ); if ( scarechoice == 1 ) then dropWeapon( victim ); end end timer.Create( "ScareRandomly", 5, 5, ScareRandom ); end[/lua] few issues here and there. [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/ternary_operations.lua.html[/url]
Ah Thank you everyone... I wasn't able to use NotePad++ and that really threw me off. Thanks!
Why can't you use it??? Enable GMod Lexer in addons, restart NP++ twice, close it, pop this in %appdata%/notepad++/addons/config/ [url]https://dl.dropboxusercontent.com/u/26074909/notepadpp_highlighting/GmodLua.xml[/url] And you'll have the most up to highlighting date file. Also, please mark this thread solved in the upper left corner to avoid confusion :-)
Oh no I meant I was using a device that didn't have it. I have all of that on my pc. Thanks though!
Sorry, you need to Log In to post a reply to this thread.