Save and load player's position in/to RAM
#1

Hello everybody.

I wouldn't post here if I haven't tried to make it myself all the whole day and night.
I'm not a scripter but just a man who edits others' scripts using self logic and not a true knowledge.
So my examples can seem awkward to you. Sorry in advance.


I need to get player's position (including facing angle), then series of teleports must pass (it's kinda tutorial in the mod, where a player gets teleported to several locations consequentially and gets tutorial messages on screen while "traveling" across SA), and then, when the tutorial ends, player must teleport back to his previous location.

So I don't need player's coordinates to be stored in file, I need them to be temporarily stored in RAM and then (but not immediately) called back.

My example:

pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,xPos,yPos,zPos);
                    SetPlayerFacingAngle(playerid,Angle);
                     
                }

            }
(all coordinates here are only for example purposes)

But with this kind of code player does not get teleported back to his previous location... Instead he remains in the tutorial area with the adjusted camera and everything... So I suppose that GetPlayerPos does not remember that location but switches to the new location every time, so when SetPlayerPos(playerid,xPos,yPos,zPos) is applying, the coordiantes are already new, not old.


I don't know how to make SA-MP teleport player back in this situation.

Many thanks in advance for the help, it would be greatly appreciated.



Solution found: http://forum.sa-mp.com/showpost.php?...0&postcount=16
Reply
#2

Variables.
Reply
#3

Quote:
Originally Posted by arbit
Посмотреть сообщение
Variables.
Of course, I tried them.

pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                new TutX; //tried new Float:TutX
                new TutY; //tried new Float:TutY
                new TutZ; //tried new Float:TutZ
                TutX[playerid]=xPos; //tried putting "Float" to both
                TutY[playerid]=YPoz; //tried putting "Float" to both
                TutZ[playerid]=zPos; //tried putting "Float" to both
                TutA[playerid]=Angle; //tried putting "Float" to both
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,TutX,TutY,TutZ);
                    SetPlayerFacingAngle(playerid,TutA);
                     
                }

            }
But here is the result

pawn Код:
C:\SAMP\mod1.pwn(2671) : error 028: invalid subscript (not an array or too many subscripts): "TutX"
C:\SAMP\mod1.pwn(2671) : warning 215: expression has no effect
C:\SAMP\mod1.pwn(2671) : error 001: expected token: ";", but found "]"
C:\SAMP\mod1.pwn(2671) : error 029: invalid expression, assumed zero
C:\SAMP\mod1.pwn(2671) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

I should have wrote it first time, but I thought it was obvious.
Reply
#4

Quote:
Originally Posted by WellDone
Посмотреть сообщение
Of course, I tried them.

pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                new TutX; //tried new Float:TutX
                new TutY; //tried new Float:TutY
                new TutZ; //tried new Float:TutZ
                TutX[playerid]=xPos; //tried putting "Float" to both
                TutY[playerid]=YPoz; //tried putting "Float" to both
                TutZ[playerid]=zPos; //tried putting "Float" to both
                TutA[playerid]=Angle; //tried putting "Float" to both
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,TutX,TutY,TutZ);
                    SetPlayerFacingAngle(playerid,TutA);
                     
                }

            }
But here is the result

pawn Код:
C:\SAMP\mod1.pwn(2671) : error 028: invalid subscript (not an array or too many subscripts): "TutX"
C:\SAMP\mod1.pwn(2671) : warning 215: expression has no effect
C:\SAMP\mod1.pwn(2671) : error 001: expected token: ";", but found "]"
C:\SAMP\mod1.pwn(2671) : error 029: invalid expression, assumed zero
C:\SAMP\mod1.pwn(2671) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

I should have wrote it first time, but I thought it was obvious.
pawn Код:
new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
This should work
Reply
#5

Quote:
Originally Posted by Adytza.
Посмотреть сообщение
pawn Код:
new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
This should work
pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
                TutX[playerid]=xPos;
                TutY[playerid]=YPos;
                TutZ[playerid]=zPos;
                TutA[playerid]=Angle;
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,TutX,TutY,TutZ); //2783
                    SetPlayerFacingAngle(playerid,TutA); //2784
                     
                }
                telPos[0][playerid]=TutX;telPos[1][playerid]=TutY; // 2789 sorry forgot to mention, this is anti cheat teleport, in this line telPos[0] must be equal to X coordiante, telPos[1] = Y coordinate

            }

pawn Код:
C:\SAMP\mod1.pwn(2783) : error 035: argument type mismatch (argument 2)
C:\SAMP\mod1.pwn(2784) : error 035: argument type mismatch (argument 2)
C:\SAMP\mod1.pwn(2789) : error 006: must be assigned to an array
C:\SAMP\mod1.pwn(2789) : error 006: must be assigned to an array
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Reply
#6

Quote:
Originally Posted by WellDone
Посмотреть сообщение
pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
                TutX[playerid]=xPos;
                TutY[playerid]=YPos;
                TutZ[playerid]=zPos;
                TutA[playerid]=Angle;
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,TutX,TutY,TutZ); //2783
                    SetPlayerFacingAngle(playerid,TutA); //2784
                     
                }
                telPos[0][playerid]=TutX;telPos[1][playerid]=TutY; // 2789 sorry forgot to mention, this is anti cheat teleport, in this line telPos[0] must be equal to X coordiante, telPos[1] = Y coordinate.

            }

pawn Код:
C:\SAMP\mod1.pwn(2783) : error 035: argument type mismatch (argument 2)
C:\SAMP\mod1.pwn(2784) : error 035: argument type mismatch (argument 2)
C:\SAMP\mod1.pwn(2789) : error 006: must be assigned to an array
C:\SAMP\mod1.pwn(2789) : error 006: must be assigned to an array
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
What are the lines :
2789,2783 and 2784 ?
Reply
#7

You have declared these variables in a per-player format
pawn Код:
new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
Correct way to set them:

pawn Код:
SetPlayerPos(playerid,TutX[playerid],TutY[playerid],TutZ[playerid]); //2783
SetPlayerFacingAngle(playerid,TutA[playerid]); //2784
Reply
#8

pawn Код:
if(Tut[playerid]==1)
            {
                new Float:xPos, Float:yPos, Float:zPos, Float:Angle;
                GetPlayerPos(playerid,xPos,yPos,zPos);
                GetPlayerFacingAngle(playerid,Angle);
                new Float:TutX[MAX_PLAYERS],Float:TutY[MAX_PLAYERS],Float:TutZ[MAX_PLAYERS],Float:TutA[MAX_PLAYERS];
                TutX[playerid]=xPos;
                TutY[playerid]=YPos;
                TutZ[playerid]=zPos;
                TutA[playerid]=Angle;
                if(TutTime[playerid]==0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerPos(playerid,55.55,55.55,55.55);
                    SetPlayerCameraPos(playerid,66.66,66.66,66);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,59,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==15)
                {
                    SetPlayerPos(playerid,66.66,66.66,66.66);
                    SetPlayerCameraPos(playerid,77.77,77.77,77);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==25)
                {
                    SetPlayerPos(playerid,77.77,77.77,77.77);
                    SetPlayerCameraPos(playerid,88.88,88.88,88);
                    SetPlayerCameraLookAt(playerid,-99.9877,-5678.1234,2.0367);
                    ShowPlayerDialog(playerid,62,DIALOG_STYLE_MSGBOX,"Tutorial","My message","OK","");
                }
                if(TutTime[playerid]==60)
                {
                    Tut[playerid]=0;
                    SetPlayerPos(playerid,TutX[playerid],TutY[playerid],TutZ[playerid]); //2783
                    SetPlayerFacingAngle(playerid,TutA[playerid]); //2784
                     
                }
                telPos[0][playerid]=TutX[playerid];telPos[1][playerid]=TutY[playerid]; // 2789 sorry forgot to mention, this is anti cheat teleport, in this line telPos[0] must be equal to X coordiante, telPos[1] = Y coordinate.
            }

Compiled but still doesn't work, player teleports to his current location (tutorial area) and doesn't get teleported back.

P.S. sorry, I'll leave for a few hours, hope for your help, thanks in advance.
Reply
#9

I'm back, any suggestions? =(
Reply
#10

Bumping thread.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)