AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved How to recache spawn points? (https://forums.alliedmods.net/showthread.php?t=346011)

damage220 02-06-2024 14:52

How to recache spawn points?
 
In my FFA plugin I created a set of virtual spawn points, I mean they do not have an entity assigned to. In player spawn event I teleport the player to random virtual spawn point. It works but I am curious if it can be done using real spawn points.

My plugin is hot swappable and therefore default entities should be replaced with FFA ones, with the ability to revert these changes multiple times. I can easily remove default spawn points, but I cannot add new ones.

I did several tests and I found out that such entities should be created in early timing only, like in plugin_precache. It looks like there is some caching mechanism to create a tree of entities, with "info_player_deathmatch" and "info_player_start" classes, to store their indexes.

But if I have to remove entities, they will no longer work once I restore them back. Is there a function I can call to "cache" those entities like the engine does after plugin_precache? Or is there only teleport option? Maybe I can somehow disable spawn entities by assigning a player to it so that engine would not consider it for spawn?

fysiks 02-06-2024 23:06

Re: How to recache spawn points?
 
The engine doesn't "cache" entities (I don't think it actually caches anything) but the client does cache files (models, sounds, etc.). Even if you were able to enable and disable spawn points, are you sure that they would even be random? In the game I play, Day of Defeat, they are definitely not random so certain spawn points would only get used if all of the others are already taken (have a player that spawned but hasn't moved yet).

damage220 02-07-2024 13:53

Re: How to recache spawn points?
 
Quote:

Originally Posted by fysiks (Post 2817569)
The engine doesn't "cache" entities (I don't think it actually caches anything) but the client does cache files (models, sounds, etc.).

I think of it because I I see no reason why the engine does not utilize spawn points created in plugin_init or later. I think it is not reasonable to iterate all entities and check whether their classes are "info_player_deathmatch" or "info_player_start" on each player spawn. I would load a map, go through all these entities and create a tree of structures.
PHP Code:

struct sp {
  
int ent_index;
  
float origin[3];
  
float angles[3];
  
struct sp *next;
}; 

While this is only my assumption, it may explain why the engine does not recognize spawn points created after plugin_precache.

Quote:

Originally Posted by fysiks (Post 2817569)
Even if you were able to enable and disable spawn points, are you sure that they would even be random? In the game I play, Day of Defeat, they are definitely not random so certain spawn points would only get used if all of the others are already taken (have a player that spawned but hasn't moved yet).

Oh, yes, default spawn points are not random. The game spawns first player in first spawn point, second player in second spawn point and so on. So it basically iterates from the first to last spawn point, but it is not a big deal for me.

fysiks 02-07-2024 22:36

Re: How to recache spawn points?
 
Ah, so I guess I was thinking of caching in the context of files. When I save pointers or other references in a variable, I don't think of it, instinctually, as "caching" (even though it can be described that way).

In Day of Defeat, we have properties of our spawn point entities that enable or disable them depending on an assigned control point master. Not sure if Counter-Strike 1.6 has something like that.

Phant 02-07-2024 22:58

Re: How to recache spawn points?
 
You can both remove and add player spawns at any time (not only in plugin_precache), and they will work correctly.
When a player respawns, the game goes through all the info_player_deathmatch entities. If there are no spawns at all, the player spawns at 0, 0, 0 (XYZ) coordinates.
Important note: I'm talking about Half-Life, but I don't think they changed anything in this algorithm for CS.

Ты можешь как удалять, так и добавлять спауны игроков в любой момент времени (не только в plugin_precache) и они будут работать корректно.
При респауне игрока, игра проходится по всем info_player_deathmatch ентитям. Если спаунов нет вообще, то игрок появляется в 0, 0, 0 (XYZ) координатах.
Важное замечение: говорю про Half-Life, но не думаю, что в CS поменяли что-то в этом алгоритме.

damage220 02-08-2024 13:02

Re: How to recache spawn points?
 
Quote:

Originally Posted by Phant (Post 2817624)
You can both remove and add player spawns at any time (not only in plugin_precache), and they will work correctly.
When a player respawns, the game goes through all the info_player_deathmatch entities. If there are no spawns at all, the player spawns at 0, 0, 0 (XYZ) coordinates.
Important note: I'm talking about Half-Life, but I don't think they changed anything in this algorithm for CS.

Ты можешь как удалять, так и добавлять спауны игроков в любой момент времени (не только в plugin_precache) и они будут работать корректно.
При респауне игрока, игра проходится по всем info_player_deathmatch ентитям. Если спаунов нет вообще, то игрок появляется в 0, 0, 0 (XYZ) координатах.
Важное замечение: говорю про Half-Life, но не думаю, что в CS поменяли что-то в этом алгоритме.

Unfortunately, no it does not work in 1.6, at least I do not know how to make it to work. If I remove all spawn points and add my own, I cannot even choose a team. If I were in a team the moment I deleted all spawn points and created new ones, after round end I spawn at 0, 0, 0 coordinates.

damage220 02-08-2024 13:13

Re: How to recache spawn points?
 
Quote:

Originally Posted by fysiks (Post 2817620)
Ah, so I guess I was thinking of caching in the context of files. When I save pointers or other references in a variable, I don't think of it, instinctually, as "caching" (even though it can be described that way).

In Day of Defeat, we have properties of our spawn point entities that enable or disable them depending on an assigned control point master. Not sure if Counter-Strike 1.6 has something like that.

If there are more players than spawn points, it is not possible to join a team. So the engine either checks the number of spawn points for a team or set a property for an entity to assign a player to it. If the latter I wish I would have known the offset. That way I can assign a fake client to a spawn point to disable it. It seems I have to get the offset experimentally if there is any.

fysiks 02-08-2024 22:29

Re: How to recache spawn points?
 
Is there any reason you need to disable a spawn point that you created? Could you maybe just put it near the normal spawn points so that it blends in with the map then when you move them dynamically, it'll be practically like they are new?

damage220 02-09-2024 22:27

Re: How to recache spawn points?
 
Quote:

Originally Posted by fysiks (Post 2817697)
Is there any reason you need to disable a spawn point that you created? Could you maybe just put it near the normal spawn points so that it blends in with the map then when you move them dynamically, it'll be practically like they are new?

Great thought, I can even use default spawn points only and change their origins based on the current mode. I do not know why I never thought of it. Thank you.


All times are GMT -4. The time now is 00:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.