CMD /v color c1 c2
#1

hi, doesn't working this command. Help me :C
PHP код:
CMD:v(playeridparams[])
{
 if(!
strcmp(params"color"true))
    {
        new 
c[2];
//        if(pInfo[playerid][VipLevel] == 0) return ErrorMessages(playerid, 4);
          
if(strcmp(GetPlayerName(playerid), vInfo[id][vowner], true)) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" This is not your vehicle");
          if(
sscanf(params,"sii"paramsc[0], c[1])) return SendClientMessage(playeridCOLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");
          else if(
c[0] > 255) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" Cannot go above 255!");
          else if(
c[1] > 255) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" Cannot go above 255!");
          if(
id != 0)
        {
              
vInfo[id][vcolor1] = c[0];
            
vInfo[id][vcolor2] = c[1];
              
ChangeVehicleColor(vehicleidc[0], c[1]);
              
format(fquery,sizeof(fquery), "UPDATE `vehicles` SET Color1 = '%d', Color2 = '%d' WHERE ID = '%d'"DB_Escape(vInfo[id][vcolor1]), DB_Escape(vInfo[id][vcolor2]), id);
             
db_free_result(db_query(Databasefquery));
              
format(fquerysizeof(fquery), "[VEHICLE]"COL_WHITE" You've changed the primary color %i and secondary %i"c[0], c[1]);
              
SendClientMessage(playeridCOLOR_SERVERfquery);
        }
        else return 
ErrorMessages(playerid13);
    }
 return 
1;

Reply
#2

What your commands checks is "/v color". Since you have parameters for "color" option, you'll need to use 4th parameter (length) in strcmp function.

pawn Код:
// if player inputs only the name of the option, return them the usage
if(!strcmp(params, "color", true)) return SendClientMessage(playerid, COLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");

// if player inputs "/v color " may or may not have parameters following, sscanf will react accordingly
// 6 is the length of the option + a space at the end
if (!strcmp(params, "color ", true, 6))
{
    new c[2];

    if(sscanf(params[6], "ii", c[0], c[1])) return SendClientMessage(playerid, COLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");

    // code..
}
And try to remember what advises people give you: http://forum.sa-mp.com/showpost.php?...04&postcount=4
Only strings need to be escaped and there's no need of DB_Escape anymore - there is now a %q specifier for format function that does the job for you.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
What your commands checks is "/v color". Since you have parameters for "color" option, you'll need to use 4th parameter (length) in strcmp function.

pawn Код:
// if player inputs only the name of the option, return them the usage
if(!strcmp(params, "color", true)) return SendClientMessage(playerid, COLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");

// if player inputs "/v color " may or may not have parameters following, sscanf will react accordingly
// 6 is the length of the option + a space at the end
if (!strcmp(params, "color ", true, 6))
{
    new c[2];

    if(sscanf(params[6], "ii", c[0], c[1])) return SendClientMessage(playerid, COLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");

    // code..
}
And try to remember what advises people give you: http://forum.sa-mp.com/showpost.php?...04&postcount=4
Only strings need to be escaped and there's no need of DB_Escape anymore - there is now a %q specifier for format function that does the job for you.
Oh thanks, ohh yes sorry. example use %q:

PHP код:

    format
(hInfo[IID][hName], MAX_PLAYER_NAME"%s"inputtext);
            
format(fquerysizeof(fquery), "UPDATE `Houses` SET Title = '%q' WHERE `ID` = '%d'"hInfo[IID][hName], IID);
            
db_free_result(db_query(Databasefquery)); 
correct?
Reply
#4

PHP код:
CMD:v(playeridparams[])
{
if(
isnull(params)) return SendClientMessage(playeridCOLOR_ORANGE,"Usage:"COL_WHITE" /v [BUY/SELL/LOCK/PARK/RESPAWN]");
 
// if player inputs only the name of the option, return them the usage
    
if(!strcmp(params"color"true)) return SendClientMessage(playeridCOLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");
    
// if player inputs "/v color " may or may not have parameters following, sscanf will react accordingly
    // 6 is the length of the option + a space at the end
    
if (!strcmp(params"color "true6))
    {
        new 
c[2];
        if(!
IsPlayerInAnyVehicle(playerid)) return ErrorMessages(playerid11);
//        if(pInfo[playerid][VipLevel] == 0) return ErrorMessages(playerid, 4);
          
if(strcmp(GetPlayerName(playerid), vInfo[id][vowner], true)) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" This is not your vehicle");
          if(
sscanf(params[6], "ii"c[0], c[1])) return SendClientMessage(playeridCOLOR_ORANGE,"Usage:"COL_WHITE" /v color [COLOR 1] [COLOR 2]");
          else if(
c[0] > 255) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" Cannot go above 255!");
          else if(
c[1] > 255) return SendClientMessage(playeridCOLOR_ERROR"[ERROR]"COL_WHITE" Cannot go above 255!");
          if(
id != 0)
        {
              
vInfo[id][vcolor1] = c[0];
            
vInfo[id][vcolor2] = c[1];
              
ChangeVehicleColor(vehicleidc[0], c[1]);
              
format(fquery,sizeof(fquery), "UPDATE `vehicles` SET Color1 = '%d', Color2 = '%d' WHERE ID = '%d'"vInfo[id][vcolor1], vInfo[id][vcolor2], id);
             
db_free_result(db_query(Databasefquery));
              
format(fquerysizeof(fquery), "[VEHICLE]"COL_WHITE" You've changed the primary color %i and secondary %i"c[0], c[1]);
              
SendClientMessage(playeridCOLOR_SERVERfquery);
        }
        else return 
ErrorMessages(playerid13);
    }
if(!
strcmp(params"respawn"true7))
    {
        new 
str[50], STR[512], idd 0;
        for(new 
iMAX_BUY_Vi++)
        {
            if(
== 0) continue;
            if(!
strcmp(GetPlayerName(playerid), vInfo[i][vowner], false))
            {
                
format(strsizeof(str),"%s \n"GetVehicleNameByModel(vInfo[i][vmodel]));
                  
strcat(STRstr);
                  
RespawnVOwner[playerid][idd] = vInfo[i][NewID];
                  
idd++;
            }
        }
        if(
strlen(STR) < 2) return SendClientMessage(playeridCOLOR_RED"[ERROR]"COL_WHITE" You don't have any vehicle");
        return 
ShowPlayerDialog(playeridCAR_LISTDIALOG_STYLE_LIST,""COL_BLUE"Cars list"STR"Select""Close");
    }
    }
 return 
1
i put /v respawn and return message no exist this command who :/?
Reply
#5

Load crashdetect plugin, I'm sure GetVehicleNameByModel function causes this and it's the exact same problem as this: https://sampforum.blast.hk/showthread.php?pid=3805925#pid3805925

By the way, as "respawn" option does not have parameters you can remove the length from strcmp because this will also work "/v respawnblablabla" and if you use else if statements, you'll be able to use an else statement at the end to show the usage and options if an option input was invalid.
Reply
#6

22:55:45] [debug] Run time error 5: "Invalid memory access"
[22:55:45] [debug] AMX backtrace:
[22:55:45] [debug] #0 000433ec in ?? (612) from CNR.amx
[22:55:45] [debug] #1 00059514 in public cmd_v (3, 28303720) from CNR.amx
[22:55:45] [debug] #2 native CallLocalFunction () from samp03svr
[22:55:45] [debug] #3 00039258 in public FIXES_OnPlayerCommandText (3, 28303676) from CNR.amx
[22:55:45] [debug] #4 00003678 in public OnPlayerCommandText (3, 28303676) from CNR.amx

PHP код:
stock GetVehicleNameByModel(modelid)
{
    if(
400<modelid || modelid>611)
    {
        
modelid=612;
    }
    return 
VehicleNames[(modelid-400)];

Reply
#7

It is most likely because you try to return the text stored in VehicleNames array directly. I knew it could return corrupted text but never expected a run time error.

Create a local string and store the name there, then return that local string instead.
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It is most likely because you try to return the text stored in VehicleNames array directly. I knew it could return corrupted text but never expected a run time error.

Create a local string and store the name there, then return that local string instead.
Yes bro GetVehicleNameByModel its the problem i change to format(str, sizeof(str),"%d \n", vInfo[i][vmodel]);
and work, i testing you idea.

THANKS BRO!!!, I SOLVED, thanks for you help. rep *2000000000
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)