|
Seran Newbie
Joined: 21 Apr 2017 Posts: 8
|
Posted: Fri Apr 21, 2017 8:12 pm
GMCP bug for Room.Players |
When I get Room.Players from GMCP, the list seems to show every player I have encountered from every room I have been to, not just the ones in the current room. Is there a way to only see the players in the current room I'm in (after I've been to several other rooms)?
Room.AddPlayer and Room.RemovePlayer seem to have the same problem. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sat Apr 22, 2017 1:17 am |
Sounds like it might be something gameside with the variables not being cleared properly, before they send you updated information.
I hate to push it off, but this may be an issue for the admin on your game. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Seran Newbie
Joined: 21 Apr 2017 Posts: 8
|
Posted: Sat Apr 22, 2017 10:16 pm |
shalimar wrote: |
Sounds like it might be something gameside with the variables not being cleared properly, before they send you updated information.
I hate to push it off, but this may be an issue for the admin on your game. |
I checked with another player of the same game who uses a different client, they said they don't have this problem. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
|
|
|
Seran Newbie
Joined: 21 Apr 2017 Posts: 8
|
Posted: Sun Apr 23, 2017 1:40 pm |
It looks like the Room exits issue was fixed by Zugg 7 years ago. Although CMud caches GMCP data until something changes, however despite the caching, the non-Room.Player related data are always current and accurate. Room.Players, Room.AddPlayer and Room.RemovePlayer are no longer accurate once the player has been to more than one room, I would call that a bug. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Mon Apr 24, 2017 2:39 am |
The problem is that the GMCP spec doesn't have any way to tell the client which data should and shouldn't be cached, and so CMUD caches everything. If there's anything that you don't want to be cached, you need to handle those cases manually. Something like this should do the trick (might not work exactly as written, I haven't written code for CMUD in a few years, but gives you a general idea anyway):
Code: |
#var PlayersInRoom {}
#trigger {Room.Players} {PlayersInRoom = %gmcp.Room.Players;%gmcp.Room.Players = {}} "gmcp"
#trigger {Room.AddPlayer} {#additem PlayersInRoom %gmcp.Room.AddPlayer;%gmcp.Room.AddPlayer = {}} "gmcp"
#trigger {Room.RemovePlayer} {#loop %numitems(@PlayersInRoom) {#if (%db(%item(@PlayersInRoom, %i), "name") == %gmcp.Room.RemovePlayer) {#delnitem PlayersInRoom %i;#break}};%gmcp.Room.RemovePlayer = ""} "gmcp" |
|
|
|
|
Seran Newbie
Joined: 21 Apr 2017 Posts: 8
|
Posted: Sat Apr 29, 2017 11:01 pm |
Daern wrote: |
The problem is that the GMCP spec doesn't have any way to tell the client which data should and shouldn't be cached, and so CMUD caches everything. If there's anything that you don't want to be cached, you need to handle those cases manually. Something like this should do the trick (might not work exactly as written, I haven't written code for CMUD in a few years, but gives you a general idea anyway):
Code: |
#var PlayersInRoom {}
#trigger {Room.Players} {PlayersInRoom = %gmcp.Room.Players;%gmcp.Room.Players = {}} "gmcp"
#trigger {Room.AddPlayer} {#additem PlayersInRoom %gmcp.Room.AddPlayer;%gmcp.Room.AddPlayer = {}} "gmcp"
#trigger {Room.RemovePlayer} {#loop %numitems(@PlayersInRoom) {#if (%db(%item(@PlayersInRoom, %i), "name") == %gmcp.Room.RemovePlayer) {#delnitem PlayersInRoom %i;#break}};%gmcp.Room.RemovePlayer = ""} "gmcp" |
|
Thanks, that worked. Correct syntax for the triggers:
Code: |
#TRIGGER {Room.Players} {PlayersInRoom = %gmcp.Room.Players; #loopdb %gmcp.Room.Players {#delkey %gmcp.Room.Players %key}} "gmcp"
#TRIGGER {Room.AddPlayer} {#loopdb %gmcp.Room.AddPlayer { #addkey PlayersInRoom %key %val; #delkey %gmcp.Room.AddPlayer %key}} "gmcp"
#TRIGGER {Room.RemovePlayer} {#delkey PlayersInRoom %gmcp.Room.RemovePlayer} "gmcp"
|
Note:
1. The script does not work in Lua since zs.sys.gmcp is readonly and cannot be overwritten
2. In zscript, setting %gmcp.Room.Players = {} screws up the variable as CMUD must retain a reference to the original table elsewhere and will not update the new {}.
3. I have not bothered to reset Room.RemovePlayer for my game since it only shows the last player who left the room, not a list of players like Room.Players or Room.AddPlayer. |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Sun Apr 30, 2017 5:34 am |
Awesome, thanks for fixing it up :) I'll keep this post for future reference.
|
|
|
|
|
|