string error rep++
#1

I have a variable 'shopname'
PHP код:
new shopname[128][128]; 
PHP код:
blah blah blah..................................................
format(shopname[26], sizeof(shopname), "Well Stacked Pizza Co");
format(stringsizeof(string), "You are in %s."shopname[26]);
SendClientMessage(playeridCOLOR_ORANGEstring); 
But, this gives me 'You are in .' , no shopname. Can someone tell me any idea about how to fix it?
Reply
#2

I tested and works fine for me, u use new string[128]; right?
Reply
#3

try to replace with this
pawn Код:
new shopname[128];
Reply
#4

I need to store both shop id and shop name to it, so I need to use shopname[128][128]
Reply
#5

why two array ? if you can make it one
example for Name
pawn Код:
new shopname[128];
format(shopname, sizeof(shopname), "Well Stacked Pizza Co");
format(string, sizeof(string), "You are in %s.", shopname[);
SendClientMessage(playerid, COLOR_ORANGE, string);

why you need a string to save id ? you can simple make variable to store id
pawn Код:
new ShopID;
Reply
#6

I need to store many shops's names in a variable.
I'm making a shop robbery.
Here's the code:

On top:
PHP код:
new robberytimer[128];
new 
robbing[128]=0;
new 
PlayerBar:robberybar[128];
new 
Text:robberytext;
new 
robbingcount[128]=0;
new 
shopunrobbable[128]=0;
new 
shopname[128][128]; 
OnGameModeInit
PHP код:
lspizza=CreateDynamicCP(376.4199,-119.9786,1001.4995,3,310,5,-1,25); 
OnPlayerEnterDynamicCP
PHP код:
if(checkpointid==lspizza)
    {
        
SendClientMessage(playeridCOLOR_ORANGE"Robbery: Type /robstore to rob this store.");
    } 
OnPlayerCommandText
PHP код:
    if(strcmp(cmdtext"/robstore"true20)==0)
    {
        new 
string[128], playername[128];
        if(
GetPlayerTeam(playerid)==TEAM_COPS || GetPlayerTeam(playerid)==TEAM_SWAT || GetPlayerTeam(playerid)==TEAM_ARMY || GetPlayerTeam(playerid)==TEAM_MEDICS) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: Your class cannot use this command.");
        if(
cuffed[playerid]==|| swatcuffed[playerid]==1) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: You cannot use this command while cuffed.");
        if(
IsPlayerInDynamicCP(playeridlspizza))
        {
            if(
shopunrobbable[lspizza]==1) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: The Well Stacked Pizza Co has been robbed recently.");
            
SendClientMessage(playeridCOLOR_ORANGE"Robbery: You have started to rob this shop. Do not leave the checkpoint until robbery is finished.");
            
SetTimerEx("ShopTimer"100000false"i"lspizza);
            
shopunrobbable[lspizza]=1;
            
robbing[playerid]=1;
            
robberybar[playerid]=CreatePlayerProgressBar(playerid265.000000362.000000126.00000021.000000118975871910BAR_DIRECTION_RIGHT);
            
TextDrawShowForPlayer(playeridrobberytext);
            
format(shopname[lspizza], sizeof(shopname), "Well Stacked Pizza Co");
            
robbingcount[playerid]=0;
            
robberytimer[playerid]=SetTimerEx("Robbery"1000true"iiii"playerid5000350010lspizza);
            
GetPlayerName(playeridplayernamesizeof(playername));
            for(new 
i=0i<MAX_PLAYERSi++)
            {
                new 
iteam=GetPlayerTeam(i);
                if(
iteam==TEAM_COPS || iteam==TEAM_SWAT || iteam==TEAM_ARMY)
                {
                      
format(stringsizeof(string), "Robbery: %s is currently robbing the Well Stacked Pizza Co., Idlewood."playername);
                    
SendClientMessage(iCOLOR_CRIMEstring);
                    
SendClientMessage(iCOLOR_CRIME"DISPATCH: All units in this area, please respond.");
                }
            }
            
wantedlevel[playerid]=wantedlevel[playerid]+5;
            
SetWanted(playeridwantedlevel[playerid]);
            
format(stringsizeof(string), "{%06x}(Crime committed) Wantedlevel: %d. Robbing."GetPlayerColor(playerid)>>>8wantedlevel[playerid]);
            
SendClientMessage(playeridCOLOR_WHITEstring);
        }
        else
        {
            
SendClientMessage(playeridCOLOR_ORANGE"ERROR: You are not in any robbery checkpoint");
        }
        return 
1;
    } 
Timer1:
PHP код:
forward Robbery (playeridmaxmoneyminmoneymaxvalueshopid);
public 
Robbery (playeridmaxmoneyminmoneymaxvalueshopid)
{
    if(
robbingcount[playerid]>maxvalue)
    {
        new 
playername[128], string[128], money;
        
TextDrawHideForPlayer(playeridrobberytext);
        
DestroyPlayerProgressBar(playeridrobberybar[playerid]);
        
KillTimer(robberytimer[playerid]);
        
money=random(maxmoney);
        while(
money<minmoney)
        {
            
money=money+500;
        }
        
GetPlayerName(playeridplayernamesizeof(playername));
        
format(stringsizeof(string), "%s has robbed $%d from the %s."playernamemoneyshopname[shopid]);
        
SendClientMessageToAll(COLOR_ORANGEstring);
        
PlayerInfo[playerid][pRobberies]++;
        
format(stringsizeof(string), "You have robbed this store and your robskill has been increased to %d."PlayerInfo[playerid][pRobberies]);
        
SendClientMessage(playeridCOLOR_PINKstring);
        
PlayerInfo[playerid][pCash]=PlayerInfo[playerid][pCash]+money;
        
ResetPlayerMoney(playerid);
        
GivePlayerMoney(playeridPlayerInfo[playerid][pCash]);
        
PlayerInfo[playerid][pScore]++;
        
robbing[playerid]=0;
        return 
1;
    }
    
robbingcount[playerid]++;
    
SetPlayerProgressBarValue(playeridrobberybar[playerid], robbingcount[playerid]);
    return 
1;

Timer2:
PHP код:
forward ShopTimer(shopid);
public 
ShopTimer(shopid)
{
    
shopunrobbable[shopid]=0;

OnPlayerLeaveDynamicCP
PHP код:
if(checkpointid==lspizza)
    {
        if(
robbing[playerid]==1)
        {
            
robbing[playerid]=0;
            
SendClientMessage(playeridCOLOR_ORANGE"You have left the checkpoint and hence the robbery has failed.");
            
KillTimer(robberytimer[playerid]);
            
TextDrawHideForPlayer(playeridrobberytext);
            
DestroyPlayerProgressBar(playeridrobberybar[playerid]);
        }
    } 
This is my code. I need to store all shops's name to one variable so that I can add more shops easily within /robstore command.
Reply
#7

replace with this
pawn Код:
forward Robbery (playerid, maxmoney, minmoney, maxvalue, shopid);
public Robbery (playerid, maxmoney, minmoney, maxvalue, shopid)
{
    if(robbingcount[playerid]>maxvalue)
    {
        new playername[128], string[128], money;
        TextDrawHideForPlayer(playerid, robberytext);
        DestroyPlayerProgressBar(playerid, robberybar[playerid]);
        KillTimer(robberytimer[playerid]);
        money=random(maxmoney);
        while(money<minmoney)
        {
            money=money+500;
        }
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "%s has robbed $%d from the %s (%i).", playername, money, shopname, shopid);
        SendClientMessageToAll(COLOR_ORANGE, string);
        PlayerInfo[playerid][pRobberies]++;
        format(string, sizeof(string), "You have robbed this store and your robskill has been increased to %d.", PlayerInfo[playerid][pRobberies]);
        SendClientMessage(playerid, COLOR_PINK, string);
        PlayerInfo[playerid][pCash]=PlayerInfo[playerid][pCash]+money;
        ResetPlayerMoney(playerid);
        GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
        PlayerInfo[playerid][pScore]++;
        robbing[playerid]=0;
        return 1;
    }
    robbingcount[playerid]++;
    SetPlayerProgressBarValue(playerid, robberybar[playerid], robbingcount[playerid]);
    return 1;
}
Reply
#8

Quote:
Originally Posted by ahmedkoki
Посмотреть сообщение
replace with this
pawn Код:
forward Robbery (playerid, maxmoney, minmoney, maxvalue, shopid);
public Robbery (playerid, maxmoney, minmoney, maxvalue, shopid)
{
    if(robbingcount[playerid]>maxvalue)
    {
        new playername[128], string[128], money;
        TextDrawHideForPlayer(playerid, robberytext);
        DestroyPlayerProgressBar(playerid, robberybar[playerid]);
        KillTimer(robberytimer[playerid]);
        money=random(maxmoney);
        while(money<minmoney)
        {
            money=money+500;
        }
        GetPlayerName(playerid, playername, sizeof(playername));
        format(string, sizeof(string), "%s has robbed $%d from the %s (%i).", playername, money, shopname, shopid);
        SendClientMessageToAll(COLOR_ORANGE, string);
        PlayerInfo[playerid][pRobberies]++;
        format(string, sizeof(string), "You have robbed this store and your robskill has been increased to %d.", PlayerInfo[playerid][pRobberies]);
        SendClientMessage(playerid, COLOR_PINK, string);
        PlayerInfo[playerid][pCash]=PlayerInfo[playerid][pCash]+money;
        ResetPlayerMoney(playerid);
        GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
        PlayerInfo[playerid][pScore]++;
        robbing[playerid]=0;
        return 1;
    }
    robbingcount[playerid]++;
    SetPlayerProgressBarValue(playerid, robberybar[playerid], robbingcount[playerid]);
    return 1;
}
Won't work for sure.
Reply
#9

pawn Код:
new shopname[128][128];
the second "128" between brackets is the length of the string (128 cells)
the first "128" between brackets is an array contents the slots
pawn Код:
format(shopname[26], sizeof(shopname), "Well Stacked Pizza Co");
format(string, sizeof(string), "You are in %s.", shopname[26]);
SendClientMessage(playerid, COLOR_ORANGE, string);
This is wrong, by that you are defining the "%s" , the 26 slot in the "shopname" array. make a single variable for each string:
pawn Код:
new sname[32];
format(sname, sizeof(sname), "Well Stacked Pizza Co");
format(string, sizeof(string), "You are in %s.", sname);
SendClientMessage(playerid, COLOR_ORANGE, string);
Otherwise,
pawn Код:
shopname[128][128]
, you are making a 128 slot array each slot contents 128 cells of string.
Reply
#10

But, how am I going to complete my command as SetTimerEx do not conducts string ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)