Random team spawns!
#1

Hi I trying to make a random team spawns but When a SWAT Spawn they will spawn him at Army location's and like others skins too.. why

OnPlayerSpawn
PHP код:
    if(gTeam[playerid] == PoliceTeam(GetPlayerSkin(playerid)) && FBII(GetPlayerSkin(playerid)))
    {
        new 
RandomSpawnP random(sizeof(RandomSpawnPolice));
        
SetPlayerPos(playeridRandomSpawnPolice[RandomSpawnP][0], RandomSpawnPolice[RandomSpawnP][1], RandomSpawnPolice[RandomSpawnP][2]);
        
SetPlayerFacingAngle(playeridRandomSpawnPolice[RandomSpawnP][3]);
    }
    if(
gTeam[playerid] == CIA(GetPlayerSkin(playerid)))
    {
        new 
RandomSpawnC random(sizeof(RandomSpawnCIA));
        
SetPlayerPos(playeridRandomSpawnCIA[RandomSpawnC][0], RandomSpawnCIA[RandomSpawnC][1], RandomSpawnCIA[RandomSpawnC][2]);
        
SetPlayerFacingAngle(playeridRandomSpawnCIA[RandomSpawnC][3]);
    }
    if(
gTeam[playerid] == Army(GetPlayerSkin(playerid)))
    {
        new 
RandomSpawnA random(sizeof(RandomSpawnArmy));
        
SetPlayerPos(playeridRandomSpawnArmy[RandomSpawnA][0], RandomSpawnArmy[RandomSpawnA][1], RandomSpawnArmy[RandomSpawnA][2]);
        
SetPlayerFacingAngle(playeridRandomSpawnArmy[RandomSpawnA][3]);
    }
    if(
gTeam[playerid] == SWAT(GetPlayerSkin(playerid)))
    {
        new 
RandomSpawnS random(sizeof(RandomSpawnSWAT));
        
SetPlayerPos(playeridRandomSpawnSWAT[RandomSpawnS][0], RandomSpawnSWAT[RandomSpawnS][1], RandomSpawnSWAT[RandomSpawnS][2]);
        
SetPlayerFacingAngle(playeridRandomSpawnSWAT[RandomSpawnS][3]);
    } 
Reply
#2

hey?? help me
Reply
#3

Show variable RandomSpawnSWAT and RandomSpawnArmy
Reply
#4

Here are stocks & Skins for police

PHP код:
new Float:RandomSpawnPolice[][] =
{
    {
2264.5823,2444.3086,10.8203,359.9533},
    {
2239.0381,2449.3228,11.0372,273.6409},
    {
2247.6023,2475.4460,10.8203,176.1515},
    {
2297.1189,2445.5356,3.2734,268.1237},
    {
2294.8137,2472.1870,-7.4531,354.3931},
    {
2234.7034,2457.3052,-7.4531,266.9514}
};
stock PoliceTeam(skinid)
{
    
// includes corrupt cops from singleplayer, SWAT, FBI and Army skin and 0.3.7 cop ones
    
switch(skinid)
    {
        case 
280..281282..283284..288300..301302..306: return 1;
        default: return 
0;
    }
    return 
1;
}
new 
Float:RandomSpawnSWAT[][] =
{
    {
1308.6097,1257.8893,10.8203,359.7846},
    {
1319.5581,1254.1016,10.8203,5.7158},
    {
1331.1968,1258.5696,10.8203,12.0047},
    {
1347.6495,1258.5513,10.8203,322.5380},
    {
1319.0024,1252.2576,14.2656,359.9701},
    {
1290.1794,1259.1654,10.8203,33.1432}
};
stock SWAT(skinid)
{
    switch(
skinid)
    {
        case 
285: return 1;
        default: return 
0;
    }
    return 
1;
}
new 
Float:RandomSpawnCIA[][] =
{
    {
2531.5835,2351.7695,4.2109,3.6471},
    {
2534.0068,2384.0269,4.2109,176.6296},
    {
2496.5671,2397.1416,4.2109,270.9034},
    {
2490.3596,2397.8206,10.8203,271.1319},
    {
2355.5044,1004.9908,10.8203,91.7737}
};
stock CIA(skinid)
{
    switch(
skinid)
    {
        case 
165..166: return 1;
        default: return 
0;
    }
    return 
1;
}
stock FBII(skinid)
{
    switch(
skinid)
    {
        case 
286: return 1;
        default: return 
0;
    }
    return 
1;
}
new 
Float:RandomSpawnArmy[][] =
{
    {
344.8889,2031.5403,22.6406,185.6785},
    {
343.4230,1980.5894,17.6406,96.5288},
    {
284.8153,1935.0155,17.6406,271.4122},
    {
284.2866,1973.3947,17.6406,276.4574}
};
stock Army(skinid)
{
    switch(
skinid)
    {
        case 
287: return 1;
        default: return 
0;
    }
    return 
1;

Reply
#5

new Float:RandomSpawnSWAT[6][3]
new Float:RandomSpawnSWAT[4][3]

Try it ? I dont know this will be work or not because I'm newbie too XD
Reply
#6

Quote:
Originally Posted by Dawkin
Посмотреть сообщение
new Float:RandomSpawnSWAT[6][3]
new Float:RandomSpawnSWAT[4][3]

Try it ? I dont know this will be work or not because I'm newbie too XD
It won't, the second dimension is 4 indexes (x, y, z, a). Furthermore, you don't really need to specify the size before declaring an array with initialization data. PAWN automatically determines the size it needs.

The error is in the logic where you check the team of the player.

The functions return 1 when the player is in that specific team (eg. FBI), however you compare them with the actual Team ID of the player:

Код:
if(gTeam[playerid] == Army(GetPlayerSkin(playerid)))
It should be

Код:
if(Army(GetPlayerSkin(playerid)))
So if that skin is an army skin it will return 1 and execute that part.

If you falsely compare it with the Team of the player, a player of team 0 cannot get any of these spawns.

You could either check the Team of a player, or the Skin. But don't compare these with each other because that doesn't make sense.


Код:
if(PoliceTeam(GetPlayerSkin(playerid)) || FBII(GetPlayerSkin(playerid)))
    {
        new RandomSpawnP = random(sizeof(RandomSpawnPolice));
        SetPlayerPos(playerid, RandomSpawnPolice[RandomSpawnP][0], RandomSpawnPolice[RandomSpawnP][1], RandomSpawnPolice[RandomSpawnP][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnPolice[RandomSpawnP][3]);
    }
    if(CIA(GetPlayerSkin(playerid)))
    {
        new RandomSpawnC = random(sizeof(RandomSpawnCIA));
        SetPlayerPos(playerid, RandomSpawnCIA[RandomSpawnC][0], RandomSpawnCIA[RandomSpawnC][1], RandomSpawnCIA[RandomSpawnC][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnCIA[RandomSpawnC][3]);
    }
    if(Army(GetPlayerSkin(playerid)))
    {
        new RandomSpawnA = random(sizeof(RandomSpawnArmy));
        SetPlayerPos(playerid, RandomSpawnArmy[RandomSpawnA][0], RandomSpawnArmy[RandomSpawnA][1], RandomSpawnArmy[RandomSpawnA][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnArmy[RandomSpawnA][3]);
    }
    if(SWAT(GetPlayerSkin(playerid)))
    {
        new RandomSpawnS = random(sizeof(RandomSpawnSWAT));
        SetPlayerPos(playerid, RandomSpawnSWAT[RandomSpawnS][0], RandomSpawnSWAT[RandomSpawnS][1], RandomSpawnSWAT[RandomSpawnS][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnSWAT[RandomSpawnS][3]);
    }
Also changed the FBI and Police check, you probably wanted to check if the team is Police or FBI?

You could however make this whole thing a bit better and easier. Instead of comparing each skin seperately, you could use ONE function to determine the team by skin and then get the player's Team ID and set their spawn accordingly.

eg.

Код:
#define TEAM_ARMY 1
#define TEAM_COPS 2
#define TEAM_SOMETHING 3

GetPlayerTeamBySkin(playerid)
{
switch(GetPlayerSkin(playerid)
{
case 289: return TEAM_ARMY; // Not the actual IDs, just examples
case 285: return TEAM_COPS;
case 260, 261, 262: return TEAM_SOMETHING;
}
return 0;
}
Which would be a lot easier to use than writing 8 functions for 8 team and copy-pasting the same code around everytime.
Reply
#7

Thank you! It's worked @Nas rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)