Little help with weapons name :/
#7

Quote:
Originally Posted by Mugalito
Посмотреть сообщение
you can use this if u want to define names by yourself.
PHP код:
stock GetWeaponNameEx(weaponid)
{
    new 
wname[64];
    if(
weaponid == 0wname "Fist";
    if(
weaponid == 31wname "M4";
    if(
weaponid == 30wname "AK-47";
/// u can add the weaponids an names by yourself.
    
return wname;

A much lightweight snippet of your code would look like this:

PHP код:
GetWeaponNameEx(weaponid)
{
    new 
w_name[16];
    switch(
weaponid)
    {
        case 
0w_name "Fist";
        case 
24w_name "Deagle";
        case 
31w_name "M4";
        case 
30w_name "AK-47";
    }
     return 
w_name;

Maximum words per a weapon are 15. You don't need to create a string variable that has 24 + cells. Also, switch statement will do faster job than the if statement. This function is pretty small, why not optimize it properly? Also, stock keyword isn't required.

https://sampforum.blast.hk/showthread.php?tid=570635

Quote:
Originally Posted by OdgFox
Посмотреть сообщение
Thanks for the advice, so I had the code (by switch), I had to use formats to establish the cells of each name!
For someone who doesn't understand:
PHP код:
GetWeaponNameEx(weaponid

    new 
w_name[16]; 
    switch(
weaponid
    { 
        case 
0format(w_namesizeof w_name"Fist"); 
        case 
24format(w_namesizeof w_name"Deagle");
        case 
31format(w_namesizeof w_name"M4");
        case 
30format(w_namesizeof w_name"AK-47");
    } 
     return 
w_name

Reply


Messages In This Thread
Little help with weapons name :/ - by OdgFox - 01.02.2018, 01:40
Re: Little help with weapons name :/ - by Mugala - 01.02.2018, 09:20
Re: Little help with weapons name :/ - by Flamehaze7 - 01.02.2018, 09:58
Re: Little help with weapons name :/ - by OdgFox - 01.02.2018, 15:34
Re: Little help with weapons name :/ - by RogueDrifter - 01.02.2018, 15:37
Re: Little help with weapons name :/ - by Mugala - 01.02.2018, 16:56
Re: Little help with weapons name :/ - by Fratello - 01.02.2018, 19:06
Re: Little help with weapons name :/ - by Mugala - 01.02.2018, 19:22
Re: Little help with weapons name :/ - by Fratello - 01.02.2018, 19:25
Re: Little help with weapons name :/ - by OdgFox - 01.02.2018, 22:42

Forum Jump:


Users browsing this thread: 4 Guest(s)