Check if point is occupied
#1

Hello people.

In this thread, I most likely want help with an idea to implement, so where it is:

I have an enum for random points (code below), I have like 50 points of these, and when I write a command, 30 players are teleported to these points, each player is teleported to a random point. What I basically want is to prevent two players or more from teleporting to one same point, and after the teleportation people are expected to die and spawn again, they'll respawn at a random point again, but still I don't want two players to spawn at the same point in same time, how can I do this?

Code:
enum RandomPoints
{
	Float:wcrm_X,
	Float:wcrm_Y,
	Float:wcrm_Z,
	Float:wcrm_RZ
};
Reply
#2

This could be a idea.

PHP Code:
#define MAX_SPAWN_POINTS           50 // Your value
enum RandomPoints
{
    
Float:wcrm_X[MAX_SPAWN_POINTS],
    
Float:wcrm_Y[MAX_SPAWN_POINTS],
    
Float:wcrm_Z[MAX_SPAWN_POINTS],
    
Float:wcrm_RZ[MAX_SPAWN_POINTS],
    
bool:IsSpawnPointUsed[MAX_SPAWN_POINTS]
};
for(new 
0MAX_SPAWN_POINTSi++){
    if(!
IsSpawnPointUsed[i]){
        
SetSpawnInfo(playeridplayerteamplayerskinwcrm_Xwcrm_Ywcrm_Zweaponammoweaponammoweaponammo);
        
IsSPawnPointUsed[i] = true;
    }    

Reply
#3

Quote:
Originally Posted by v1k1nG
View Post
This could be a idea.

PHP Code:
#define MAX_SPAWN_POINTS           50 // Your value
enum RandomPoints
{
    
Float:wcrm_X[MAX_SPAWN_POINTS],
    
Float:wcrm_Y[MAX_SPAWN_POINTS],
    
Float:wcrm_Z[MAX_SPAWN_POINTS],
    
Float:wcrm_RZ[MAX_SPAWN_POINTS],
    
bool:IsSpawnPointUsed[MAX_SPAWN_POINTS]
};
for(new 
0MAX_SPAWN_POINTSi++){
    if(!
IsSpawnPointUsed[i]){
        
SetSpawnInfo(playeridplayerteamplayerskinwcrm_Xwcrm_Ywcrm_Zweaponammoweaponammoweaponammo);
        
IsSPawnPointUsed[i] = true;
    }    

I've used this idea before, but when players will die again and they will respawn to another random point. Like in 10 minutes, all random points will be "used", and players won't be able to respawn anymore.

So..?
Reply
#4

Give your random point an id and a boolean, false by defaut.

Every time a player spawns at that point, set the point boolean to true (as someone has already spawned at the said location) and also make a player variable containing that spawn id. When the player dies, set that random point boolean to false (thus it can be used again).

What is left to do is a function that checks whether there is a free (boolean set to false) spawn point. If there is none, just choose a random one from the whole set of spawn points.
Reply
#5

Quote:

but when players will die again and they will respawn to another random point.

I didn't put my idea under any public function. If you do use SetSpawnInfo under OnPlayerDeath obviously that code will be read by the server under OnPlayerDeath and so when player dies. If you put it under OnPlayerConnect for example it will be read only once when player connects.

I think you need more basic knowledge, you should check samp wiki more often https://sampwiki.blast.hk/wiki/Main_Page.
Reply
#6

Quote:
Originally Posted by v1k1nG
View Post
I didn't put my idea under any public function. If you do use SetSpawnInfo under OnPlayerDeath obviously that code will be read by the server under OnPlayerDeath and so when player dies. If you put it under OnPlayerConnect for example it will be read only once when player connects.

I think you need more basic knowledge, you should check samp wiki more often https://sampwiki.blast.hk/wiki/Main_Page.
No dude, I want them to spawn on another random point purposely, I have enough knowledge about the way it works, but the concept is that they will respawn again and again till I write the command again.
Reply
#7

Command or player death? You are not being clear, anyways checking the wiki is not a sin nor a shameful act.
Reply
#8

Quote:
Originally Posted by Private200
View Post
Give your random point an id and a boolean, false by defaut.

Every time a player spawns at that point, set the point boolean to true (as someone has already spawned at the said location) and also make a player variable containing that spawn id. When the player dies, set that random point boolean to false (thus it can be used again).

What is left to do is a function that checks whether there is a free (boolean set to false) spawn point. If there is none, just choose a random one from the whole set of spawn points.
This is a good idea. Will wait for more ideas.


Quote:
Originally Posted by v1k1nG
View Post
Command or player death? You are not being clear, anyways checking the wiki is not a sin nor a shameful act.
You need to re-read the main post, afterwards, re-think about the idea. I'm fully understanding the way it works but you are too lazy to read I guess.
Reply
#9

Quote:
Originally Posted by Viggo
View Post
This is a good idea. Will wait for more ideas.
You didn't read my code. Private200 and me had the same idea.
Reply
#10

Or maybe you could make 2 arrays. One with all of the spawns unmodified, and one where the used spawns get removed as they get used. Then you simply remove it from the array and "compress" the array.
Reply
#11

Quote:
Originally Posted by v1k1nG
View Post
You didn't read my code. Private200 and me had the same idea.
At the beginning of the idea it's the same, but Private200 added a nice touch to his idea at the end which is the touch I need, but I'm waiting for more ideas, more efficient ideas if there are any.

You need to read more dude, just read slowly and understand what you read.
Reply
#12

Quote:
Originally Posted by Viggo
View Post
At the beginning of the idea it's the same, but Private200 added a nice touch to his idea at the end which is the touch I need, but I'm waiting for more ideas, more efficient ideas if there are any.

You need to read more dude, just read slowly and understand what you read.
Quote:
Originally Posted by Private200
View Post
What is left to do is a function that checks whether there is a free (boolean set to false) spawn point. If there is none, just choose a random one from the whole set of spawn points.
PHP Code:
for(new 0MAX_SPAWN_POINTSi++){
    if(!
IsSpawnPointUsed[i]){
        
SetSpawnInfo(playeridplayerteamplayerskinwcrm_X[i], wcrm_Y[i], wcrm_Z[i], weaponammoweaponammoweaponammo);
        
IsSPawnPointUsed[i] = true;
    }    

Reply
#13

If you would not want the player to have any relation to the ID, you can make it all related to the enum itself. Add a player id variable in your spawn position enum and when a player spawns on the said location, set that id to the player id. When the player dies, loop through all the spawn positions and if that player id matches the one of the player that died, reset the boolean.

It is almost similar in terms of efficiency, it will though not change anything to the player variables.
Reply
#14

Quote:
Originally Posted by RedFusion
View Post
Or maybe you could make 2 arrays. One with all of the spawns unmodified, and one where the used spawns get removed as they get used. Then you simply remove it from the array and "compress" the array.
Another cool idea, maybe nice.

But I've just realized that I can have a more efficient idea. Which is adding "wcrm_LastSpawned" adjective to the enum, when the player is spawned, wcrm_LastSpawned will contain the GetTickCount when he spawns, and when someone else respawns, I choose a random point, if the random point was used in less than 60 seconds, then I'll randomize again till I find a random point with LastSpawned higher than 60 seconds.

Quote:
Originally Posted by v1k1nG
View Post
PHP Code:
for(new 0MAX_SPAWN_POINTSi++){
    if(!
IsSpawnPointUsed[i]){
        
SetSpawnInfo(playeridplayerteamplayerskinwcrm_X[i], wcrm_Y[i], wcrm_Z[i], weaponammoweaponammoweaponammo);
        
IsSPawnPointUsed[i] = true;
    }    

You haven't quoted his whole reply, the part you haven't quoted of his reply makes the difference between both ideas.

Quote:
Originally Posted by Private200
View Post
If you would not want the player to have any relation to the ID, you can make it all related to the enum itself. Add a player id variable in your spawn position enum and when a player spawns on the said location, set that id to the player id. When the player dies, loop through all the spawn positions and if that player id matches the one of the player that died, reset the boolean.

It is almost similar in terms of efficiency, it will though not change anything to the player variables.
Yeah that's a different way for it, cool.
Reply
#15

Okay so I've just realized that I will be spawning vehicles! And not players lol. Vehicles will be randomly spawning there, and what I'm willing to use, is.. add to each spawn point the VehicleID whenever a vehicle spawns in it, and whenever a vehicle dies or respawns (most importantly it leaves the area), I tell the server that the spawn point is free now.

If you think there's a better way, then let me know.
Reply
#16

I would use Incognito's streamer for that. For each vehicle created, also create an area attached to that vehicle. Of course, only create areas for the vehicles that you need verification on. Then, when you select a position, check with IsPointInAnyDynamicArea if the selected position is in any area.

I don't know how efficient that is, though. Simply looping through those vehicles (if there aren't many) should do the trick.
Reply
#17

Quote:
Originally Posted by CONTROLA
View Post
I would use Incognito's streamer for that. For each vehicle created, also create an area attached to that vehicle. Of course, only create areas for the vehicles that you need verification on. Then, when you select a position, check with IsPointInAnyDynamicArea if the selected position is in any area.

I don't know how efficient that is, though. Simply looping through those vehicles (if there aren't many) should do the trick.
Yeah, this is it. This is what I was looking for.

REP'd, thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)