Set 3 Variables w/ one entry - 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: Set 3 Variables w/ one entry (
/showthread.php?tid=508062)
Set 3 Variables w/ one entry -
austin070 - 20.04.2014
I can't seem to figure out how to change three coordinate variables with one text entry. Say a player enters a coordinate:
How can I set a variable for the X value, the Y value, and the Z value with only this entry?
Re: Set 3 Variables w/ one entry -
klimgorilla - 20.04.2014
Are you using ZCMD, DCMD or sa-mp's default commands.
Re: Set 3 Variables w/ one entry -
austin070 - 20.04.2014
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).
Re: Set 3 Variables w/ one entry -
Calgon - 20.04.2014
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)
Re: Set 3 Variables w/ one entry -
austin070 - 20.04.2014
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.