[DiscordArchive] Is there a way to fetch a valid player object across maps? It seems that when a player casts a spell
[DiscordArchive] Is there a way to fetch a valid player object across maps? It seems that when a player casts a spell
Archived author: Qeme • Posted: 2024-12-09T10:49:51.841000+00:00
Original source
Is there a way to fetch a valid player object across maps? It seems that when a player casts a spell and their target is on a different map, the server doesn't recognize the target or provide access to their Player object. For example, calling GetSelectedPlayer() or similar methods fails. How can I reliably fetch the target player object across maps? Is there an alternative approach or workaround to handle such cases?
Archived author: Nyeriah • Posted: 2024-12-09T11:03:25.758000+00:00
Original source
FindConnectedPlayer()
Archived author: walkline • Posted: 2024-12-09T11:30:51.918000+00:00
Original source
If you want to access a player from another map while you are in the map thread, make sure you understand what you are doing, as it can lead to a race condition.
Archived author: Qeme • Posted: 2024-12-09T11:52:25.539000+00:00
Original source
Thank you both
Archived author: Qeme • Posted: 2024-12-09T12:16:10.552000+00:00
Original source
Yeah I still can't get the object across maps. To use FindConnectedPlayer I need their GUID, I can't get the target GUID because there is no target object when the player is on a different map.
I guess I'm having the same issue as with the .appear command. If you are not on the same map, you'll need to provide the players name.
https://github.com/azerothcore/azerothco...c.cpp#L737
Archived author: Qeme • Posted: 2024-12-09T12:19:36.156000+00:00
Original source
Basically, I am trying to cast a spell on a party member, when that party member is the players target, regardless of range or map.
Archived author: Qeme • Posted: 2024-12-09T12:20:44.419000+00:00
Original source
I can't do it with a spell script either, because the target is invalid if they're not on the same map.
Archived author: Takenbacon • Posted: 2024-12-09T13:20:57.335000+00:00
Original source
You can hook into the set_selection opcode which is called when you change your target, this also gives you the ObjectGuid of said target as well.
As already mentioned, this opcode and most other ways you'd accomplish this is going to be unsafe for the servers threading model - you may run into occasional undefined behavior (including crashes).
Archived author: Takenbacon • Posted: 2024-12-09T13:22:56.814000+00:00
Original source
A relatively simple fix would be to change the processing status of the set selection opcode to process_threadsafe