How can i specify specific alphabetical character or Specific number

Kelvinvenema

  • Jr. Member
  • Posts: 51
Hello, guys, can someone help me out I have tried my best to find something related to Alphabetical character but I found nothing.
I already know how I can use IsNum:
But I would like to know how I can specify a certain  number like 1 or 9 //  or character like A or Z

I tried doing this for IsNum:

if(IsNum == 5) MessagePlayer ("You have typed number 5", player );

it won't work.
I don't know if there is a value I can use to specify a character for example

if(Charac == 'a') MessagePlayer("You have typed A",player);

Anyways thanks for reading greets Kelvin.

DarkRaZoR^

  • Full Member
  • VC:MP Battlefield Head Developer/KF Leader
  • Posts: 226

MatheuS

  • Wiki Contributor
  • LBR | Co-Leader & Brasil Real RPG | Developer
  • Posts: 465
Code: [Select]
if( !sucess ) tryAgain();

Thanks to the VCMP community. It was the happiest period of my life.

Kelvinvenema

  • Jr. Member
  • Posts: 51
Re: How can i specify specific alphabetical character or Specific number
« Reply #4,  »
Quote from MatheuS on February 4th, 2020, 05:22 PM
if(IsNum == 5) MessagePlayer ("You have typed number 5", player );
Code: [Select]
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );

if(Charac == 'a') MessagePlayer("You have typed A",player);
Code: [Select]
if(text.find( "a" ) != null ) MessagePlayer("You have typed A",player);
I really appreciate your help thanks :)
Re: How can i specify specific alphabetical character or Specific number
« Reply #5,  »
Quote from MatheuS on February 4th, 2020, 05:22 PM
if(IsNum == 5) MessagePlayer ("You have typed number 5", player );
Code: [Select]
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );

if(Charac == 'a') MessagePlayer("You have typed A",player);
Code: [Select]
if(text.find( "a" ) != null ) MessagePlayer("You have typed A",player);
I have tried using the if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );
I thought it worked when it pressed the button it outputted the right number but it also sends a message when the number isn't 5 what is wrong with the line it doesn't give me any errors


DraGone

  • Newbie
  • Posts: 5
Re: How can i specify specific alphabetical character or Specific number
« Reply #6,  »Last edited
You just need to use IsNum() function if you want to check whether the text is a number..

You dont necessarily need to check whether the text is number if you just want to compare two string. You can just do it right away, e.g:
Code: [Select]
function onPlayerCommand(player, command, text)
{
// Remember, 'text' is a string by default, no matter you typed a number or anything
// Or it is simply null if player left it empty

if ( command == "test" )
{
/* Only proceed if 'text' is not null because we cant compare 'null' with a string */
if ( text != null )
{
/* Compare the 'text' with string '5', notice "5" is a string not integer */
if ( text == "5" ) PrivMessage( player, "You just typed: 5" );
else if ( text == "a" ) PrivMessage( player, "You just typed: a" );
}
}
}

You just need to use IsNum if you really want and need the text to be number, e.g.
Code: [Select]
function onPlayerCommand(player, command, text)
{
if ( command == "givemecash" )
{
/* Only proceed if 'text' is not null because IsNum function only accept string */
if ( text != null )
{
/* Check whether the 'text' is a number using IsNum function */
/* If it return true, that means the the text is indeed a number */
if ( IsNum( text ) == true )
{
/* Convert 'text' from string to integer. In this example we are going to increase player's cash so it must be integer */
text = text.tointeger( );

/* Compare 'text' with integer 0, we can compare it with integer cuz we already converted it to integer just now */
if ( text <= 0 ) PrivMessage( player, "Hey, the amount must be higher than 0!" );
else
{
player.Cash += text;
PrivMessage( player, "You just got $"+ text +"!" );
}
}
else
{
PrivMessage( player, "Hey, "+ text +" is not a number!" );
}
}
else PrivMessage( player, "Please specify how much you need" );
}
}

The codes above are untested, it's just an example!

Kelvinvenema

  • Jr. Member
  • Posts: 51
Re: How can i specify specific alphabetical character or Specific number
« Reply #7,  »
Quote from DraGone on February 5th, 2020, 04:09 AM
You just need to use IsNum() function if you want to check whether the text is a number..

You dont necessarily need to check whether the text is number if you just want to compare two string. You can just do it right away, e.g:
Code: [Select]
function onPlayerCommand(player, command, text)
{
// Remember, 'text' is a string by default, no matter you typed a number or anything
// Or it is simply null if player left it empty

if ( command == "test" )
{
/* Only proceed if 'text' is not null because we cant compare 'null' with a string */
if ( text != null )
{
/* Compare the 'text' with string '5', notice "5" is a string not integer */
if ( text == "5" ) PrivMessage( player, "You just typed: 5" );
else if ( text == "a" ) PrivMessage( player, "You just typed: a" );
}
}
}

You just need to use IsNum if you really want and need the text to be number, e.g.
Code: [Select]
function onPlayerCommand(player, command, text)
{
if ( command == "givemecash" )
{
/* Only proceed if 'text' is not null because IsNum function only accept string */
if ( text != null )
{
/* Check whether the 'text' is a number using IsNum function */
/* If it return true, that means the the text is indeed a number */
if ( IsNum( text ) == true )
{
/* Convert 'text' from string to integer. In this example we are going to increase player's cash so it must be integer */
text = text.tointeger( );

/* Compare 'text' with integer 0, we can compare it with integer cuz we already converted it to integer just now */
if ( text <= 0 ) PrivMessage( player, "Hey, the amount must be higher than 0!" );
else
{
player.Cash += text;
PrivMessage( player, "You just got $"+ text +"!" );
}
}
else
{
PrivMessage( player, "Hey, "+ text +" is not a number!" );
}
}
else PrivMessage( player, "Please specify how much you need" );
}
}

The codes above are untested, it's just an example!
Thanks, you now I understand how I can interpret them in my codes and my commands
Using this

local TextSplit = split( text, " " ),let1=TextSplit[ 0 ],num1=TextSplit[ 1 ];

I can name my text whatever I want
for example

  local TextSplit = split( text, " " ),let1=TextSplit[ 0 ],num1=TextSplit[ 1 ];
   if (( let1 == "5") && (num1 == "a")) PrivMessage( player, "You just typed: "+let1+", "+num1+" " );