• Error with PrintMessage in DarkRP
    2 replies, posted
Hello community, Ive just coded this script to get a random player for a GiveAWay or something but if i want to run this on my server its keeps getting errors. Lua File: [CODE]concommand.Add( "getrandom", getrandom ) function getrandom (ply) if table.HasValue({"superadmin", "admin"}, ply:GetNWString("usergroup")) then local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom1 ) end end function getrandom1 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom2 ) end function getrandom2 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom3 ) end function getrandom3 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom4 ) end function getrandom4 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom5 ) end function getrandom5 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom6 ) end function getrandom6 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom7 ) end function getrandom7 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom8 ) end function getrandom8 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom9 ) end function getrandom9 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( atlaschat, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom10 ) end function getrandom10 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandom11 ) end function getrandom11 ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "<c=255,150,0>Der Gewinner wird rausgesucht:</c> <hsv> " .. ply:Nick() .. "</hsv>" ) timer.Simple( 0.5, getrandomlast ) end function getrandomlast ( ) local rply = math.random(1, #player.GetAll()) local ply = player.GetAll()[rply] PrintMessage( HUD_PRINTCENTER, "---------------------------------------------" ) PrintMessage( HUD_PRINTCENTER, "-" ) PrintMessage( HUD_PRINTCENTER, "<c=255,150,0> Der Gewinner der Verlosung ist: </c>" ) PrintMessage( HUD_PRINTCENTER, "<hsv> " .. ply:Nick() .. " </hsv>" ) PrintMessage( HUD_PRINTCENTER, "-" ) PrintMessage( HUD_PRINTCENTER, "---------------------------------------------" ) end[/CODE] Error: [CODE] [ERROR] lua/autorun/rand.lua:7: attempt to call method 'PrintMessage' (a nil value) 1. unknown - lua/autorun/rand.lua:7 2. unknown - lua/includes/modules/concommand.lua:54 [/CODE]
My eyes burn when i see the code :rollout: Google "for loop" and understand how you can make your code 900% better.
for i = 1, 11 do getrandom() end and PrintMessage is a serverside function. It will only work in the server realm, not shared nor client.
Sorry, you need to Log In to post a reply to this thread.