01.01.2014, 16:03
I do not suggest you creating 12 variables for each colour, I suggest you use Array it's easier, so you can just loop them and delete them, I am writing a code, please wait :P
EDIT - You must use curly braces ( { and } )] because we are using char-array
EDIT - You must use curly braces ( { and } )] because we are using char-array
pawn Код:
#include <a_samp>
#include <zcmd>
#include <YSI\y_stringhash>
#define MAX_LIGHTS \
(12)
new
green_light[MAX_LIGHTS char],
red_light[MAX_LIGHTS char],
purple_light[MAX_LIGHTS char]
;
CMD:lights(playerid, params[])
{
if(isnull(params))
return SendClientMessage(playerid, -1, "Syntax: /lights [colour]");
ClearObjectsFirst(); //clears the last set of created lights for the new set
switch ( YHash( params ), false )
{
case _H<green>:
{
//You need to start from 0
green_light{0} = CreateObject( ... );
green_light{1} = CreateObject( ... );
// and so on.
}
case _H<red>:
{
//You need to start from 0
red_light{0} = CreateObject( ... );
red_light{1} = CreateObject( ... );
// and so on.
}
case _H<purple>:
{
//You need to start from 0
purple_light{0} = CreateObject( ... );
purple_light{1} = CreateObject( ... );
// and so on.
}
}
//continue to create all the green lights and setting them to green_light_x
return 1;
}
stock ClearObjectsFirst()
{
new
i = 0
;
while(i < MAX_LIGHTS)
{
if(IsValidObject( green_light{i} ) ) //Im only checking for the first one in the set since if one is valid they all should be
{
DestroyObject( green_light{i} );
}
else if(IsValidObject( red_light{i} ) )
{
DestroyObject( red_light{i} );
}
else //the purple lights must be the ones spawned then
{
DestroyObject( purple_light{i} );
}
i++;
}
return 1;
}