How do I get the player who wrote anything, in the OnPlayerChat hook?
just adding player to the hook doesn't work:
--------------------------Code:function PLUGIN:OnPlayerChat(arg, player) print("[" .. player.displayName .. "]: " .. arg) end
I also think that simply using the arg variable here wouldn't work like this, would it?
Does it work the same way as the way to use in commands?
message = tostring(arg[0]) for example?
Solved Getting player in the OnPlayerChat hook (Lua)
Discussion in 'Rust Development' started by LaserHydra, Apr 21, 2015.
-
Code:
local player = arg.connection.player
-
-
Its a ConsoleSystem.Arg
http://docs.oxidemod.org/#player-hooks -
I found this but im not sure if it is what im searching for:
-
Wulf Community Admin
-
Thanks
[DOUBLEPOST=1429627451][/DOUBLEPOST]Okay that works fine thanks, but I can't get it to stop the original message from being in the chat.
Code:function PLUGIN:OnPlayerChat(arg, player) local message = arg:GetString(0, "text") local player = arg.connection.player print("[" .. player.displayName .. "]: " .. message) return end
---------
And also, is it possible to get the player icon and use it with rust.BroadcastChat?
- would need that for my Player Talk plugin ^^ -
You need to get player as BasePlayer, cause arg.connection.player returns MonoBehavior
-
player = BasePlayer? or arg.BasePlayer? or arg.connection.BasePlayer
anyway however I do it, it does not work. -
-
-
The answer to how to cancel the default chat can be found in the docs. A hint: returning nothing in lua means you returning null
For the player icon: The icon is simply pulled by the steamID. The syntax for that can also be found in the docs. -
these?
http://docs.oxidemod.org
[DOUBLEPOST=1429643563][/DOUBLEPOST]Okay I found the way to get the picture but I wasn't able to fix that return yet
[DOUBLEPOST=1429644130][/DOUBLEPOST]Nevermind, I got it. #JustUnderstoodWhatYourHintMent...
Code:return ""