SA-MP Forums Archive
How to shorten this up a bit? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to shorten this up a bit? (/showthread.php?tid=470546)



How to shorten this up a bit? - Pawnie - 18.10.2013

pawn Код:
CMD:deagle(playerid, params[])
{
    WeaponReceivedDeagle = 1;
    return 1;
}


CMD:receivedweapon(playerid, params[])
{
    if(WeaponReceivedDeagle == 1)
    {
        GivePlayerWeapon(playerid, 24, 100);
    }
    else if(WeaponReceivedShotgun == 1)
    {
        GivePlayerWeapon(playerid, 25, 100);
    }
    return 1;
}

Is there any way to make it so it's like

new weaponreceived

if(weaponreceived = "deagle");
etc..

and ofc
pawn Код:
CMD:deagle(playerid, params[])
{
    Weaponreceived = "deagle";
    return 1;
}

I'm kinda newb


Re: How to shorten this up a bit? - daemon3304 - 18.10.2013

give me all the code pawno script i will fix it and back it to u


Re: How to shorten this up a bit? - Pawnie - 18.10.2013

There are no bugs or such, I just need to cut it down. Its too big.


I just need to know how to instead of making

pawn Код:
new weaponreceiveddeagle
new weaponreceivedshotgun
new weaponreceivedminigun
I can just make
new weaponreceived = "shotgun" and then if they receive deagle it would actualy be weaponreceived = "deagle" (Set by me).


EX:
pawn Код:
CMD:receivedeagle(playerid, params[])
{
           weaponreceived = "deagle";
           return 1;
}

CMD:receiveshotgun(playerid, params[])
{
           weaponreceived = "shotgun";
           return 1;
}

CMD:what(playerid,params[])
{
            if(weaponreceived = "shotgun")
            {
                       //.................
            }
return 1;
}
Basicaly how to detect it

if I have weapon = "deagle";
how to detect it?

if(weapon == "deagle") bugs...


Re: How to shorten this up a bit? - -Prodigy- - 18.10.2013

pawn Код:
if(strcmp(weaponreceived, "deagle", true) != -1)



AW: How to shorten this up a bit? - Nero_3D - 18.10.2013

Just save the weapon id

pawn Код:
new WeaponReceived;
//
WeaponReceived = WEAPON_DEAGLE; // or = 24
//
GivePlayerWeapon(playerid, WeaponReceived, 100);
//
new tmp[32];
GetWeaponName(WeaponReceived, tmp, sizeof tmp);
SendClientMessage(playerid, -1, tmp);