ok, so basically I want to detect the playername to a player who triggers a function, so I later can print it out in chat.
I would like to save the playername in a variable or something like that, so I can for example do: chat.AddText(trigger.."ran the command!")
[lua]
concommand.Add("command",function(player)
local name = player:Nick() //Will store the nick player nick name into the var name
if SERVER then
player:SendLua("chat.AddText('"..name.." ran the command')") //In the case that you're running on a singleplayer game or a local MP this will be printed on the player
else
chat.AddText(name.." ran the command") //If this is intended for a dedicated server, then the client i'ts intended to run the command
end
end)
[/lua]
[QUOTE=gonzalolog;45195051][lua]
concommand.Add("command",function(player)
local name = player:Nick() //Will store the nick player nick name into the var name
if SERVER then
player:SendLua("chat.AddText('"..name.." ran the command')") //In the case that you're running on a singleplayer game or a local MP this will be printed on the player
else
chat.AddText(name.." ran the command") //If this is intended for a dedicated server, then the client i'ts intended to run the command
end
end)
[/lua][/QUOTE]
chat.AddText is clientside and concommand.Add is serverside, so your code won't really work. The client doesn't somehow run serverside code just because you're not playing singleplayer
[QUOTE=Coffeee;45195101]chat.AddText is clientside and concommand.Add is serverside, so your code won't really work. The client doesn't somehow run serverside code just because you're not playing singleplayer[/QUOTE]
[IMG]http://i.imgur.com/8Ggze7q.jpg[/IMG]
The client doesn't automatically become the client when playing a singleplayer game. The same thing can be achieved with:
[lua]
concommand.Add("command",function(player)
player:SendLua("chat.AddText('"..player:Nick().." ran the command')")
end)
[/lua]
(and then it being run serverside or shared)
(rate dumb and provide no actual input, ok)
Sorry, you need to Log In to post a reply to this thread.