Strcmp to zcmd
#1

Hey. I have got to a point where I can't figure out how to convert these two strcmp commands to zcmd! Believe me, I have been trying for at least 20 minutes without any progress. I'm no master so I thought I'd ask here.

Objective: Convert these two commands to zcmd commands (it's using parameters).

Command 1:
pawn Код:
if(strcmp(cmd, "/approvehouse", true) == 0)
    { // Accepting house.
        if(!IsPlayerAdmin(playerid))
            return SendClientMessage(playerid, 0xFFFFFFAA, "SERVER: Unknown command.");
        new tmp[128], giveplayerid;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, 0xE21F1FFF, "USAGE: /approvehouse [playerid/PartOfName]");
            return 1;
        }
        giveplayerid = ReturnUser(tmp);
        if(IsPlayerConnected(giveplayerid)) {
            if(giveplayerid != INVALID_PLAYER_ID) {
                if(IsApprovalPending[giveplayerid] == true) {
                    new money = GetPlayerMoney(giveplayerid);
                    if(money < SetupHouseInfo[giveplayerid][SetupPrice])
                    { // Cannot afford, so we'll reset all variables used.
                        SendClientMessage(giveplayerid, 0xE21F1FFF, "You cannot afford the house.");
                        IsSettingUpHouse[giveplayerid] = false; SettingUpEntrance[giveplayerid] = false;
                        HasAlreadySetupName[giveplayerid] = false; HasAlreadySetupDesc[giveplayerid] = false;
                        HasAlreadySetupEntrance[giveplayerid] = false; HasAlreadySetupInterior[giveplayerid] = false;
                        HasAlreadySetupRentable[giveplayerid] = false; HasAlreadySetupRentPrice[giveplayerid] = false;
                        HasAlreadySetupCar[giveplayerid] = false;
                        SetupHouseInfo[giveplayerid][SetupName] = 0; SetupHouseInfo[giveplayerid][SetupDesc] = 0;
                        SetupHouseInfo[giveplayerid][SetupOwner] = 0; SetupHouseInfo[giveplayerid][SetupPrice] = 0;
                        SetupHouseInfo[giveplayerid][SetupPX] = 0.0; SetupHouseInfo[giveplayerid][SetupPY] = 0.0;
                        SetupHouseInfo[giveplayerid][SetupPZ] = 0.0; SetupHouseInfo[giveplayerid][SetupTX] = 0.0;
                        SetupHouseInfo[giveplayerid][SetupTY] = 0.0; SetupHouseInfo[giveplayerid][SetupTZ] = 0.0;
                        SetupHouseInfo[giveplayerid][SetupTA] = 0.0; SetupHouseInfo[giveplayerid][SetupInt] = 0;
                        SetupHouseInfo[giveplayerid][SetupVir] = 0; SetupHouseInfo[giveplayerid][SetupRentable] = 0;
                        SetupHouseInfo[giveplayerid][SetupRentPrice] = 0; SetupHouseInfo[giveplayerid][SetupCarX] = 0.0;
                        SetupHouseInfo[giveplayerid][SetupCarY] = 0.0; SetupHouseInfo[giveplayerid][SetupCarZ] = 0.0;
                        SetupHouseInfo[giveplayerid][SetupCarRot] = 0.0; SetupHouseInfo[giveplayerid][SetupCarModel] = 0;
                        DestroyPickup(HousePickup[playerid]);
                        Delete3DTextLabel(HouseLabel[playerid]);
                        DestroyVehicle(HouseCar[playerid]);
                        IsApprovalPending[giveplayerid] = false;
                        PlayerPlaySound(giveplayerid, 1085, 0.0, 0.0, 0.0);
                        new file[100], pname[24];
                        GetPlayerName(giveplayerid, pname, 24);
                        format(file, sizeof(file), "Houses/%s.ini", pname);
                        dini_Remove(file);
                        return 1;
                    }
                    else { // If player can afford house.
                        new str[64];
                        for(new h = 0; h < sizeof(HouseInfo); h++)
                        { // Store setup data in house variables.
                            new str2[128];
                            HouseInfo[h][Name] = SetupHouseInfo[giveplayerid][SetupName];
                            HouseInfo[h][Desc] = SetupHouseInfo[giveplayerid][SetupDesc];
                            HouseInfo[h][Owner] = SetupHouseInfo[giveplayerid][SetupOwner];
                            HouseInfo[h][Price] = SetupHouseInfo[giveplayerid][SetupPrice];
                            HouseInfo[h][PX] = SetupHouseInfo[giveplayerid][SetupPX];
                            HouseInfo[h][PY] = SetupHouseInfo[giveplayerid][SetupPY];
                            HouseInfo[h][PZ] = SetupHouseInfo[giveplayerid][SetupPZ];
                            HouseInfo[h][TX] = SetupHouseInfo[giveplayerid][SetupTX];
                            HouseInfo[h][TY] = SetupHouseInfo[giveplayerid][SetupTY];
                            HouseInfo[h][TZ] = SetupHouseInfo[giveplayerid][SetupTZ];
                            HouseInfo[h][TA] = SetupHouseInfo[giveplayerid][SetupTA];
                            HouseInfo[h][Int] = SetupHouseInfo[giveplayerid][SetupInt];
                            HouseInfo[h][Vir] = SetupHouseInfo[giveplayerid][SetupVir];
                            HouseInfo[h][Locked] = 0;
                            HouseInfo[h][Rentable] = SetupHouseInfo[giveplayerid][SetupRentable];
                            HouseInfo[h][RentPrice] = SetupHouseInfo[giveplayerid][SetupRentPrice];
                            HouseInfo[h][CarModel] = SetupHouseInfo[giveplayerid][SetupCarModel];
                            HouseInfo[h][CarX] = SetupHouseInfo[giveplayerid][SetupCarX];
                            HouseInfo[h][CarY] = SetupHouseInfo[giveplayerid][SetupCarY];
                            HouseInfo[h][CarZ] = SetupHouseInfo[giveplayerid][SetupCarZ];
                            HouseInfo[h][CarRot] = SetupHouseInfo[giveplayerid][SetupCarRot];
                            PlayerPlaySound(giveplayerid, 1149, 0.0, 0.0, 0.0);
                            format(str, sizeof(str), "Congratulations! You have bought a house for $%i.", SetupHouseInfo[giveplayerid][SetupPrice]);
                            SendClientMessage(giveplayerid, 0xFFFF00FF, str);
                            GivePlayerMoney(giveplayerid, -HouseInfo[h][Price]);
                            HouseOwner[giveplayerid] = true;
                            IsSettingUpHouse[giveplayerid] = false; SettingUpEntrance[giveplayerid] = false;
                            HasAlreadySetupName[giveplayerid] = false; HasAlreadySetupDesc[giveplayerid] = false;
                            HasAlreadySetupEntrance[giveplayerid] = false; HasAlreadySetupInterior[giveplayerid] = false;
                            SetupHouseInfo[giveplayerid][SetupName] = 0; SetupHouseInfo[giveplayerid][SetupDesc] = 0;
                            SetupHouseInfo[giveplayerid][SetupOwner] = 0; SetupHouseInfo[giveplayerid][SetupPrice] = 0;
                            SetupHouseInfo[giveplayerid][SetupPX] = 0.0; SetupHouseInfo[giveplayerid][SetupPY] = 0.0;
                            SetupHouseInfo[giveplayerid][SetupPZ] = 0.0; SetupHouseInfo[giveplayerid][SetupTX] = 0.0;
                            SetupHouseInfo[giveplayerid][SetupTY] = 0.0; SetupHouseInfo[giveplayerid][SetupTZ] = 0.0;
                            SetupHouseInfo[giveplayerid][SetupTA] = 0.0; SetupHouseInfo[giveplayerid][SetupInt] = 0;
                            SetupHouseInfo[giveplayerid][SetupVir] = 0; HasAlreadySetupRentable[giveplayerid] = false;
                            SetupHouseInfo[giveplayerid][SetupRentable] = 0; HasAlreadySetupCar[giveplayerid] = false;
                            SetupHouseInfo[giveplayerid][SetupRentable] = 0;
                            SetupHouseInfo[giveplayerid][SetupRentPrice] = 0; SetupHouseInfo[giveplayerid][SetupCarX] = 0.0;
                            SetupHouseInfo[giveplayerid][SetupCarY] = 0.0; SetupHouseInfo[giveplayerid][SetupCarZ] = 0.0;
                            SetupHouseInfo[giveplayerid][SetupCarRot] = 0.0; SetupHouseInfo[giveplayerid][SetupCarModel] = 0;
                            HasAlreadySetupRentPrice[giveplayerid] = false;
                            IsApprovalPending[giveplayerid] = false;
                            new pname[MAX_PLAYER_NAME];
                            new name[256], desc[256];
                            new file[100];
                            GetPlayerName(giveplayerid, pname, sizeof(pname));
                            format(file, sizeof(file), "Houses/%s.ini", pname);
                            name = dini_Get(file, "Name");
                            desc = dini_Get(file, "Description");
                            format(str2, sizeof(str2), "Name: %s\n\nDescription: %s\n\nOwner: %s", name, desc, pname);
                            HouseLabel[giveplayerid] = Create3DTextLabel(str2, 0xF97804FF, HouseInfo[h][PX], HouseInfo[h][PY], HouseInfo[h][PZ], 20.0, 0);
                            for(new i; i<MAX_PLAYERS; i++)
                            {
                                SetPlayerMapIcon(i, HouseUser[playerid], HouseInfo[h][CarX], HouseInfo[h][CarY], HouseInfo[h][CarZ], 31, MAPICON_GLOBAL);
                            }
                            return 1;
                        }
                    }
                }
            }
        }
        else
        {
            SendClientMessage(playerid, 0xE21F1FFF, "That player didn't create a house yet!");
        }
        return 1;
    }
Command 2:
pawn Код:
if(strcmp(cmd, "/denyhouse", true) == 0)
    { // Deny house.
        if(!IsPlayerAdmin(playerid))
            return SendClientMessage(playerid, 0xFFFFFFAA, "SERVER: Unknown command.");
        new tmp[128], giveplayerid;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, 0xE21F1FFF, "USAGE: /denyhouse [playerid/PartOfName]");
            return 1;
        }
        giveplayerid = ReturnUser(tmp);
        if(IsPlayerConnected(giveplayerid)) {
            if(giveplayerid != INVALID_PLAYER_ID) {
                if(IsApprovalPending[giveplayerid] == true) {
                    SendClientMessage(giveplayerid, 0xE21F1FFF, "Your house request was denied.");
                    IsSettingUpHouse[giveplayerid] = false; SettingUpEntrance[giveplayerid] = false;
                    HasAlreadySetupName[giveplayerid] = false; HasAlreadySetupDesc[giveplayerid] = false;
                    HasAlreadySetupEntrance[giveplayerid] = false; HasAlreadySetupInterior[giveplayerid] = false;
                    SetupHouseInfo[giveplayerid][SetupName] = 0; SetupHouseInfo[giveplayerid][SetupDesc] = 0;
                    SetupHouseInfo[giveplayerid][SetupOwner] = 0; SetupHouseInfo[giveplayerid][SetupPrice] = 0;
                    SetupHouseInfo[giveplayerid][SetupPX] = 0.0; SetupHouseInfo[giveplayerid][SetupPY] = 0.0;
                    SetupHouseInfo[giveplayerid][SetupPZ] = 0.0; SetupHouseInfo[giveplayerid][SetupTX] = 0.0;
                    SetupHouseInfo[giveplayerid][SetupTY] = 0.0; SetupHouseInfo[giveplayerid][SetupTZ] = 0.0;
                    SetupHouseInfo[giveplayerid][SetupTA] = 0.0; SetupHouseInfo[giveplayerid][SetupInt] = 0;
                    SetupHouseInfo[giveplayerid][SetupVir] = 0; SetupHouseInfo[giveplayerid][SetupRentable] = 0;
                    SetupHouseInfo[giveplayerid][SetupRentPrice] = 0;
                    IsApprovalPending[giveplayerid] = false;
                    DestroyPickup(HousePickup[giveplayerid]);
                    Delete3DTextLabel(HouseLabel[giveplayerid]);
                    PlayerPlaySound(giveplayerid, 1085, 0.0, 0.0, 0.0);
                    new file[100], pname[24];
                    GetPlayerName(giveplayerid, pname, 24);
                    format(file, sizeof(file), "Houses/%s.ini", pname);
                    dini_Remove(file);
                    return 1;
                }
            }
        }
        else
        {
            SendClientMessage(playerid, 0xE21F1FFF, "That player didn't create a house yet!");
        }
        return 1;
    }
    return 0;
}
Reward: Make me happy.
Reply
#2

To convert any command to dcmd:

Код:
if(strcmp(cmd, "/denyhouse", true) == 0)
Will be:
Код:
CMD:denyhouse(playerid,params[])
{
and rename cmdtext to params.
Reply
#3

It gives me an error at the line below saying: (1452) : error 017: undefined symbol "idx"
pawn Код:
tmp = strtok(params, idx);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)