Need help with payfare command
#1

Guys i have made a taxi system for my script with /taxi you can call taxi and taxi driver will use /acceptfare to accept offer of fare from taxi driver and it will save that playerid to player file of id but i got a problem with fayfare command with this you can pay fare to taxi driver so i called it id with dini here is the command but problem is when i use /payfare it always giving cash to id 0 player

pawn Код:
if (strcmp(string, "/payfare", true) == 0)
    {
                new playerName[MAX_PLAYER_NAME],newstring[100],newstring1[120],giveName[MAX_PLAYER_NAME];
                new id;

                if(TaxiDriverOnDuty[playerid] == 1) return SendClientMessage2(playerid, COLOR_RED, "You are a taxi driver.");

                if(CallingTaxi[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"You are not requesting a taxi.");


                GetPlayerName(playerid,playerName,sizeof(playerName));
                GetPlayerName(id,giveName,sizeof(giveName));
               
                id = dini_Int(AddDirFile(dir_userfiles, playerName), "FareFor");

                if(dini_Int(AddDirFile(dir_userfiles, playerName), "FareFor") == -1) return SendClientMessage2(playerid, COLOR_RED, "You did not accept any fare offer.");

                format(newstring, sizeof(newstring), "You have paid $%d fare to %s.", dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"), giveName);
                SendClientMessage(playerid,COLOR_ORANGE,newstring);

                format(newstring1, sizeof(newstring1), "%s has paid $%d fare to you.", playerName,dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"));
                SendClientMessage(giveplayerid,COLOR_RED,newstring1);

                GivePlayerMoney(playerid, -dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"));
                GivePlayerMoney(id, dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"));

                dini_IntSet(AddDirFile(dir_userfiles, playerName), "FareFor", -1);
                dini_IntSet(AddDirFile(dir_userfiles, playerName), "Fare", 0);
                Offerby[playerid] = 0;
                CallingTaxi[playerid] = 0;
                return 1;
    }
for accept offer of fare

pawn Код:
if (strcmp(string, "/acceptfare", true) == 0)
    {
                new playerName[MAX_PLAYER_NAME],newstring[100],givedplayerid,newstring1[120],giveName[MAX_PLAYER_NAME],newstring3[100];

                if(CallingTaxi[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"You are not requesting a taxi.");

                tmp = strtok(cmdtext, idx);
                if (!strlen(tmp)) return SendClientMessage2(playerid, COLOR_WHITE, "Usage: /acceptfare [playerid]");
                givedplayerid = strval(tmp);

                GetPlayerName(playerid,playerName,sizeof(playerName));
                GetPlayerName(givedplayerid,giveName,sizeof(giveName));

                format(newstring3, sizeof(newstring3), "%s did not offered you the taxi fare.", giveName);

                if (!IsPlayerConnected2(givedplayerid) || !isNumeric(tmp)) return SendClientMessage2(playerid, COLOR_RED, "Error: Inactive player id!");

                if (orcl[givedplayerid][0] != 0) return SendPlayerFormattedText(playerid, COLOR_WHITE, "Please wait until %s has spawned.", giveName, "");

                if(givedplayerid == playerid) return SendClientMessage2(playerid, COLOR_RED, "You are a taxi driver.");

                if(Offerby[playerid] == 0) return SendClientMessage2(playerid, COLOR_RED, newstring3);

                if(dini_Int(AddDirFile(dir_userfiles, playerName), "FareFor") != -1) return SendClientMessage2(playerid, COLOR_RED, "You already accept somone's offer decline or cancel your request before accept another fare.");

                format(newstring, sizeof(newstring), "You have accepted %s offered with a fare of $%d.", giveName,dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"));
                SendClientMessage(playerid,COLOR_ORANGE,newstring);

                format(newstring1, sizeof(newstring1), "%s has accepted your fare of $%d for a taxi.", giveName,dini_Int(AddDirFile(dir_userfiles, playerName), "Fare"));
                SendClientMessage(givedplayerid,COLOR_ORANGE,newstring1);

                dini_IntSet(AddDirFile(dir_userfiles, playerName), "FareFor", givedplayerid);
                return 1;
    }
Reply
#2

I suggest you to switch right away to sscanf2 by ******.

sscanf 2.8.1
Reply
#3

Hmm well its not possible because in my script have almost 200+ command with strcmp
Reply
#4

Quote:
Originally Posted by IceBilizard
Посмотреть сообщение
Hmm well its not possible because in my script have almost 200+ command with strcmp
You can, just read this:
http://forum.sa-mp.com/showpost.php?...7&postcount=16

Furthermore, even wiki states that strtok is a deprecated function, and it should be avoided in most of the cases

Here's an example:

pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)//Replace OnPlayerCommandText with this callback
{
    if(success)
    {
        return 1;
    }
    //Place all your strcmp commands here:
    if(strcmp(cmdtext, "/help", true) == 0)
    {
        SendClientMessage(playerid, -1, "Available commands: ");
        return 1;
    }

    if(strcmp(cmdtext, "/kill", true) == 0)
    {
        SetPlayerHealth(playerid, 0);
        return 1;
    }

    return 0;
}
//Now you can make a zcmd command outside that callback:

CMD:hi(playerid, params[])
{
    SendClientMessage(playerid, -1, "Hello World.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)