anti 2 spawns
#1

There is a chance, more than one player, teleports to the same place:
I want to block it, and allow each player to teleport one

( sorry my bad english )

PHP код:
new Float:Mini_Spawns[][] ={
    {
2504.0403, 2752.6584, 10.8203, 277.4510},
    {
2501.9241, 2786.6301, 10.8203, 280.2944},
    {
2502.4229, 2823.0249, 10.8203, 271.8576},
    {
2530.3135, 2825.2761, 10.8203, 343.9250},
    {
2542.3699, 2842.7058, 14.2559, 233.0039},
    {
2566.8967, 2845.7397, 14.2559, 168.4566},
    {
2615.5188, 2848.5894, 10.8203, 165.5162},
    {
2613.9805, 2807.5530, 10.8203, 35.2887},
    {
2575.2578, 2838.7549, 19.9922, 180.8019},
    {
2556.9509, 2813.4043, 19.9922, 276.6828},
    {
2589.8726, 2806.3186, 19.9922, 33.1235},
    {
2608.6619, 2824.7385, 19.9922, 66.7710},
    {
2576.0601, 2696.9539, 28.1406, 291.5832},
    {
2579.1174, 2712.5681, 28.1953, 266.1107},
    {
2616.1858, 2717.8274, 36.5386, 264.6547},
    {
2625.7529, 2735.0579, 36.1918, 346.7751},
    {
2618.9297, 2748.1260, 26.7127, 340.5084},
    {
2637.2224, 2769.2407, 25.8222, 186.6836}
}; 
PHP код:
    for(new iCount; iCount < MAX_PLAYERS; iCount++) if(IsPlayerConnected(iCount) && pInActivity[iCount])
                        {
                            new 
rand = random(sizeof(Mini_Spawns));
                            
SetPlayerPos(iCount, Mini_Spawns[rand][0], Mini_Spawns[rand][1], Mini_Spawns[rand][2]);
                            
SetPlayerFacingAngle(iCount, Mini_Spawns[rand][3]);
} 
Reply
#2

Declare global variable:
Код:
new LastSpawn = -1;
And do something like that, should works.
Код:
loop_start:
new rand = random(sizeof(Mini_Spawns));
if(LastSpawn == rand) goto loop_start;
SetPlayerPos(iCount, Mini_Spawns[rand][0], Mini_Spawns[rand][1], Mini_Spawns[rand][2]);
SetPlayerFacingAngle(iCount, Mini_Spawns[rand][3]);
Reply
#3

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
Declare global variable:
Код:
new LastSpawn = -1;
And do something like that, should works.
Код:
loop_start:
new rand = random(sizeof(Mini_Spawns));
if(LastSpawn == rand) goto loop_start;
SetPlayerPos(iCount, Mini_Spawns[rand][0], Mini_Spawns[rand][1], Mini_Spawns[rand][2]);
SetPlayerFacingAngle(iCount, Mini_Spawns[rand][3]);
I do not know how to fix what you did here

Please send me a working code


Do you think it will work?
->>

PHP код:
    for(new iCount; iCount < MAX_PLAYERS; iCount++) if(IsPlayerConnected(iCount) && pInActivity[iCount])
                        {
                            
loop_start:
                            new 
rand = random(sizeof(Mini_Spawns));
                            if(
LastSpawn == rand) goto loop_start;
                            
LastSpawn = rand;
                            
SetPlayerPos(iCount, Mini_Spawns[rand][0], Mini_Spawns[rand][1], Mini_Spawns[rand][2]);
                            
SetPlayerFacingAngle(iCount, Mini_Spawns[rand][3]);
                        } 
Reply
#4

Yes, just try it.
Reply
#5

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
Yes, just try it.
I want to be sure
Reply
#6

I'm sure it's if-goto loop, read about it at wiki.
https://sampwiki.blast.hk/wiki/Control_Structures#if-goto
Reply
#7

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
I'm sure it's if-goto loop, read about it at wiki.
https://sampwiki.blast.hk/wiki/Control_Structures#if-goto
PHP код:
    for(new iCount; iCount < MAX_PLAYERS; iCount++) if(IsPlayerConnected(iCount) && pInActivity[iCount]) 
                        { 
                            
loop_start: 
                            new 
rand = random(sizeof(Mini_Spawns)); 
                            if(
LastSpawn == rand) goto loop_start; 
                            
LastSpawn = rand; 
                            
SetPlayerPos(iCount, Mini_Spawns[rand][0], Mini_Spawns[rand][1], Mini_Spawns[rand][2]); 
                            
SetPlayerFacingAngle(iCount, Mini_Spawns[rand][3]); 
                        } 
Note that I did it in the loop

It works this way?
Reply
#8

Yes, it will work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)