PDA

View Full Version : Random Spawns


Captain_Mani
08/08/2012, 08:51 AM
So I followed this tutorial http://forum.sa-mp.com/showthread.php?t=162488.

And I am making a Cops n Robbers server.
So I want the players except the cops to spawn in random locations as in that tutorial. And I don't want the cops to get randomly spawned.

I have this under OnPlayerSpawn:
public OnPlayerSpawn(playerid)
{

new Random = random(sizeof(RandomSpawns));
SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);
return 1;
}

And I am having the coordinates of random locations too:
// Random Spawns
new Float:RandomSpawns[][] =
{
{2097.2593,2473.7183,10.8203,178.1770},
{1898.8087,2323.0466,10.8203,264.9472},
{2172.4478,2008.0054,10.8203,88.9606},
{2025.3451,1919.7219,12.3384,269.4235},
{1690.7856,1449.0375,10.7660,270.6801},
{2490.2200,1207.5165,10.8203,179.5049},
{2653.4827,1093.5004,10.8203,86.7689},
{1704.4315,993.5544,10.8203,90.2138},
{1307.2826,2075.1921,10.8203,178.9650},
{644.5126,1689.4279,6.9922,35.9316},
{-332.7460,1549.4673,75.5625,3.8023},
{12.9660,1179.5498,19.4441,178.5491},
{1848.6863,2625.6885,10.8203,357.9653}
};

Now I want to make this random spawn for all the skins except for the skins 266, 265, 283, 284, and 285.
Those are the cop skins. How could I do this? Help would be greatly appreciated and I will +rep you.

Thanks,
Captain_Mani ;)

[KHK]Khalid
08/08/2012, 09:00 AM
Use this stock I made:

stock IsPlayerACop(playerid)
{
if(GetPlayerSkin(playerid) == 266 || 265 || 283 || 284 || 285)
return 1; // true

return 0; // false
}

Now this can be used under OnPlayerspawn to check whether a player is a cop or not, example:
if(IsPlayerACop(playerid) == 0) // if the player is not a cop
{
new Random = random(sizeof(RandomSpawns));
SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);
}
if(IsPlayerACop(playerid) == 1) // the player is a cop
{
// Code
}

Youice
08/08/2012, 09:05 AM
try this , (I didn't even test it, and it's mid-night here and Im tired, so good luck with that bro!!)


forward SetRandomSkin(playerid);
public SetRandomSkin(playerid)
{
new randskin = random(randskin); new randskins = random(randskins);
if(gTeam[playerid] == TEAM_COP)//change this line to the real "team cops" variable in your script
{
switch(randskin)
{
case 1:
{
SetPlayerSkin(playerid, 266);
}
case 2:
{
SetPlayerSkin(playerid, 265);
}
case 3:
{
SetPlayerSkin(playerid, 283);
}
case 4:
{
SetPlayerSkin(playerid, 284);
}
case 5:
{
SetPlayerSkin(playerid, 285);
}
}
}
if(gTeam[playerid] == TEAM_ROBBERS)//change this line to the real "team robbers" variable in your script
{
switch(randskins)
{
case 1:
{
new skins = 0>299;
SetPlayerSkin(playerid, skins);
}
}
}
SetPlayerSkin(playerid, randskin);
return 1;
}


now it can be used under etc, by just adding "SetRandomSkin(playerid);"

Captain_Mani
08/08/2012, 10:37 AM
@ Youice; Thanks for trying to help me but I want a random spawn fixed, not setting players' skins, lol. o.o


@ HellSphinX; Thanks for trying to help, but it compiles good, but in-game neither the cops nor the others spawn in random locations. Please help!

IceMeteor
08/08/2012, 10:43 AM
How can we know if the player is a cop or not?

Captain_Mani
08/08/2012, 10:46 AM
How can we know if the player is a cop or not?
By the skin id.

Anyway I fixed it.
Thanks to HellSphinX.
I changed his stock to this:

stock IsPlayerACop(playerid)
{
if(GetPlayerSkin(playerid == 266+265+283+284+285))
return 1; // true

return 0; // false
}

+Repped HellSphinX for giving me a clue and fixing half of the problem.

IceMeteor
08/08/2012, 10:49 AM
Okay then, and what is the other half problem?

[MM]RoXoR[FS]
08/08/2012, 10:51 AM
public OnPlayerSpawn(playerid)
{

if(GetPlayerSkin(playerid) != 266 && GetPlayerSkin(playerid) != 265 && GetPlayerSkin(playerid) != 283 && GetPlayerSkin(playerid) != 284 && GetPlayerSkin(playerid) != 285)
{
new Random = random(sizeof(RandomSpawns));
SetPlayerPos(playerid, RandomSpawns[Random][0], RandomSpawns[Random][1], RandomSpawns[Random][2]);
SetPlayerFacingAngle(playerid, RandomSpawns[Random][3]);}
return 1;
}

Captain_Mani
08/08/2012, 11:40 AM
Okay then, and what is the other half problem?
The problem was with that guy's stock. His stock didn't work properly. I changed it and fixed the problem. That was the half problem.

And RoXoR, I fixed the problem.
Thanks anyway. :)

Vince
08/08/2012, 11:56 AM
By the skin id.

Anyway I fixed it.
Thanks to HellSphinX.
I changed his stock to this:

stock IsPlayerACop(playerid)
{
if(GetPlayerSkin(playerid == 266+265+283+284+285))
return 1; // true

return 0; // false
}

+Repped HellSphinX for giving me a clue and fixing half of the problem.

Wtf? The compiler does constant math, so this will just compile to 1383. I'm surprised that it does even compile.

Captain_Mani
08/08/2012, 12:03 PM
It works though. o.o