SA-MP Forums Archive
Checking for spaces in OnPlayerText - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Checking for spaces in OnPlayerText (/showthread.php?tid=573306)



Checking for spaces in OnPlayerText - Luis- - 06.05.2015

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);



Re: Checking for spaces in OnPlayerText - Konstantinos - 06.05.2015

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


Re: Checking for spaces in OnPlayerText - Luis- - 06.05.2015

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


Re: Checking for spaces in OnPlayerText - Konstantinos - 06.05.2015

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?


Re: Checking for spaces in OnPlayerText - Luis- - 06.05.2015

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.


Re: Checking for spaces in OnPlayerText - Ahmad45123 - 06.05.2015

What is the var text ? What does it contains ?


Re: Checking for spaces in OnPlayerText - Konstantinos - 06.05.2015

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?


Re: Checking for spaces in OnPlayerText - Luis- - 06.05.2015

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.


Re: Checking for spaces in OnPlayerText - MP2 - 06.05.2015

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'



Re: Checking for spaces in OnPlayerText - Luis- - 06.05.2015

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.