SA-MP Forums Archive
string in SetPlayerPos. - 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: string in SetPlayerPos. (/showthread.php?tid=448561)



string in SetPlayerPos. - Activest - 04.07.2013

Hey.
I wanna make function to use string in SetPlayerPos, like:
SPP(playerid, "1234.1234, 1234.1234, 1234.1234");
But I don't have any idea to make it.
Thanks.


Re: string in SetPlayerPos. - Akira297 - 04.07.2013

- If you have no idea how to make yet, and won't attempt to make it either. You need to post this on Scripting Request.


Re: string in SetPlayerPos. - thimo - 04.07.2013

What do you mean Activest? I dont get what you are trying to do here. I would love to help you but....


Re: string in SetPlayerPos. - Activest - 04.07.2013

Hmm, for example:
new position[30];
position = "13424.0, 35892.0, 43647.0";

I want to put it in SetPlayerPos, like that:
SetPlayerPos(playerid, position);

But I can't find way for that...


Re: string in SetPlayerPos. - MP2 - 04.07.2013

Why would you store floats as a string? If you want this for a command input ('params'), use sscanf.


Re: string in SetPlayerPos. - Activest - 04.07.2013

I need another way from sscanf, other ideas?


Re: string in SetPlayerPos. - MP2 - 04.07.2013

Why do you?


Re: string in SetPlayerPos. - Activest - 04.07.2013

To load this string from file to one variable that I can use this variable in SetPlayerPos in few publics.


Re: string in SetPlayerPos. - MP2 - 04.07.2013

Quote:
Originally Posted by Activest
Посмотреть сообщение
To load this string from file to one variable that I can use this variable in SetPlayerPos in few publics.
You can't store THREE values in ONE variable. You need to declare THREE float variables, and use SSCANF to SPLIT the string up into the THREE variables.


Re: string in SetPlayerPos. - stokdam - 05.07.2013

Try this:
pawn Код:
new position[30];
position = "13424.0,35892.0,43647.0";
//NO SPACES BETWEEN FLOATS, JUST USE COMMA


strtokv(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ','))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ',') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}


stock SetPlayerPosFromString(playerid,strpos[256])
{
new Float:x, Float:y, Float:z;
new idx;
x=floatstr(strtokv(strpos,idx));
y=floatstr(strtokv(strpos,idx));
z=floatstr(strtokv(strpos,idx));
SetPlayerPos(playerid,x,y,z);
return 1;
}