What's wrong with this command?
#1

pawn Код:
CMD:setclass(playerid, params[])
{
    new NewClass[24];
    if(sscanf(params, "s[24]", NewClass)) return SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}/setclass [classname]");

    if(strcmp(NewClass, "Taxi", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}{FFFFFF}You are already playing as a cab driver!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a taxi driver.");
        SetPlayerColor(playerid, COLOR_YELLOW);
        ResetPlayerWeapons(playerid);
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, 100);
        SetPlayerSkin(playerid, 234);
        SetPlayerPos(playerid, 1690.7296, 1447.7753, 10.7661);
        SetPlayerFacingAngle(playerid, 267.7922);
        PlayerClass[playerid] = 0;
    }
    else if(strcmp(NewClass, "Pilot", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}{FFFFFF}You are already playing as a pilot!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a pilot.");
        SetPlayerColor(playerid, COLOR_CYAN);
        ResetPlayerWeapons(playerid);
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, 100);
        SetPlayerSkin(playerid, 61);
        SetPlayerPos(playerid, 1319.2111, 1256.2635, 10.8203);
        SetPlayerFacingAngle(playerid, 359.9823);
        PlayerClass[playerid] = 1;
    }
    else if(strcmp(NewClass, "Paramedic", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 2) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}You are already playing as a paramedic!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a paramedic.");
        SetPlayerColor(playerid, COLOR_RED);
        ResetPlayerWeapons(playerid);
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, 100);
        SetPlayerSkin(playerid, 275);
        SetPlayerPos(playerid, 1607.5043, 1819.6926, 10.8280);
        SetPlayerFacingAngle(playerid, 359.0171);
        PlayerClass[playerid] = 2;
    }
    else if(strcmp(NewClass, "Lowlife", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 3) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}You are already playing as a lowlife!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a lowlife.");
        SetPlayerColor(playerid, COLOR_WHITE);
        ResetPlayerWeapons(playerid);
        SetPlayerArmour(playerid, 50);
        SetPlayerHealth(playerid, 100);
        GivePlayerWeapon(playerid, PISTOL, 256);
        GivePlayerWeapon(playerid, TEC9, 512);
        SetPlayerSkin(playerid, 292);
        SetPlayerPos(playerid, 1927.6666, 674.5269,  10.8203);
        SetPlayerFacingAngle(playerid, 0.0902);
        PlayerClass[playerid] = 3;
    }
    else if(strcmp(NewClass, "Firefighter", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 4) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}You are already playing as a firefighter!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a firefighter.");
        SetPlayerColor(playerid, COLOR_ORANGE);
        ResetPlayerWeapons(playerid);
        SetPlayerArmour(playerid, 0);
        SetPlayerHealth(playerid, 100);
        SetPlayerSkin(playerid, 278);
        SetPlayerPos(playerid, 1735.5243, 2111.2268, 12.2891);
        SetPlayerFacingAngle(playerid, 94.0980);
        PlayerClass[playerid] = 4;
    }
    else if(strcmp(NewClass, "Police", false, sizeof(NewClass)))
    {
        if(PlayerClass[playerid] == 5) return SendClientMessage(playerid, COLOR_RED, "(ERROR): {FFFFFF}You are already playing as a police officer!");
        SendClientMessage(playerid, COLOR_GRAY, "{7FAFDA}Server: {FFFFFF}You have respawned as a police officer.");
        SetPlayerColor(playerid, COLOR_BLUE);
        ResetPlayerWeapons(playerid);
        SetPlayerHealth(playerid, 100);
        SetPlayerArmour(playerid, 100);
        GivePlayerWeapon(playerid, PISTOL, 256);
        GivePlayerWeapon(playerid, SHOTGUN, 50);
        SetPlayerSkin(playerid, 282);
        SetPlayerPos(playerid, 2273.6729, 2447.4644, 3.5313);
        SetPlayerFacingAngle(playerid, 182.2979);
        PlayerClass[playerid] = 5;
    }

    return 1;
}
This command only runs the first if statement. If you try to switch from any class to any other class, it switches your class only to taxi.
Reply
#2

Can i see your classes definition?
Reply
#3

Try

PHP код:
CMD:setclass(playeridparams[])
{
    new 
NewClass[24];
    if(
sscanf(params"s[24]"NewClass)) return SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}/setclass [classname]");
    if(
strcmp(NewClass"Taxi"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 0) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}{FFFFFF}You are already playing as a cab driver!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a taxi driver.");
        
SetPlayerColor(playeridCOLOR_YELLOW);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid234);
        
SetPlayerPos(playerid1690.72961447.775310.7661);
        
SetPlayerFacingAngle(playerid267.7922);
        
PlayerClass[playerid] = 0;
        return 
1;
    }
    if(
strcmp(NewClass"Pilot"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 1) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}{FFFFFF}You are already playing as a pilot!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a pilot.");
        
SetPlayerColor(playeridCOLOR_CYAN);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid61);
        
SetPlayerPos(playerid1319.21111256.263510.8203);
        
SetPlayerFacingAngle(playerid359.9823);
        
PlayerClass[playerid] = 1;
        return 
1;
    }
    if(
strcmp(NewClass"Paramedic"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 2) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a paramedic!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a paramedic.");
        
SetPlayerColor(playeridCOLOR_RED);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid275);
        
SetPlayerPos(playerid1607.50431819.692610.8280);
        
SetPlayerFacingAngle(playerid359.0171);
        
PlayerClass[playerid] = 2;
        return 
1;
    }
    if(
strcmp(NewClass"Lowlife"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 3) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a lowlife!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a lowlife.");
        
SetPlayerColor(playeridCOLOR_WHITE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid50);
        
SetPlayerHealth(playerid100);
        
GivePlayerWeapon(playeridPISTOL256);
        
GivePlayerWeapon(playeridTEC9512);
        
SetPlayerSkin(playerid292);
        
SetPlayerPos(playerid1927.6666674.5269,  10.8203);
        
SetPlayerFacingAngle(playerid0.0902);
        
PlayerClass[playerid] = 3;
        return 
1;
    }
    if(
strcmp(NewClass"Firefighter"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 4) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a firefighter!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a firefighter.");
        
SetPlayerColor(playeridCOLOR_ORANGE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid278);
        
SetPlayerPos(playerid1735.52432111.226812.2891);
        
SetPlayerFacingAngle(playerid94.0980);
        
PlayerClass[playerid] = 4;
        return 
1;
    }
    if(
strcmp(NewClass"Police"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 5) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a police officer!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a police officer.");
        
SetPlayerColor(playeridCOLOR_BLUE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerHealth(playerid100);
        
SetPlayerArmour(playerid100);
        
GivePlayerWeapon(playeridPISTOL256);
        
GivePlayerWeapon(playeridSHOTGUN50);
        
SetPlayerSkin(playerid282);
        
SetPlayerPos(playerid2273.67292447.46443.5313);
        
SetPlayerFacingAngle(playerid182.2979);
        
PlayerClass[playerid] = 5;
        return 
1;
    }
    return 
1;

Reply
#4

If two strings are equal, then strcmp will return 0. It should be:
pawn Код:
if(!strcmp(NewClass, "Taxi", false, sizeof(NewClass)))
pawn Код:
else if(!strcmp(NewClass, "... class_name_here ...", false, sizeof(NewClass)))
Reply
#5

Quote:
Originally Posted by MCZOFT
Посмотреть сообщение
Try

PHP код:
CMD:setclass(playeridparams[])
{
    new 
NewClass[24];
    if(
sscanf(params"s[24]"NewClass)) return SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}/setclass [classname]");
    if(
strcmp(NewClass"Taxi"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 0) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}{FFFFFF}You are already playing as a cab driver!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a taxi driver.");
        
SetPlayerColor(playeridCOLOR_YELLOW);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid234);
        
SetPlayerPos(playerid1690.72961447.775310.7661);
        
SetPlayerFacingAngle(playerid267.7922);
        
PlayerClass[playerid] = 0;
        return 
1;
    }
    if(
strcmp(NewClass"Pilot"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 1) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}{FFFFFF}You are already playing as a pilot!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a pilot.");
        
SetPlayerColor(playeridCOLOR_CYAN);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid61);
        
SetPlayerPos(playerid1319.21111256.263510.8203);
        
SetPlayerFacingAngle(playerid359.9823);
        
PlayerClass[playerid] = 1;
        return 
1;
    }
    if(
strcmp(NewClass"Paramedic"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 2) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a paramedic!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a paramedic.");
        
SetPlayerColor(playeridCOLOR_RED);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid275);
        
SetPlayerPos(playerid1607.50431819.692610.8280);
        
SetPlayerFacingAngle(playerid359.0171);
        
PlayerClass[playerid] = 2;
        return 
1;
    }
    if(
strcmp(NewClass"Lowlife"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 3) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a lowlife!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a lowlife.");
        
SetPlayerColor(playeridCOLOR_WHITE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid50);
        
SetPlayerHealth(playerid100);
        
GivePlayerWeapon(playeridPISTOL256);
        
GivePlayerWeapon(playeridTEC9512);
        
SetPlayerSkin(playerid292);
        
SetPlayerPos(playerid1927.6666674.5269,  10.8203);
        
SetPlayerFacingAngle(playerid0.0902);
        
PlayerClass[playerid] = 3;
        return 
1;
    }
    if(
strcmp(NewClass"Firefighter"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 4) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a firefighter!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a firefighter.");
        
SetPlayerColor(playeridCOLOR_ORANGE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerArmour(playerid0);
        
SetPlayerHealth(playerid100);
        
SetPlayerSkin(playerid278);
        
SetPlayerPos(playerid1735.52432111.226812.2891);
        
SetPlayerFacingAngle(playerid94.0980);
        
PlayerClass[playerid] = 4;
        return 
1;
    }
    if(
strcmp(NewClass"Police"falsesizeof(NewClass)))
    {
        if(
PlayerClass[playerid] == 5) return SendClientMessage(playeridCOLOR_RED"(ERROR): {FFFFFF}You are already playing as a police officer!");
        
SendClientMessage(playeridCOLOR_GRAY"{7FAFDA}Server: {FFFFFF}You have respawned as a police officer.");
        
SetPlayerColor(playeridCOLOR_BLUE);
        
ResetPlayerWeapons(playerid);
        
SetPlayerHealth(playerid100);
        
SetPlayerArmour(playerid100);
        
GivePlayerWeapon(playeridPISTOL256);
        
GivePlayerWeapon(playeridSHOTGUN50);
        
SetPlayerSkin(playerid282);
        
SetPlayerPos(playerid2273.67292447.46443.5313);
        
SetPlayerFacingAngle(playerid182.2979);
        
PlayerClass[playerid] = 5;
        return 
1;
    }
    return 
1;

This is the same as having them in else if statements. Same problem.
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If two strings are equal, then strcmp will return 0. It should be:
pawn Код:
if(!strcmp(NewClass, "Taxi", false, sizeof(NewClass)))
pawn Код:
else if(!strcmp(NewClass, "... class_name_here ...", false, sizeof(NewClass)))
Grazie
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)