[HELP] Random, MoveObject
#1

Hello, I'am trying to make fallout minigame by myself but i have some problems.

So, i have timer to MoveObject (fallout platforms) down by 5 units every x seconds.

I HAVE:

Код:
new fFallObject[100];
public OnGameModeInit()
Код:
fFallObject[1] = CreateObject(...);
//... 1 - 100
fFallObject[100] = CreateObject(...);
Timer for moving random(100) object down by 5 units every 5 seconds

Код:
SetTimer("FalloutFall", 5000, true);
The timer functions

Код:
forward FalloutFall();
public FalloutFall()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(FalloutJoined[i] == true)
		{
		//some code
		}

	}
	
	new Fall = random(100);
	new Float:oX, Float:oY, Float:oZ;
	
	GetObjectPos(fFallObject[Fall], oX, oY, oZ);
	MoveObject(fFallObject[Fall],oX,oY,oZ-5,5);

}
PROBLEM 1:

I have no idea how to call that random(100) only once per generated number.
So if random(100) is for example 66, DO NOT CALL 66 AGAIN! (how?)
And if it's generate something 99x, stop generating so last object stay on its position !
Any idea?

PROBLEM 2:
How to get these objects back to their positions like in OnGameModeInIt after i stop my timer?

Код:
forward FalloutRespawn();
public FalloutRespawn()
{
//??? :'( xD
}
Reply
#2

You could create a holder

like moveobjects[100];

initialize everything to -1

if(moveobject[number] != -1)
{
then skip it. or something like that, just an idea though
}
Reply
#3

Код:
new bool:ObjectFallen[100] = false;

forward FalloutFall();
public FalloutFall()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(FalloutJoined[i] == true)
		{
		//some code
		}

	}
	new Fall = -1;
        while(Fall == -1)
        {
               Fall = random(100);
               if(ObjectFallen[Fall]) Fall = -1;
        }
	
        ObjectFallen[Fall] = true;
	new Float:oX, Float:oY, Float:oZ;
	
	GetObjectPos(fFallObject[Fall], oX, oY, oZ);
	MoveObject(fFallObject[Fall],oX,oY,oZ-5,5);
        if(AllObjectsFallen) ResetFallenObjects();

}

AllObjectsFallen()
{
       for(new i = 0; i < 100; i++)
       {
              if(!ObjectFallen[i]) return false;
       }
       return true;
}

ResetFallenObjects()
{
       for(new i = 0; i < 100; i++)
       {
              ObjectFallen[i] = false;
       }
}
If you get the code above, i can you help you with the rest as well
Reply
#4

Thank you very much this is working prefectly! Changed some little erros and it works! Finally!


EDIT:

Код:
ResetFallenObjects()
{
       for(new i = 0; i < 100; i++)
       {
              ObjectFallen[i] = false;
       }
}
DOES NOT WORK - IDK WHY

another problem: object 100 NEVER FALL

IF IT WORK: Everything what i need now is to Check Last Player on Pos Z 666 and made him a winner.
Then kill timer and END this game !
Reply
#5

Loops start from 0 to 99, that's why 100 is never called
Reply
#6

Well ok i got it. But why the code i posted does not work ?:/

Код:
ResetFallenObjects()
{
       for(new i = 0; i < 100; i++)
       {
              ObjectFallen[i] = false;
       }
}
Reply
#7

BUMP!
Reply
#8

Try moving the object?

ResetFallenObjects()
{
for(new i = 0; i < 100; i++)
{
ObjectFallen[i] = false;
MoveObject(ObjectFallen[i], ....);
}
}
Reply
#9

Код:
stock ResetFallenObjects()
{
       for(new i = 0; i < 100; i++)
       {
            new Float:x, Float:y, Float:z;
			GetObjectPos(i, x, y, z);
			ObjectFallen[i] = false;
			MoveObject(ObjectFallen[i],x ,y ,z+5 ,20 ,0,0,0);
       }
}
STILL DOES NOT WORK 0 ERROR
Reply
#10

Quote:
Originally Posted by jop9888
Посмотреть сообщение
Код:
new bool:ObjectFallen[100] = false;

forward FalloutFall();
public FalloutFall()
{
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(FalloutJoined[i] == true)
		{
		//some code
		}

	}
	new Fall = -1;
        while(Fall == -1)
        {
               Fall = random(100);
               if(ObjectFallen[Fall]) Fall = -1;
        }
	
        ObjectFallen[Fall] = true;
	new Float:oX, Float:oY, Float:oZ;
	
	GetObjectPos(fFallObject[Fall], oX, oY, oZ);
	MoveObject(fFallObject[Fall],oX,oY,oZ-5,5);
        if(AllObjectsFallen) ResetFallenObjects();

}

AllObjectsFallen()
{
       for(new i = 0; i < 100; i++)
       {
              if(!ObjectFallen[i]) return false;
       }
       return true;
}

ResetFallenObjects()
{
       for(new i = 0; i < 100; i++)
       {
              ObjectFallen[i] = false;
       }
}
If you get the code above, i can you help you with the rest as well
WHY ONE OF 100 OBJECTS NEVER FALL? HOW TO FIX IT?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)