Bomber help
#1

Hello.

I'm making bomber system, all work good but when i press bomb 3-4 times 1 bomb explode, on other i just see objects. Didn't explode..

Код:
new Rocket[ MAX_PLAYERS ]; // The Rocket
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if( newkeys == KEY_YES )
	{
		new Float:x, Float:y, Float:z, vehicleid, Float:Angle;
		GetPlayerPos( playerid, x, y, z );
        vehicleid = GetPlayerVehicleID(playerid);
        GetVehicleZAngle(vehicleid, Angle);
        Rocket[playerid] = CreateObject(354, x, y, z-3.0, 0, 0, Angle+90);
		z = 0.0;
		GetPointZPos( x, y, z );
		MoveObject(Rocket[playerid], x, y, z, 32.0 );

	}

	return 1;
}
Код:
public OnObjectMoved(objectid)
{
		new playerid;
		new Float:x, Float:y, Float:z;
		GetObjectPos( Rocket[playerid], x, y, z );
		CreateExplosion( x, y, z, 4, 40 );
		DestroyObject( Rocket[playerid] );
	return 1;
}
Reply
#2

That is because how you store the bombs ID, if you launch 3 bombs, the variable only will get the last bomb, and will only work with the last bomb.
Example:
I press the Y key, so Rocket will have the ID of the current object
pawn Код:
Rocket[playerid] = CreateObject(354, x, y, z-3.0, 0, 0, Angle+90);//Suppose that the ID returned is 1500 so that is the value of the variable now
Now I press again the Y key
pawn Код:
Rocket[playerid] = CreateObject(354, x, y, z-3.0, 0, 0, Angle+90);//Now the 'Rocket' variable will have the returned ID of this object, suppose that is 1501
So when the callback OnObjectMoved is called:
pawn Код:
GetObjectPos( Rocket[playerid], x, y, z );
        CreateExplosion( x, y, z, 4, 40 );
        DestroyObject( Rocket[playerid] );//The variable because only have the last ID of the last object, will only work with this object, others launched before won't work. (Important: It should work only if you wait until the object is completely moved, two moving at same time won't work)
Reply
#3

I'know that, but what i do? To call OnObjectMoved one more time?
Reply
#4

i think You Can Make a Timer To Count when you Call OnObjectMoved Again .
Reply
#5

Can i use multiple arrays? Like Rocket[MAX_PLAYERS][MAX_BOMBS]
Reply
#6

BUMP
Reply
#7

Quote:
Originally Posted by shulk
Посмотреть сообщение
Can i use multiple arrays? Like Rocket[MAX_PLAYERS][MAX_BOMBS]
Exactly, setting MAX_BOMBS to 40 should be good, and increase the Bomb_ID depending of the bombs that are launched, decrease the ID when the bombs have touched the ground. Remember put a limit, or you will get an out of bounds error if 41 or more bombs are launched.

If you don't have other objects moving, you should change this
pawn Код:
public OnObjectMoved(objectid)
{
        new playerid;
        new Float:x, Float:y, Float:z;
        GetObjectPos( Rocket[playerid], x, y, z );
        CreateExplosion( x, y, z, 4, 40 );
        DestroyObject( Rocket[playerid] );
    return 1;
}
to
pawn Код:
public OnObjectMoved(objectid)
{
        //new playerid; - This is wrong too, the variable always will have a value of 0
        new Float:x, Float:y, Float:z;
        GetObjectPos( objectid, x, y, z );
        CreateExplosion( x, y, z, 4, 40 );
        DestroyObject( objectid );
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)