Little help with weapons name :/
#1

I need some help with my weapons system ... (how to get the ID of a weapon by its name), the problem is that I have changed the name of the weapons and I do not know how to recognize that name and get id .. Someone help me?

Код:
Dialog:ShowPlayerWeapons(playerid, response, listitem, inputtext[])
{
	if(response)
	{
			new caption[80];
			format(caption, sizeof(caption), "Arma: %s ID:%d", inputtext, ????? );
			Dialog_Show(playerid, ShowPlayerWeapons, DIALOG_STYLE_LIST, caption, "t\na\nt", "Aceptar", "Cancelar");
	}
	return true;
}
In this case, my character has 4 weapons, a baton, 9mm, a shotgun and a m4, when selecting one only takes the value of the m4 ..

My language is not English, but I am trying to learn it, greetings!
Reply
#2

you can use basic fuction GetWeaponName (https://sampwiki.blast.hk/wiki/GetWeaponName) to get name from weapon ID.
Reply
#3

Код:
GetPlayerWeaponData(playerid, slot, &weapons, &ammo)
https://sampwiki.blast.hk/wiki/GetPlayerWeaponData

You can use this to get the ID of a weapon, there's an example too inside the wiki link i posted.
Reply
#4

I already read about those functions, the problem is that I change the name of the weapons and they are displayed in Spanish, because of this I can not use those native functions, anyway I found the way but I think it will present bugs when it opens the server thanks anyway!
Reply
#5

Quote:
Originally Posted by OdgFox
Посмотреть сообщение
I already read about those functions, the problem is that I change the name of the weapons and they are displayed in Spanish, because of this I can not use those native functions, anyway I found the way but I think it will present bugs when it opens the server thanks anyway!
It doesn't matter! the way they posted gets the name THROUGH the id NOT the other way around so changing the weapons names is still up to you.
Reply
#6

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;

Reply
#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
#8

Quote:
Originally Posted by Fratello
Посмотреть сообщение
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
he's using his named weapons, so we dont know how many values are required, but yeah we can use cases and this way too, both is acceptable.
Reply
#9

Quote:
Originally Posted by Mugalito
Посмотреть сообщение
he's using his named weapons, so we dont know how many values are required, but yeah we can use cases and this way too, both is acceptable.
I thought so. Also, I'm sure that he will keep the original names. Yes, it is. Both scripts are going to do the job.
Reply
#10

Thanks for the advice, so I had the code (by switch), I had to use formats to establish the cells of each name!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)