OnPlayerWeaponShot not recognizing minigun
#1

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;
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;
}
( 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.
Reply
#2

bump
Reply
#3

Why are you using the objectid as in index for your minigun data in OnPlayerWeaponShot?
Reply
#4

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Why are you using the objectid as in index for your minigun data in OnPlayerWeaponShot?
Eh? Could you explain please ( I didn't understand the word 'index' ;_; )

What should I change, and why? xd
Reply
#5

I'm sure this isn't helpful, but why do you use GetPlayerWeapon instead of 'weaponid'?
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
I'm sure this isn't helpful, but why do you use GetPlayerWeapon instead of 'weaponid'?
Uh.. GetPlayerWeapon was the first thing that came into my mind :d
Reply
#7

Well in that line you do insert hitid in the MinigunInfo array although it is the objectid
pawn Код:
if( hitid == MinigunInfo[hitid][Object] && hitid != INVALID_OBJECT_ID )
Although I don't know what id's you use for the array but I assume that it can't be the object id because you create the object like that
pawn Код:
MinigunInfo[mID][Object] = CreateObject(2985,X,Y+1,Z-0.95,0,0,0);
And not like that
pawn Код:
new objectid = CreateObject(2985,X,Y+1,Z-0.95,0,0,0);
MinigunInfo[objectid][Object] = objectid;
Reply
#8

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Well in that line you do insert hitid in the MinigunInfo array although it is the objectid
pawn Код:
if( hitid == MinigunInfo[hitid][Object] && hitid != INVALID_OBJECT_ID )
Although I don't know what id's you use for the array but I assume that it can't be the object id because you create the object like that
pawn Код:
MinigunInfo[mID][Object] = CreateObject(2985,X,Y+1,Z-0.95,0,0,0);
And not like that
pawn Код:
new objectid = CreateObject(2985,X,Y+1,Z-0.95,0,0,0);
MinigunInfo[objectid][Object] = objectid;
Eh..
Here's the full code;
http://pastebin.com/JijHbQqL

I create the minigun like this;

pawn Код:
CMD:createminigun(playerid, params[]) {
        if(IsPlayerAdmin(playerid))
        {
            if(Miniguns < MAX_MINIGUNS)
            {
                new health, Float:damage, Float:range;
                if(sscanf(params, "iff", health, damage, range)) return SendClientMessage(playerid, COLOR_NOTES, "[USAGE] /createminigun HEALTH DAMAGE RANGE");
               
                if(health > 100 || health < 45) return SendClientMessage(playerid, COLOR_NOTES, "[INFO] The max. HEALTH is 100, the min. HEALTH is 45.");
                else if(damage > 20 || damage < 5) return SendClientMessage(playerid, COLOR_NOTES, "[INFO] The max. DAMAGE is 20, the min. DAMAGE is 5.");
                else if(range > 35 || range < 10) return SendClientMessage(playerid, COLOR_NOTES, "[INFO] The max. RANGE is 35, the min. RANGE is 10.");
               
                new Float:X, Float:Y, Float:Z, Float:Angle; GetPlayerPos(playerid, X, Y, Z); GetPlayerFacingAngle(playerid, Angle);
                new id = GetAvailableID();
                CreateMinigun(playerid, id, X, Y, Z, Angle, health, damage, range);
               
                //Remove these 4 lines ( 594 -> 597 ), if you don't want people to get notifications about miniguns being created.
                new string[72];
                format(string, sizeof(string), "[INFO] %s(%d) has created a minigun at %s.", GetName(playerid), playerid, GetPlayerArea(playerid));
                SendClientMessageToAll(COLOR_RED, string), string = "\0";
                }
                else SendClientMessage(playerid, COLOR_RED, "[NOTE] The max. amount of miniguns has been reached.");
        }
        else return 0;
        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;
}
Reply
#9

Okay, I am just wondering how the script could even work ?
The only possiblilty is that you don't use any other objects in this server, do you?

To fix that just change that if statment into a loop
pawn Код:
//OnPlayerWeaponShot
if( hitid == MinigunInfo[hitid][Object] )
// into
for(new i = 0; i < MAX_MINIGUNS; i++)
{
    if(hitid == MinigunInfo[i][Object])
    {
        // the remaining code
        return 1; // or break;
    }
}
I also noticed that you do in DestroyMinigun
pawn Код:
MinigunInfo[i][IsSpawned] = -1;
// but it should be
MinigunInfo[i][IsSpawned] = 0;
Reply
#10

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Okay, I am just wondering how the script could even work ?
The only possiblilty is that you don't use any other objects in this server, do you?

To fix that just change that if statment into a loop
pawn Код:
//OnPlayerWeaponShot
if( hitid == MinigunInfo[hitid][Object] )
// into
for(new i = 0; i < MAX_MINIGUNS; i++)
{
    if(hitid == MinigunInfo[i][Object])
    {
        // the remaining code
        return 1; // or break;
    }
}
I also noticed that you do in DestroyMinigun
pawn Код:
MinigunInfo[i][IsSpawned] = -1;
// but it should be
MinigunInfo[i][IsSpawned] = 0;
Worked, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)