11.08.2014, 17:43
I've had this problem for a quite a time now.
As long as I have 1 spare minigun, the script works fine.
But if every single minigun gets destroyed, and you do /createminigun again, nothing happens.
The object, textlabel gets created, but nothing is happening when you shoot it.
Code;
( the only stuff needed i guess.. )
In a shorter/weirder way;
If miniguns is more than 1, you can create and destroy as much as miniguns you want, as long as there is still ONE minigun left.
If miniguns is 0, you can create them, but you wont be able to destroy them.
As long as I have 1 spare minigun, the script works fine.
But if every single minigun gets destroyed, and you do /createminigun again, nothing happens.
The object, textlabel gets created, but nothing is happening when you shoot it.
Code;
pawn Код:
new Miniguns;
enum mInfo
{
ID,
Object,
CreatorID,
IsSpawned,
MinigunHealth,
Float:MinigunDamage,
Float:MinigunRange,
Float:mX, Float:mY, Float:mZ, Float:mAngle,
Text3D:Label
};
new MinigunInfo[MAX_MINIGUNS][mInfo];
public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ )
{
if( hittype == BULLET_HIT_TYPE_OBJECT )
{
if( hitid == MinigunInfo[hitid][Object] && hitid != INVALID_OBJECT_ID )
{
switch(GetPlayerWeapon(playerid))
{
case 22, 23: MinigunInfo[hitid][MinigunHealth]--;
case 24: MinigunInfo[hitid][MinigunHealth] -= 2;
case 25..27: MinigunInfo[hitid][MinigunHealth] -= 2+random(3);
case 28, 29, 32: MinigunInfo[hitid][MinigunHealth] -= 1+random(2);
case 30, 31: MinigunInfo[hitid][MinigunHealth] -= 3+random(4);
case 33, 34: MinigunInfo[hitid][MinigunHealth] -= 2+random(5);
case 38: MinigunInfo[hitid][MinigunHealth] -= 5+random(10);
}
new lString[124], string[112];
if(MinigunInfo[hitid][MinigunHealth] > 2)
{
format(lString, sizeof(lString), "{FFFFFF}%s's {64CC66}minigun(ID: %d)\n{FFFFFF}Deals {64CC66}%0.1f damage\n{FFFFFF}Has {64CC66}%d health left.", GetName(MinigunInfo[hitid][CreatorID]), MinigunInfo[hitid][ID], MinigunInfo[hitid][MinigunDamage], MinigunInfo[hitid][MinigunHealth]);
UpdateDynamic3DTextLabelText(MinigunInfo[hitid][Label], -1, lString);
}
else DestroyDynamic3DTextLabel(MinigunInfo[hitid][Label]);
if(MinigunInfo[hitid][MinigunHealth] == 35)
{
foreach(Player, i)
{
if(IsPlayerInRangeOfPoint(i, 60, MinigunInfo[hitid][mX], MinigunInfo[hitid][mY], MinigunInfo[hitid][mZ]))
{
format(string, sizeof(string), "* %s(%d) has damaged the minigun to %d/100 health!", GetName(playerid), playerid, MinigunInfo[hitid][MinigunHealth]);
SendClientMessage(i, COLOR_RED, string), string = "\0";
SendClientMessage(i, COLOR_RED, "* The Minigun has enabled its Advanced Self-Defense mode!");
}
}
MinigunInfo[hitid][MinigunDamage] = 20;
MinigunInfo[hitid][MinigunRange] = 55;
}
else if(MinigunInfo[hitid][MinigunHealth] <= 1)
{
format(string, sizeof(string), "* %s(%d) destroyed %s's(%d) minigun!", GetName(playerid), playerid, GetName(MinigunInfo[hitid][CreatorID]), MinigunInfo[hitid][CreatorID]);
SendClientMessageToAll(COLOR_NOTES, string), string = "\0";
SetPlayerHealth(playerid, 99);
GivePlayerScore(playerid, 3);
GivePlayerMoney(playerid, 15000);
SendClientMessage(playerid, COLOR_NOTES, "* You've received 3 score and 15'000$!");
DestroyMinigun(hitid);
}
return 1;
}
}
return 1;
}
stock CreateMinigun(Creator, mID, Float:X, Float:Y, Float:Z, Float:Angle, Health, Float:Damage, Float:Range)
{
new lString[124];
MinigunInfo[mID][Object] = CreateObject(2985,X,Y+1,Z-0.95,0,0,0);
MinigunInfo[mID][ID] = mID;
MinigunInfo[mID][CreatorID] = Creator;
MinigunInfo[mID][IsSpawned] = 1;
MinigunInfo[mID][MinigunHealth] = Health;
MinigunInfo[mID][MinigunDamage] = Damage, MinigunInfo[mID][MinigunRange] = Range;
MinigunInfo[mID][mX] = X, MinigunInfo[mID][mY] = Y+1, MinigunInfo[mID][mZ] = Z-0.75, MinigunInfo[mID][mAngle] = Angle;
Miniguns++;
printf("[info] created minigun %d .. %d", mID, Miniguns);
printf("[info] creator: %d, health: %d, dmg: %0.1f, rng: %0.1f.", Creator, Health, Damage, Range);
format(lString, sizeof(lString), "{FFFFFF}%s's {64CC66}minigun(ID: %d)\n{FFFFFF}Deals {64CC66}%0.1f damage\n{FFFFFF}Has {64CC66}%d health left.", GetName(Creator), mID, Damage, Health);
MinigunInfo[mID][Label] = CreateDynamic3DTextLabel(lString, -1, X,Y+1,Z, 60);
return 1;
}
stock DestroyMinigun(minigunid)
{
DestroyObject(MinigunInfo[minigunid][Object]), MinigunInfo[minigunid][Object] = INVALID_OBJECT_ID;
MinigunInfo[minigunid][ID] = -1;
MinigunInfo[minigunid][CreatorID] = -1;
MinigunInfo[minigunid][IsSpawned] = -1;
MinigunInfo[minigunid][MinigunHealth] = -1;
MinigunInfo[minigunid][MinigunDamage] = -1, MinigunInfo[minigunid][MinigunRange] = -1;
MinigunInfo[minigunid][mX] = -1, MinigunInfo[minigunid][mY] = -1, MinigunInfo[minigunid][mZ] = -1, MinigunInfo[minigunid][mAngle] = -1;
SelectedMinigun[MinigunInfo[minigunid][CreatorID]] = 0;
DestroyDynamic3DTextLabel(MinigunInfo[minigunid][Label]);
Miniguns--;
return 1;
}
In a shorter/weirder way;
If miniguns is more than 1, you can create and destroy as much as miniguns you want, as long as there is still ONE minigun left.
If miniguns is 0, you can create them, but you wont be able to destroy them.