Checking for spaces in OnPlayerText
#1

Hey! I've been trying to fix this problem for a while now but, sadly no luck.

What I want to happen is when somebody calls for a Taxi, they are asked where they are located, obviously, if they're, say at Glen Park it'll just show "Glen".

pawn Код:
strmid(PlayerTaxiLoca[playerid], tmp, 0, strlen(text), sizeof(tmp));
format(string, sizeof string, "Redsquare Taxis says: Alright, a Taxi should be on it's way to '%s'! Thanks for calling.", PlayerTaxiLoca[playerid]);
SendClientMessage(playerid, COLOR_GREY, string);
Reply
#2

How do you store the name of the location to "tmp"?
Reply
#3

I'm guessing you mean this;
pawn Код:
tmp = strtok(text, idx);
I know it's not the best way to do it.
Reply
#4

Yeah, it's not.
I've never used strtok so I don't know what the problem is with it, but we could find a more efficient way of doing this if you want to.

If you don't mind, how does the player give the location name and you retrieve it?
Reply
#5

If you know a better way, I'd love to hear it!

I use a command to actually get the players information, then pass it onto OnPlayerText.
Reply
#6

What is the var text ? What does it contains ?
Reply
#7

Quote:
Originally Posted by Luis-
Посмотреть сообщение
If you know a better way, I'd love to hear it!

I use a command to actually get the players information, then pass it onto OnPlayerText.
Can you post that part of code so it'd be easier for us to understand?
Reply
#8

The command;
pawn Код:
CMD:call(playerid, params[]) {
    new num;
    if(sscanf(params, "i", num)) return SendUsageMessage(playerid, "/call [phone number]");
    else {
        if(num == 454) {
            PlayerInfo[playerid][pOnPhone] = true;
            PlayerInfo[playerid][pCalled] = 454;
            SendClientMessage(playerid, COLOR_GREY, "Redsquare Taxis says: Thank you for calling, where are you located?");
            TaxiStep{playerid} = 1;
            PlayerCalledTaxi{playerid} = playerid;
        }
    }  
    return 1;
}
OnPlayerText part;
pawn Код:
if(TaxiStep{playerid} == 1) {
                strmid(PlayerTaxiLoca[playerid], tmp, 0, strlen(text), sizeof(tmp));
                format(string, sizeof string, "Redsquare Taxis says: Alright, a Taxi should be on it's way to '%s'! Thanks for calling.", PlayerTaxiLoca[playerid]);
                SendClientMessage(playerid, COLOR_GREY, string);
                PlayerInfo[playerid][pOnPhone] = false;
                PlayerInfo[playerid][pCalled] = 0;
                TaxiStep{playerid} = 0;
                foreach(new i : Player) {
                    if(PlayerInfo[i][pTaxiDuty] == 1) {
                        new Float:X, Float:Y, Float:Z;
                        format(string, sizeof string, "Dispatch: We have a customer located at, %s.", PlayerTaxiLoca[playerid]);
                        SendClientMessage(i, COLOR_WHITE, string);
                        GetPlayerPos(playerid, X, Y, Z);
                        TaxiCustomerCP{i} = CreateDynamicCP(X, Y, Z, 6.0, -1, -1, i, 12000.0);
                    }
                }
            }
Sorry about the indentation.
Reply
#9

Off-topic, but why on earth would you want to do that..? So if they're at 'Come a Lot' it's going to say 'I'm at Come'. What possible justification is there for wanting that..?

Also, to do this is quite simple:

pawn Код:
new originalString[] = "Hello World";
new finalString[32];
   
new pos = strfind(originalString, " ");

if(pos)
{
    strmid(finalString, originalString, 0, pos);
}
else
{
    strcat(finalString, originalString);
}

printf("Original String: '%s'\nFinal String: '%s'", originalString, finalString);

// Output:
// Original String: 'Hello World'
// Final String: 'Hello'
Reply
#10

Oh, sorry. I must not of made it clear enough. It does only show one word, so if I do say "Come a Lot" it will only show "Come". I'm wanting it to actually show the whole word.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)