Set 3 Variables w/ one entry
#1

I can't seem to figure out how to change three coordinate variables with one text entry. Say a player enters a coordinate:
pawn Код:
140.17, 1366.07, 1083.65
How can I set a variable for the X value, the Y value, and the Z value with only this entry?
Reply
#2

Are you using ZCMD, DCMD or sa-mp's default commands.
Reply
#3

Quote:
Originally Posted by klimgorilla
Посмотреть сообщение
Are you using ZCMD, DCMD or sa-mp's default commands.
I'm using ZCMD. That is not relevant, however. I should have explained better; I'm using just regular text entry to do it. No command, you just open the text box and enter the coordinates (OnPlayerText).
Reply
#4

I believe you could use sscanf to split the entry by using comma as the delimiter.

pawn Код:
public OnPlayerText(playerid, text[]) {
    new
        Float: fCoordinates[3];

    if(sscanf(text, "p<,>fff", fCoordinates[0], fCoordinates[1], fCoordinates[2]))
        return 1; // Error: Invalid coordinates

    SetPlayerPos(playerid, fCoordinates[0], fCoordinates[1], fCoordinates[2]);
    return 1;
}
However, the spaces should be removed between the coordinate text. (140.17,1366.07,1083.65)
Reply
#5

Quote:
Originally Posted by Calgon
Посмотреть сообщение
I believe you could use sscanf to split the entry by using comma as the delimiter.

pawn Код:
public OnPlayerText(playerid, text[]) {
    new
        Float: fCoordinates[3];

    if(sscanf(text, "p<,>fff", fCoordinates[0], fCoordinates[1], fCoordinates[2]))
        return 1; // Error: Invalid coordinates

    SetPlayerPos(playerid, fCoordinates[0], fCoordinates[1], fCoordinates[2]);
    return 1;
}
However, the spaces should be removed between the coordinate text. (140.17,1366.07,1083.65)
Brilliant, thank you. I didn't even think to use sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)