PDA

View Full Version : checking if the wep name is valid


MattSlater
27/12/2012, 10:22 PM
Okay, I have a dialog
'ShowPlayerDialog(playerid, DIALOG_CARTRUNKDEPOSIT, DIALOG_STYLE_INPUT, "[ VEHICLE TRUNK ]", "Enter the weapon you wish to deposit into the trunk.", "Deposit", "Close");'

How can I make it check if the weapon name they enter is valid on the response?

Like if I enter: 'This isn't a gun!' it will say Invalid gun name

And then if I type 'Desert Eagle' it will succeed and say i deposited it(I can do the deposit bit)

Threshold
27/12/2012, 11:36 PM
Okay here's an example:

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_CARTRUNKDEPOSIT)
{
if(response)
{
if(!IsValidWeaponName(inputtext)) return SendClientMessage(playerid, 0xFF0000FF, "You have entered an invalid gun name.");
//Put gun in trunk
//code continues
}
}
return 0;
}

Now as you may have realised... IsValidWeaponName is not an actual function, so I have made a stock function that should operate properly.

stock IsValidWeaponName(name[])
{
if(strcmp(name, "9mm", true) == 0) return true;
else if(strcmp(name, "colt", true) == 0) return true;
else if(strcmp(name, "silenced 9mm", true) == 0) return true;
else if(strcmp(name, "silenced colt", true) == 0) return true;
else if(strcmp(name, "desert eagle", true) == 0) return true;
else if(strcmp(name, "deagle", true) == 0) return true;
else if(strcmp(name, "shotgun", true) == 0) return true;
else if(strcmp(name, "sawnoff shotgun", true) == 0) return true;
else if(strcmp(name, "sawnoff", true) == 0) return true;
else if(strcmp(name, "combat shotgun", true) == 0) return true;
else if(strcmp(name, "spaz", true) == 0) return true;
else if(strcmp(name, "spaz12", true) == 0) return true;
else if(strcmp(name, "spaz 12", true) == 0) return true;
else if(strcmp(name, "micro smg", true) == 0) return true;
else if(strcmp(name, "smg", true) == 0) return true;
else if(strcmp(name, "uzi", true) == 0) return true;
else if(strcmp(name, "mini uzi", true) == 0) return true;
else if(strcmp(name, "mp5", true) == 0) return true;
else if(strcmp(name, "ak-47", true) == 0) return true;
else if(strcmp(name, "ak47", true) == 0) return true;
else if(strcmp(name, "ak 47", true) == 0) return true;
else if(strcmp(name, "m4", true) == 0) return true;
else if(strcmp(name, "tec 9", true) == 0) return true;
else if(strcmp(name, "tec9", true) == 0) return true;
else if(strcmp(name, "country rifle", true) == 0) return true;
else if(strcmp(name, "rifle", true) == 0) return true;
else if(strcmp(name, "sniper rifle", true) == 0) return true;
else if(strcmp(name, "sniper", true) == 0) return true;
else if(strcmp(name, "rpg", true) == 0) return true;
else if(strcmp(name, "rocket launcher", true) == 0) return true;
else if(strcmp(name, "heatseeker", true) == 0) return true;
else if(strcmp(name, "flamethrower", true) == 0) return true;
else if(strcmp(name, "flame thrower", true) == 0) return true;
else if(strcmp(name, "minigun", true) == 0) return true;
else if(strcmp(name, "mini gun", true) == 0) return true;
return false;
}

This may not be the most effective method to doing it, but it should work. I have also added slang terms such as 'colt' etc. so that players have more than 1 option.