Raised This Month: $51 Target: $400
 12% 

Solved Get random spawn for team


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 03-09-2018 , 19:14   Get random spawn for team
Reply With Quote #1

Hello,
I added save spawn to file.
Code:
"SC_spawn"
{
	"0"
	{
		"origin"		"336.050629 2297.175537 -118.968750"
		"rotation"		"0.000000 134.953613 0.000000"
		"team"		"TT"
	}
}
How I can get random origin/rotation for team?
I want to random spawn, but with "team".

If player is Terrorist, plugin check all spawn with team = TT, but if player is counter-terrorist, check all spawn with CT.

To extract all spawns with a given sign, just do something like that:
Code:
public Action:TestSpawnsInfo(client, args)
{
	new Handle:spawns = SC_GetSpawnsArray();
	new Handle:teams = SC_GetTeamsArray();
	new count = GetArraySize(spawns);
	new Float:spawn[3];
	decl String:sTeam[3];

	for (new i = 0; i < count; ++i)
	{
		GetArrayArray(spawns, i, spawn);
		GetArrayString(teams, i, sTeam, sizeof(sTeam));

		if(GetClientTeam(client) == 3 && StrEqual(sTeam, "CT"))
		{
			ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);
		}
		else
			if(GetClientTeam(client) == 2 && StrEqual(sTeam, "TT"))
				ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);
	}

	return Plugin_Handled;
}
https://forums.alliedmods.net/showthread.php?t=147542

Last edited by Qes; 03-11-2018 at 09:18.
Qes is offline
pride95
Senior Member
Join Date: Aug 2015
Old 03-10-2018 , 06:09   Re: Get random spawn for team
Reply With Quote #2

PHP Code:

stock int EntityTerroristSpawn
()
{
    
int Spawn = -1;
    
ArrayList ArrayListSpawns = new ArrayList();
    
    while((
Spawn FindEntityByClassname(Spawn"info_player_terrorist")) != -1)
    {
        
ArrayListSpawns.Push(Spawn);
    }
    
    
Spawn 0;
    if(
ArrayListSpawns.Length)
    {
        
Spawn ArrayListSpawns.Get(GetRandomInt(0ArrayListSpawns.Length 1));
    }
    
    
delete ArrayListSpawns;
    return 
0;

this returns a random spawn. after you get the spawn, you get the position of the spawn.

PHP Code:

float Position
[3];
GetEntPropVector(EntityTerroristSpawn(), Prop_Send"m_vecOrigin"Position); 
if you need a random spawn every round, save the entities in a global arraylist.
if you have custom spawn spoints from a file, create the entities in OnMapStart (createentitybyname("info_player_terrorist") etc.)

Last edited by pride95; 03-10-2018 at 06:09.
pride95 is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 03-10-2018 , 06:35   Re: Get random spawn for team
Reply With Quote #3

https://forums.alliedmods.net/showthread.php?t=147542
I edit this library and add new position "team" on file.

But You give me code with spawn on map, not custom spawn in this plugin
Quote:
if you have custom spawn spoints from a file, create the entities in OnMapStart (createentitybyname("info_player_terrorist") etc.)
\
I have two spawn:
Custom spawn
Map spawn

In the new round I spawn player on mapspawn (buyzone), but if player death, I respawn player on custom spawn when enemy player is not near this spawn. If enemy player is near this spawn (custom spawn), I respawn player on mapspawn (buyzone).

I want to check random spawn on the team with "custom spawn", but I don't want check mapspawn on the team, unless player enemy is near this custom spawn.

Last edited by Qes; 03-10-2018 at 06:35.
Qes is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 03-10-2018 , 08:48   Re: Get random spawn for team
Reply With Quote #4

I maked to do it, but is this the optimal way?
This is only test code
Code:
public Action:TestSpawnsInfo(client, args)
{
	new Handle:spawns = SC_GetSpawnsArray();
	new Handle:teams = SC_GetTeamsArray();
	new count = GetArraySize(teams);
	new Float:spawn[3];
	decl String:sTeam[3];
	new random_numbers[10] = { 0, ...}, number_count = 0;

	ReplyToCommand(client, "Dumping %d spawn point%s", count, count == 1 ? "" : "s");
	for (new i = 0; i < count; ++i)
	{
		GetArrayArray(spawns, i, spawn);
		GetArrayString(teams, i, sTeam, sizeof(sTeam));

		if(GetClientTeam(client) == 3)
		{
			if(StrEqual(sTeam, "TT"))
				continue

			ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);

			if (number_count < 10) {
        random_numbers[number_count++] = i;    // Store new number
    	}
			else {
        PrintToServer("* * * Cannot add more than 10 numbers * * *")  // Exceeded maximum numbers
    	}
		}
		else
			if(GetClientTeam(client) == 2)
			{
				if(StrEqual(sTeam, "CT"))
					continue

				ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);

				if (number_count < 10) {
					random_numbers[number_count++] = i;    // Store new number
				}
				else {
					PrintToServer("* * * Cannot add more than 10 numbers * * *")  // Exceeded maximum numbers
			}
		}
	}
	new big = random_numbers[GetRandomInt(0, number_count-1)];
	GetArrayArray(spawns, big, spawn);
	GetArrayString(teams, big, sTeam, sizeof(sTeam));
	ReplyToCommand(client, "End of spawn points dump", count);
	ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", big, spawn[0], spawn[1], spawn[2], sTeam);

	return Plugin_Handled;
}
Code is work, but i don't know does is optimal

Last edited by Qes; 03-10-2018 at 08:51.
Qes is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 03-11-2018 , 05:48   Re: Get random spawn for team
Reply With Quote #5

Quote:
Originally Posted by Qes View Post
Hello,
I added save spawn to file.
Code:
"SC_spawn"
{
	"0"
	{
		"origin"		"336.050629 2297.175537 -118.968750"
		"rotation"		"0.000000 134.953613 0.000000"
		"team"		"TT"
	}
}
How I can get random origin/rotation for team?
I want to random spawn, but with "team".

If player is Terrorist, plugin check all spawn with team = TT, but if player is counter-terrorist, check all spawn with CT.

To extract all spawns with a given sign, just do something like that:
Code:
public Action:TestSpawnsInfo(client, args)
{
	new Handle:spawns = SC_GetSpawnsArray();
	new Handle:teams = SC_GetTeamsArray();
	new count = GetArraySize(spawns);
	new Float:spawn[3];
	decl String:sTeam[3];

	for (new i = 0; i < count; ++i)
	{
		GetArrayArray(spawns, i, spawn);
		GetArrayString(teams, i, sTeam, sizeof(sTeam));

		if(GetClientTeam(client) == 3 && StrEqual(sTeam, "CT"))
		{
			ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);
		}
		else
			if(GetClientTeam(client) == 2 && StrEqual(sTeam, "TT"))
				ReplyToCommand(client, "%2d - (%.2f, %.2f, %.2f) - %s", i, spawn[0], spawn[1], spawn[2], sTeam);
	}

	return Plugin_Handled;
}
https://forums.alliedmods.net/showthread.php?t=147542
Random spawns are not meant to belong to a team, what do you mean?
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 03-11-2018 , 09:18   Re: Get random spawn for team
Reply With Quote #6

No,
Random spawn = spawn points and this spawn have "section" (TT / CT).

The topic can be closed because I managed anyway, but I did not know if what I did was optimal
Qes is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:38.


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