string in SetPlayerPos.
#1

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.
Reply
#2

- 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.
Reply
#3

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

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...
Reply
#5

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

I need another way from sscanf, other ideas?
Reply
#7

Why do you?
Reply
#8

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

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.
Reply
#10

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)