• How to find Owner's Nickname?
    10 replies, posted
So I need to find the nickname for the player who is using my SWEP... I have tried the following [code] print("Username is: "..self.Owner:Nick()) [/code] [code] print("Username is: "..Nick(self.Owner)) [/code] [code] print("Username is: "..Player:Nick()) [/code] They all led to errors :( Please help thanks
What are the errors?
self.Owner has to be inside a SWEP:Function()
This is the real code I try to use [code] player.GetAll( chat.AddText(Color(255,0,0), "(GLOBAL ADMIN MESSAGE FROM "..self.Owner:Nick()..") " ,Color(0,0,255),Text:GetValue() ) ) [/code] And the error is... [code] [ERROR] addons/omg_weapons/lua/weapons/admin_essentials/shared.lua:60: attempt to index global 'self' (a nil value) 1. DoClick - addons/omg_weapons/lua/weapons/admin_essentials/shared.lua:60 2. unknown - lua/vgui/dlabel.lua:206 [/code]
You have to iterate over the table player.GetAll() returns [lua]for k, v in pairs( player.GetAll() ) do // stuff end[/lua]
[QUOTE=OMGOMG132;42746211]This is the real code I try to use [code] player.GetAll( chat.AddText(Color(255,0,0), "(GLOBAL ADMIN MESSAGE FROM "..self.Owner:Nick()..") " ,Color(0,0,255),Text:GetValue() ) ) [/code] And the error is... [code] [ERROR] addons/omg_weapons/lua/weapons/admin_essentials/shared.lua:60: attempt to index global 'self' (a nil value) 1. DoClick - addons/omg_weapons/lua/weapons/admin_essentials/shared.lua:60 2. unknown - lua/vgui/dlabel.lua:206 [/code][/QUOTE] I bet you are trying to use 'self' inside a custom function that doesn't start with SWEP:funcNameHere() Post the whole function, then we can do something about it.
[code] function window() if CLIENT then local TextSilent = vgui.Create( "DTextEntry", Form ) TextSilent:SetPos( 16, 58 ) TextSilent:SetTall( 20 ) TextSilent:SetWide( 210 ) TextSilent:SetEnterAllowed( true ) TextSilent.OnEnter = function() end local SubmitSilent = vgui.Create( "DButton" ) SubmitSilent:SetParent( Form ) -- Set parent to our "DermaPanel" SubmitSilent:SetText( "Execute Silent" ) SubmitSilent:SetPos( 232, 58 ) SubmitSilent:SetSize( 90, 20 ) SubmitSilent.DoClick = function () player.GetAll( chat.AddText(Color(255,0,0), "(GLOBAL ADMIN MESSAGE) ",Color(0,100,255),TextSilent:GetValue() ) ) Form:SetVisible( false ) end end end [/code] I took care of the net and what not already so dont worry
player.GetAll returns a table, not run the function on everybody.
[QUOTE=Chessnut;42748380]player.GetAll returns a table, not run the function on everybody.[/QUOTE] ops. Well how do i run it on everybody?
You need to iterate over the table of players and then you can use them to do other things such as [Arbitrary Player]:ChatPrint( [text] ). For example.. (serverside code) [lua] for _, ply in pairs( player.GetAll() ) do ply:ChatPrint( "This prints something to every players chat" ); end [/lua] chat.AddText is a clientside function, meaning it cannot be executed on the server and must be executed on a players computer. If you want to do something that effects other clients from a client, the server must be used as a medium to do so. You can see if a function is clientside or serverside by using the garry's mod wiki.
[QUOTE=zzaacckk;42749440]You need to iterate over the table of players and then you can use them to do other things such as [Arbitrary Player]:ChatPrint( [text] ). For example.. (serverside code) [lua] for _, ply in pairs( player.GetAll() ) do ply:ChatPrint( "This prints something to every players chat" ); end [/lua] chat.AddText is a clientside function, meaning it cannot be executed on the server and must be executed on a players computer. If you want to do something that effects other clients from a client, the server must be used as a medium to do so. You can see if a function is clientside or serverside by using the garry's mod wiki.[/QUOTE] alright
Sorry, you need to Log In to post a reply to this thread.