What Lua function does one use when wanting to show a message to all players.
An event occurs for player1 (lost 10 units), gadget sends message to all players with "player1 has lost 10 units"
I thought it was Spring.SendMessage but I just tested it with no luck.
Anyone know?
Send message to all players from gadget
Moderator: Moderators
Re: Send message to all players from gadget
If you want it to just appear in the chat you could just use Spring.Echo. Not elegant but it will work.
Re: Send message to all players from gadget
Spring.SendMessage works and has the advantage over Spring.Echo that you can pass playernames with syntax such as <PLAYER0>
Here is short gadget as an exemple.
Here is short gadget as an exemple.
Re: Send message to all players from gadget
I've tried a these and it still doesn't work. Each player only sees their own announcements instead of everybody's.
I even tried Spring.SendMessageToPlayer which each playerID with the same outcome. Anyone know why?
I even tried Spring.SendMessageToPlayer which each playerID with the same outcome. Anyone know why?
Re: Send message to all players from gadget
can you pastebin your gadget code showing the only-to-one-player problem?
Re: Send message to all players from gadget
http://pastebin.com/Y0PPsGZg
These lines are responsible for the message process.
Using SendMessageToPlayer is my latest attempt.
I have also tried Echo and SendMessage with exactly the same results.
These lines are responsible for the message process.
Using SendMessageToPlayer is my latest attempt.
I have also tried Echo and SendMessage with exactly the same results.
Re: Send message to all players from gadget
Here's an example using the synced->unsynced method:
It's a little more code than if you were to just put the echo in the synced :UnitDestroyed callin, but the synced side of a gadget isn't the proper place for displaying information anyway as it can't do any drawing/display etc. Also the synced side of a gadget can't get player names.
You might know this already but gadgets run on every players PC, not the server, so messaging all players can be accomplished by just having the gadget message the local player (as Spring.Echo does).
Code: Select all
if gadgetHandler:IsSyncedCode() then
----------------------------------------------------------------
-- Synced
----------------------------------------------------------------
function gadget:UnitDestroyed(uID, uDefID, uTeam, aID, aDefID, aTeam)
SendToUnsynced('TeamLostAUnit', uTeam)
end
else
----------------------------------------------------------------
-- Unsynced
----------------------------------------------------------------
function gadget:RecvFromSynced(identifier, arg1, arg2, arg3, ...)
if identifier == 'TeamLostAUnit' then
local teamID = arg1
local _, playerID = Spring.GetTeamInfo(teamID)
if playerID then
local playerName = Spring.GetPlayerInfo(playerID)
Spring.Echo(string.format('%s lost a unit !', playerName))
end
end
end
end
You might know this already but gadgets run on every players PC, not the server, so messaging all players can be accomplished by just having the gadget message the local player (as Spring.Echo does).
Re: Send message to all players from gadget
Thanks for the replies.
I know how this all works, I have a fully function synced->unsynced gadget now. What I'm trying to do is make it so that every player is responsible for tracking their own deaths/kills and then sending a message to everyone with things like "player 1 got 100 kills" etc.
I could do it so that each player keeps track of everybody's kills and deaths and displays the info to themselves (using Echo). However, I thought it would be more efficient to make each player responsible for their own updates.
Does this make sense to you?
I know how this all works, I have a fully function synced->unsynced gadget now. What I'm trying to do is make it so that every player is responsible for tracking their own deaths/kills and then sending a message to everyone with things like "player 1 got 100 kills" etc.
I could do it so that each player keeps track of everybody's kills and deaths and displays the info to themselves (using Echo). However, I thought it would be more efficient to make each player responsible for their own updates.
Does this make sense to you?
Re: Send message to all players from gadget
Having the gadget work it out for everyone is better because it doesn't add any network traffic, which is more important than negligible CPU load.LEDZ wrote:Thanks for the replies.
I know how this all works, I have a fully function synced->unsynced gadget now. What I'm trying to do is make it so that every player is responsible for tracking their own deaths/kills and then sending a message to everyone with things like "player 1 got 100 kills" etc.
I could do it so that each player keeps track of everybody's kills and deaths and displays the info to themselves (using Echo). However, I thought it would be more efficient to make each player responsible for their own updates.
Does this make sense to you?
What exactly are you trying to do? Have players announce their kills? Show a scoreboard? Something else?
Re: Send message to all players from gadget
I've gone with SendCommands say bla bla now, it works ok.
Would the sending of messages contribute a lot to network traffic?
The widget tracks metal profit/loss from killing and losing units. It also tracks kills and deaths and announces certain milestones. I'll pastebin the code once I've tidied it up a bit.
Would the sending of messages contribute a lot to network traffic?
The widget tracks metal profit/loss from killing and losing units. It also tracks kills and deaths and announces certain milestones. I'll pastebin the code once I've tidied it up a bit.
Re: Send message to all players from gadget
It sorta can, <PLAYER0> <PLAYER1> <PLAYER2> get replaced by the player name when used in Spring.SendMessage (does not work with Spring.Echo)Niobium wrote:Also the synced side of a gadget can't get player names.
Re: Send message to all players from gadget
imo not worth it.LEDZ wrote:However, I thought it would be more efficient to make each player responsible for their own updates.
Does this make sense to you?
Just have one gadget that tracks all kills and send the count/score to all players. If you care about only counting kills that happend in a players LOS, you can check that too in a gadget.