Little help with weapons name :/ -
OdgFox - 01.02.2018
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!
Re: Little help with weapons name :/ -
Mugala - 01.02.2018
you can use basic fuction GetWeaponName (
https://sampwiki.blast.hk/wiki/GetWeaponName) to get name from weapon ID.
Re: Little help with weapons name :/ -
Flamehaze7 - 01.02.2018
Код:
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.
Re: Little help with weapons name :/ -
OdgFox - 01.02.2018
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!
Re: Little help with weapons name :/ -
RogueDrifter - 01.02.2018
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.
Re: Little help with weapons name :/ -
Mugala - 01.02.2018
you can use this if u want to define names by yourself.
PHP код:
stock GetWeaponNameEx(weaponid)
{
new wname[64];
if(weaponid == 0) wname = "Fist";
if(weaponid == 31) wname = "M4";
if(weaponid == 30) wname = "AK-47";
/// u can add the weaponids an names by yourself.
return wname;
}
Re: Little help with weapons name :/ -
Fratello - 01.02.2018
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 == 0) wname = "Fist";
if(weaponid == 31) wname = "M4";
if(weaponid == 30) wname = "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 0: w_name = "Fist";
case 24: w_name = "Deagle";
case 31: w_name = "M4";
case 30: w_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 0: format(w_name, sizeof w_name, "Fist");
case 24: format(w_name, sizeof w_name, "Deagle");
case 31: format(w_name, sizeof w_name, "M4");
case 30: format(w_name, sizeof w_name, "AK-47");
}
return w_name;
}
Re: Little help with weapons name :/ -
Mugala - 01.02.2018
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 0: w_name = "Fist";
case 24: w_name = "Deagle";
case 31: w_name = "M4";
case 30: w_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.
Re: Little help with weapons name :/ -
Fratello - 01.02.2018
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.
Re: Little help with weapons name :/ -
OdgFox - 01.02.2018
Thanks for the advice, so I had the code (by switch), I had to use formats to establish the cells of each name!