Converting to zcmd
#1

A friend of mine asked me to convert this command to zcmd which i taught it was going to be easy, but i have no experience with strcmp so i would just like someone to give me some explanation on some lines
PHP код:
     if(strcmp(cmd"/bet"true) == 0)
    {
        if(
IsPlayerConnected(playerid))
        {
            if(
BizzInfo[PlayerInfo[playerid][InBusiness]][bType] == 5)
            {
                if(!
IsAtRLTable(playerid))
                {
                    
SendClientMessage(playeridCOLOR_GREY"   You are not near a Roulette table!");
                    return 
1;
                }
                 new 
ball random(4);
                
tmp strtok(cmdtextidx);//what does this line do
                  
if(!strlen(tmp))//what does this line do
                
{
                    
SendClientMessage(playeridCOLOR_WHITE"USAGE: /bet [red/black] [amount]");
                    return 
1;
                }
                if(
strcmp(tmp,"red",true) == 0)//what does this line do
                
{
                    
tmp strtok(cmdtextidx);//what does this line do
                    
if(!strlen(tmp))
                    {
                        
SendClientMessage(playeridCOLOR_WHITE"USAGE: /bet [red/black] [amount]");
                        return 
1;
                    }
                    new 
mred strvalEx(tmp);//what does this line do
                    
if(mred || mred 10000)
                    {
                        
SendClientMessage(playeridCOLOR_GREY"   Bet can't be below $0 or above $10,000!");
                        return 
1;
                    }
                       
GetPlayerName(playeridsendernamesizeof(sendername));
                       if(
ball == 1)
                    {
                        if(
PlayerInfo[playerid][pMask] == 1format(stringsizeof(string), "* Stranger beats on red and won.");
                           else 
format(stringsizeof(string), "* %s bets on red and won."sendername);
                        
ProxDetector(5.0playeridstringCOLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
                        
format(stringsizeof(string), "* You won $%d."mred);
                        
SendClientMessage(playeridCOLOR_GREENstring);
                        
PlayerInfo[playerid][pCash] += mred;
                        
GivePlayerMoney(playeridmred);
                        
BizzInfo[PlayerInfo[playerid][InBusiness]][bTill] -= mred;
                    }
                    else
                    {
                           if(
PlayerInfo[playerid][pMask] == 1format(stringsizeof(string), "* Stranger beats on red and lost.");
                        else 
format(stringsizeof(string), "* %s bets on red and lost."sendername);
                        
ProxDetector(5.0playeridstringCOLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
                        
format(stringsizeof(string), "* You lost $%d."mred);
                        
SendClientMessage(playeridCOLOR_LIGHTREDstring);
                         
PlayerInfo[playerid][pCash] -= mred;
                         
GivePlayerMoney(playerid, -mred);
                        
BizzInfo[PlayerInfo[playerid][InBusiness]][bTill] += mred;
                    }
                }
                if(
strcmp(tmp,"black",true) == 0)//what does this line do
                
{
                      
tmp strtok(cmdtextidx);//what does this line do
                      
if(!strlen(tmp))//what does this line do
                    
{
                        
SendClientMessage(playeridCOLOR_WHITE"USAGE: /bet [black/red] [amount]");
                        return 
1;
                    }
                    new 
mblack strvalEx(tmp);
                    if(
mblack || mblack 10000)
                    {
                        
SendClientMessage(playeridCOLOR_GREY"   Bet can't be below $0 or above $10,000!");
                        return 
1;
                    }
                    
GetPlayerName(playeridsendernamesizeof(sendername));
                    if(
ball == 1)
                    {
                        if(
PlayerInfo[playerid][pMask] == 1format(stringsizeof(string), "* Stranger beats on black and won.");
                        else 
format(stringsizeof(string), "* %s bets on black and won."sendername);
                        
ProxDetector(5.0playeridstringCOLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
                        
format(stringsizeof(string), "* You won $%d."mblack);
                        
SendClientMessage(playeridCOLOR_GREENstring);
                        
PlayerInfo[playerid][pCash] += mblack;
                        
GivePlayerMoney(playeridmblack);
                         
BizzInfo[PlayerInfo[playerid][InBusiness]][bTill] -= mblack;
                    }
                    else
                    {
                        if(
PlayerInfo[playerid][pMask] == 1format(stringsizeof(string), "* Stranger beats on black and lost.");
                        else 
format(stringsizeof(string), "* %s bets on black and lost."sendername);
                         
ProxDetector(5.0playeridstringCOLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
                        
format(stringsizeof(string), "* You lost $%d."mblack);
                        
SendClientMessage(playeridCOLOR_LIGHTREDstring);
                         
PlayerInfo[playerid][pCash] -= mblack;
                         
GivePlayerMoney(playerid, -mblack);
                         
BizzInfo[PlayerInfo[playerid][InBusiness]][bTill] += mblack;
                    }
                }
            } 
Can someone explain what those line mean and what it would look like in zcmd?
Reply
#2

Just search:
https://sampforum.blast.hk/showthread.php?tid=280282

This should pretty much answer all your questions. Take your time and read through it ^_^
Reply
#3

Just saying, that's very basic if it's roulette, as roulette has a lot more than just red and black.

You can play thirds, and specific numbers boosting the payouts. There are other options as well, but really, red and black, is simply a TINY fraction of what roulette is.

Reply
#4

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
Just search:
https://sampforum.blast.hk/showthread.php?tid=280282

This should pretty much answer all your questions. Take your time and read through it ^_^
I have red and understand everything and i attempted to make the changes which turned out successfully, but there is a small bug... When i tried to test it , i bet on black , but it keeps on sending these message at the sametime doesn't matter which bet you made.
PHP код:
  format(stringsizeof(string), "* %s bets on red and won."GetName(playerid));
                    
ProxDetector(5.0playeridstring, -1);
                    
format(stringsizeof(string), "* You won $%d."mred);
                    
SendClientMessage(playerid, -1string);
                
format(stringsizeof(string), "* %s bets on red and lost.",  GetName(playerid));
                    
ProxDetector(5.0playeridstring,-1);
                    
format(stringsizeof(string), "* You lost $%d."mred);
                    
SendClientMessage(playerid, -1string); 
Doesnt matter which bet you make it will return the two message's

here is the code once i transfered it to zcmd
PHP код:
CMD:bet(playerid,params[])
{
    new 
option[64],string[128];
    if(
IsPlayerConnected(playerid))
    {
           new 
idx GetPlayerVirtualWorld(playerid)-100;
        if(
BizInfo[idx][bType] == 7)
         {
              if(!
IsAtRLTable(playerid))
               {
                   
SendClientMessage(playeriderror"You are not near a Roulette table!");
                   return 
1;
            }
               new 
ball random(4);
            if(!
strcmp(option"red"true))
            {
                new 
mred strvalEx(option);
                if(
sscanf(params"s[8]i"optionmred)) return SendClientMessage(playeriderror"Usage: /bet [Red/Black][$Amount]");
                if(
mred || mred 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
                if(
ball == 1)
                   {
                    
format(stringsizeof(string), "* %s bets on red and won."GetName(playerid));
                    
ProxDetector(5.0playeridstring, -1);
                    
format(stringsizeof(string), "* You won $%d."mred);
                    
SendClientMessage(playerid, -1string);
                    
pInfo[playerid][Cash] += mred;
                    
GivePlayerCash(playeridmred);
                    
BizInfo[idx][bMoney] -= mred;
                }
                else
                {
                       
format(stringsizeof(string), "* %s bets on red and lost.",  GetName(playerid));
                    
ProxDetector(5.0playeridstring,-1);
                    
format(stringsizeof(string), "* You lost $%d."mred);
                    
SendClientMessage(playerid, -1string);
                     
pInfo[playerid][Cash] -= mred;
                     
GivePlayerCash(playerid, -mred);
                    
BizInfo[idx][bMoney] += mred;
                }
                   if(!
strcmp(option"black"true))
                {
                      new 
mblack strvalEx(option);
                    if(
sscanf(params"s[8]i"option,mblack)) return SendClientMessage(playeriderror"Usage: /bet [Red/Black][$Amount]");
                    if(
mblack || mblack 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
                     if(
ball == 1)
                    {
                        
format(stringsizeof(string), "* %s bets on black and won."GetName(playerid));
                        
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You won $%d."mblack);
                        
SendClientMessage(playerid, -1string);
                        
pInfo[playerid][Cash] += mblack;
                        
GivePlayerCash(playeridmblack);
                        
BizInfo[idx][bMoney] -= mblack;
                    }
                    else
                    {
                        
format(stringsizeof(string), "* %s bets on black and lost.",  GetName(playerid));
                         
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You lost $%d."mblack);
                        
SendClientMessage(playerid, -1string);
                         
pInfo[playerid][Cash] -= mblack;
                         
GivePlayerMoney(playerid, -mblack);
                         
BizInfo[idx][bMoney] += mblack;
                    }
                }
            }
        }
    }
    return 
1;

Reply
#5

PHP код:
if(!strcmp(option"red"true)) 
This line will always return 1, ie, The strings will never be the same. Because the string option is empty. And You are setting the option inside the if. So that code will never run. I don't know anything about roulette cuz' I haven't played the game at all. So If you could tell me what you are trying to do here, I will help
Reply
#6

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
PHP код:
if(!strcmp(option"red"true)) 
This line will always return 1, ie, The strings will never be the same. Because the string option is empty. And You are setting the option inside the if. So that code will never run. I don't know anything about roulette cuz' I haven't played the game at all. So If you could tell me what you are trying to do here, I will help
In the line you specified , i trying to see which option the player has choosen to bet on.. So say the player choose red(/bet red 1000). that line is the option otherwise if the player bet black(/bet black 1000)
Reply
#7

PHP код:
CMD:bet(playerid,params[])
{
    new 
option[64],string[128], amount;
    new 
idx GetPlayerVirtualWorld(playerid)-100;
    if(
BizInfo[idx][bType] == 7)
         {
              if(!
IsAtRLTable(playerid))
               {
                   
SendClientMessage(playeriderror"You are not near a Roulette table!");
                   return 
1;
            }
               new 
ball random(4);
            if(
sscanf(params"s[8]i"option,amount)) return SendClientMessage(playeriderror"Usage: /bet [Red/Black][$Amount]");
            if(
amount || amount 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
            if(!
strcmp(option"red"true))
            {
                
                if(
ball == 1)
                   {
                    
format(stringsizeof(string), "* %s bets on red and won."GetName(playerid));
                    
ProxDetector(5.0playeridstring, -1);
                    
format(stringsizeof(string), "* You won $%d."amount);
                    
SendClientMessage(playerid, -1string);
                    
pInfo[playerid][Cash] += amount;
                    
GivePlayerCash(playeridamount);
                    
BizInfo[idx][bMoney] -= amount;
                }
                else
                {
                       
format(stringsizeof(string), "* %s bets on red and lost.",  GetName(playerid));
                    
ProxDetector(5.0playeridstring,-1);
                    
format(stringsizeof(string), "* You lost $%d."amount);
                    
SendClientMessage(playerid, -1string);
                     
pInfo[playerid][Cash] -= amount;
                     
GivePlayerCash(playerid, -amount);
                    
BizInfo[idx][bMoney] += amount;
                }
            if(!
strcmp(option"black"true))
                {
                    if(
mblack || mblack 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
                     if(
ball == 1)
                    {
                        
format(stringsizeof(string), "* %s bets on black and won."GetName(playerid));
                        
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You won $%d."amount);
                        
SendClientMessage(playerid, -1string);
                        
pInfo[playerid][Cash] += amount;
                        
GivePlayerCash(playeridamount);
                        
BizInfo[idx][bMoney] -= amount;
                    }
                    else
                    {
                        
format(stringsizeof(string), "* %s bets on black and lost.",  GetName(playerid));
                         
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You lost $%d."amount);
                        
SendClientMessage(playerid, -1string);
                         
pInfo[playerid][Cash] -= amount;
                         
GivePlayerMoney(playerid, -amount);
                         
BizInfo[idx][bMoney] += amount;
                    }
                }
            }
        }
    return 
1;

Try this. What I've done is I removed the IsPlayerConnected check, I added the sscanf at the top and used a common variable 'amount' instead of 'mred' and 'mblack'.

EDIT: I've edited the code a bit. Try this
Reply
#8

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
PHP код:
CMD:bet(playerid,params[])
{
    new 
option[64],string[128], amount;
    new 
idx GetPlayerVirtualWorld(playerid)-100;
    if(
BizInfo[idx][bType] == 7)
         {
              if(!
IsAtRLTable(playerid))
               {
                   
SendClientMessage(playeriderror"You are not near a Roulette table!");
                   return 
1;
            }
               new 
ball random(4);
            if(
sscanf(params"s[8]i"option,amount)) return SendClientMessage(playeriderror"Usage: /bet [Red/Black][$Amount]");
            if(
amount || amount 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
            if(!
strcmp(option"red"true))
            {
                
                if(
ball == 1)
                   {
                    
format(stringsizeof(string), "* %s bets on red and won."GetName(playerid));
                    
ProxDetector(5.0playeridstring, -1);
                    
format(stringsizeof(string), "* You won $%d."amount);
                    
SendClientMessage(playerid, -1string);
                    
pInfo[playerid][Cash] += amount;
                    
GivePlayerCash(playeridamount);
                    
BizInfo[idx][bMoney] -= amount;
                }
                else
                {
                       
format(stringsizeof(string), "* %s bets on red and lost.",  GetName(playerid));
                    
ProxDetector(5.0playeridstring,-1);
                    
format(stringsizeof(string), "* You lost $%d."amount);
                    
SendClientMessage(playerid, -1string);
                     
pInfo[playerid][Cash] -= amount;
                     
GivePlayerCash(playerid, -amount);
                    
BizInfo[idx][bMoney] += amount;
                }
            if(!
strcmp(option"black"true))
                {
                    if(
mblack || mblack 50000) return SendClientMessage(playeriderror"Bet can't be below $1 or above $50,000!");
                     if(
ball == 1)
                    {
                        
format(stringsizeof(string), "* %s bets on black and won."GetName(playerid));
                        
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You won $%d."amount);
                        
SendClientMessage(playerid, -1string);
                        
pInfo[playerid][Cash] += amount;
                        
GivePlayerCash(playeridamount);
                        
BizInfo[idx][bMoney] -= amount;
                    }
                    else
                    {
                        
format(stringsizeof(string), "* %s bets on black and lost.",  GetName(playerid));
                         
ProxDetector(5.0playeridstring, -1);
                        
format(stringsizeof(string), "* You lost $%d."amount);
                        
SendClientMessage(playerid, -1string);
                         
pInfo[playerid][Cash] -= amount;
                         
GivePlayerMoney(playerid, -amount);
                         
BizInfo[idx][bMoney] += amount;
                    }
                }
            }
        }
    return 
1;

Try this. What I've done is I removed the IsPlayerConnected check, I added the sscanf at the top and used a common variable 'amount' instead of 'mred' and 'mblack'.

EDIT: I've edited the code a bit. Try this
i tested the code you gave me and there were some errors here and there but i fixed them all...Thanks you very very very much for taking the time out to help me...REP+
Reply
#9

There were errors because I couldn't test the code. I just used an online text editor to edit stuff. Notepad was too much for me xD. You're Welcome!
Reply
#10

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
I added the sscanf at the top and used a common variable 'amount' instead of 'mred' and 'mblack'.
Good spotting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)