#1

Hi Guys
i have small problems my Code no effect in my Server
PHP код:
public OnPlayerText(playeridtext[])
{
    if(
text[0] == '1')
    {
        if(
FirstWeaponText[playerid] == 1)
        {
           new 
Amount;
           if( 
sscanf text[1], "i",Amount))  return SendClientMessage(playerid,-1"[amount]");// amount he wants.
           
if(Amount || Amount 10000) return SendClientMessage(playerid,-1,"You can only buy from 1 - 10000 bullets");// check if player has writen more than required
           
{
               
GivePlayerMoney(playerid,-Amount*100); // this makes 1 bullet for 100$
               
GivePlayerWeapon(playeridWEAPON_M4Amount);
           }
        }
    } 
i tired to Type 1 in chat after that's i Type Amount Ammo i needed not working why ?
Reply
#2

as i know you should remov brackers

PHP код:
 if(Amount || Amount 10000) return SendClientMessage(playerid,-1,"You can only buy from 1 - 10000 bullets");// check if player has writen more than required 
           
// This one 
               
GivePlayerMoney(playerid,-Amount*100); // this makes 1 bullet for 100$ 
               
GivePlayerWeapon(playeridWEAPON_M4Amount); 
           } 
// and this one 
i realy dont know why u put them there :S cus of that last if statement u used a return value

Sorry for my bad eng
Reply
#3

[QUOTE=khRamin78;3864803]as i know you should remov brackers

PHP код:
public OnPlayerText(playeridtext[])
{
    if(
text[0] == '1')
    {
        if(
FirstWeaponText[playerid] == 1)
        {
           new 
Amount;
           if( 
sscanf text[1], "i",Amount))  return SendClientMessage(playerid,-1"[amount]");// amount he wants.
           
// This one
               
GivePlayerMoney(playerid,-Amount*100); // this makes 1 bullet for 100$
               
GivePlayerWeapon(playeridWEAPON_M4Amount);
           } 
// and this one
         
}
    } 
its working only when i write in chat 1 100
give me 100 ammo
i want making it when i'm write 1 in chat after that's write my amount ammo in chat
Reply
#4

[QUOTE=astanalol;3864817]
Quote:
Originally Posted by khRamin78
Посмотреть сообщение
as i know you should remov brackers

PHP код:
public OnPlayerText(playeridtext[])
{
    if(
text[0] == '1')
    {
        if(
FirstWeaponText[playerid] == 1)
        {
           new 
Amount;
           if( 
sscanf text[1], "i",Amount))  return SendClientMessage(playerid,-1"[amount]");// amount he wants.
           
// This one
               
GivePlayerMoney(playerid,-Amount*100); // this makes 1 bullet for 100$
               
GivePlayerWeapon(playeridWEAPON_M4Amount);
           } 
// and this one
         
}
    } 
its working only when i write in chat 1 100
give me 100 ammo
i want making it when i'm write 1 in chat after that's write my amount ammo in chat
Bump!!
Reply
#5

I think you want something like that:

PHP код:
public OnPlayerText(playeridtext[]) 
{  
    if(
FirstWeaponText[playerid] == 1
    { 
        if(!
isNumeric(text))
        {
            
SendClientMessage(playerid,-1"[Enter only digits]");// amount he wants.
            
return 0;
        }
         
        if(
strval(text) < || strval(text) > 10000)
        {
            
SendClientMessage(playerid,-1,"You can only buy from 1 - 10000 bullets");// check if player has writen more than required 
            
return 0;
        }
        
GivePlayerMoney(playerid,-strval(text)*100); // this makes 1 bullet for 100$ 
        
GivePlayerWeapon(playeridWEAPON_M4strval(text)); 
        
FirstWeaponText[playerid] = 0;
        return 
0;
    }
    else
    {
        if(!
strcmp(text"1")) 
        {
            
FirstWeaponText[playerid] = 1;
            
SendClientMessage(playerid, -1"Enter the amount of ammo:");
            return 
0;
        }
    }
    return 
1;

Reply
#6

Quote:
Originally Posted by XpDeviL
Посмотреть сообщение
I think you want something like that:

PHP код:
public OnPlayerText(playeridtext[]) 
{  
    if(
FirstWeaponText[playerid] == 1
    { 
        if(!
isNumeric(text))
        {
            
SendClientMessage(playerid,-1"[Enter only digits]");// amount he wants.
            
return 0;
        }
         
        if(
strval(text) < || strval(text) > 10000)
        {
            
SendClientMessage(playerid,-1,"You can only buy from 1 - 10000 bullets");// check if player has writen more than required 
            
return 0;
        }
        
GivePlayerMoney(playerid,-strval(text)*100); // this makes 1 bullet for 100$ 
        
GivePlayerWeapon(playeridWEAPON_M4strval(text)); 
        
FirstWeaponText[playerid] = 0;
        return 
0;
    }
    else
    {
        if(!
strcmp(text"1")) 
        {
            
FirstWeaponText[playerid] = 1;
            
SendClientMessage(playerid, -1"Enter the amount of ammo:");
            return 
0;
        }
    }
    return 
1;

error
Quote:

(389) : error 017: undefined symbol "isNumeric"

PHP код:
if(!isNumeric(text)) 
Reply
#7

PHP код:
stock isNumeric(const string[])
{
 new 
length=strlen(string);
 if (
length==0) return false;
 for (new 
0lengthi++)
  {
   if (
      (
string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+'// Not a number,'+' or '-'
       
|| (string[i]=='-' && i!=0)                       // A '-' but not at first.
       
|| (string[i]=='+' && i!=0)                       // A '+' but not at first.
     
) return false;
  }
 if (
length==&& (string[0]=='-' || string[0]=='+')) return false;
 return 
true;

Reply
#8

Quote:
Originally Posted by XpDeviL
Посмотреть сообщение
PHP код:
stock isNumeric(const string[])
{
 new 
length=strlen(string);
 if (
length==0) return false;
 for (new 
0lengthi++)
  {
   if (
      (
string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+'// Not a number,'+' or '-'
       
|| (string[i]=='-' && i!=0)                       // A '-' but not at first.
       
|| (string[i]=='+' && i!=0)                       // A '+' but not at first.
     
) return false;
  }
 if (
length==&& (string[0]=='-' || string[0]=='+')) return false;
 return 
true;

fucking awesome thanks man working prefct +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)