SA-MP Forums Archive
LP and SP - 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: LP and SP (/showthread.php?tid=426862)



LP and SP - CBCandyBoy - 30.03.2013

hello everyone i made a cmd for saving players current position and then teleporting them to those saved positions
here's the cmd

pawn Код:
CMD:sp(playerid,params[])
{
    #pragma unused params
    if(gPlayerInfo[playerid][LoggedIn] == 1 && gPlayerInfo[playerid][Level] >= 1)
    {
        new Float:x,Float:y,Float:z, interior, file[1000];
        GetPlayerPos(playerid,x,y,z);
        format(file, sizeof(file), PlayerFile);
        interior = GetPlayerInterior(playerid);

        dini_IntSet(file,"x",floatround(x));
        dini_IntSet(file,"y",floatround(y));
        dini_IntSet(file,"z",floatround(z));
        dini_IntSet(file,"interior",interior);
        dini_IntSet(file,"world", (GetPlayerVirtualWorld(playerid)));
        return SendClientMessage(playerid,COLOR_YELLOW,"~~ Coordinates of your position successfully saved! ~~");
    }
    else return SendClientMessage(playerid,red, "ERROR: You must be an administrator to use this command");
}
CMD:lp(playerid,params[])
{
    #pragma unused params
    if(gPlayerInfo[playerid][Level] >= 1)
    {
        new file[1000], Float:x, Float:y, Float:z;
        format(file, sizeof(file), PlayerFile);
        if (dini_Int(file, "x") != 0)
        {
            dini_Int(file, "x");
            dini_Int(file, "y");
            dini_Int(file, "z");
            SetPlayerPos(playerid,x,y,z);
            SetPlayerVirtualWorld(playerid, dini_Int(file, "world") );
            return SendClientMessage(playerid,COLOR_YELLOW,"~~ You have been teleported to your saved position ~~");
        }
        else return SendClientMessage(playerid,red,"ERROR: You not have a saved Position! (/gotoplace)");
    }
    else return SendClientMessage(playerid,red, "ERROR: You must be an administrator to use this command");
}



Re: LP and SP - Lady-Happy - 30.03.2013

Why did you post it here?


Re: LP and SP - CBCandyBoy - 30.03.2013

i need hep it dosent works even in the file it dont save cords


Re: LP and SP - RajatPawar - 30.03.2013

Jesus, a 1000 celled array ! !
What's the PlayerFile thing?


Re: LP and SP - CBCandyBoy - 30.03.2013

it saves players thing all money level name ping score.......


Re: LP and SP - Jochemd - 30.03.2013

Where is PlayerFile defined?


Re: LP and SP - CBCandyBoy - 30.03.2013

#define PlayerFile "CAdmin/Users/%s.ini"


Re: LP and SP - CBCandyBoy - 30.03.2013

in that looks like

Код:
Name=[CB]CandyBoy
Ip=192.168.1.3
Registered=1
Registered On:=30/3/2013
Password=147849867
Level=5
Money=0
Score=0
x=0
y=0
z=0
interior=0
world=0
Last On:=30/3/2013



Re: LP and SP - Pawnie - 30.03.2013

Hmm take a look at this.
Код:
enum pInfo
{
    Float:pPosX,
    Float:pPosY,
    Float:pPosZ,
    Float:pPosA,
    pInterior,
    pVw
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Код:
forward loadaccount_user(playerid, name[], value[]); 
public loadaccount_user(playerid, name[], value[])
{
	INI_Float("PositionX", PlayerInfo[playerid][pPosX]);
    INI_Float("PositionY", PlayerInfo[playerid][pPosY]);
    INI_Float("PositionZ", PlayerInfo[playerid][pPosZ]);
    INI_Float("Angle", PlayerInfo[playerid][pPosA]);
    INI_Int("Interior", PlayerInfo[playerid][pInterior]);
    INI_Int("VirtualWorld", PlayerInfo[playerid][pVw]);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	GetPlayerPos(playerid, PlayerInfo[playerid][pPosX],  PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
    GetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPosA]);
	if(fexist(Path(playerid)))
	{
	    new INI:file = INI_Open(Path(playerid)); 
	    INI_SetTag(file,"Player's Data");
   	    INI_WriteFloat(file,"PositionX", PlayerInfo[playerid][pPosX]);
	    INI_WriteFloat(file,"PositionY", PlayerInfo[playerid][pPosY]);
	    INI_WriteFloat(file,"PositionZ", PlayerInfo[playerid][pPosZ]);
	    INI_WriteFloat(file,"Angle", PlayerInfo[playerid][pPosA]);
	    INI_WriteInt(file,"Interior", GetPlayerInterior(playerid));
	    INI_WriteInt(file,"VirtualWorld", GetPlayerVirtualWorld(playerid));
            return 1;
}

public OnPlayerSpawn(playerid)
{
	if (PlayerInfo[playerid][pPosX] != 0 && PlayerInfo[playerid][pPosY] != 0 && PlayerInfo[playerid][pPosZ] != 0)
    {
        SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPosA]);
        SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
        SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVw]);
		return 1;
    }
    else
    {
        //Set normal pos here if they dont have acc
	}
    return 1;
}
Just make sure you make it that it will write the play pos on register.
Код:
INI_WriteFloat(file,"PositionX", 0);
		    INI_WriteFloat(file,"PositionY", 0);
		    INI_WriteFloat(file,"PositionZ", 0);
		    INI_WriteFloat(file,"Angle", 0);
		    INI_WriteInt(file,"Interior", 0);
		    INI_WriteInt(file,"VirtualWorld", 0);
Command example
Код:
CMD:gotpos(playerid, params[])
{
    if (PlayerInfo[playerid][pPosX] != 0 && PlayerInfo[playerid][pPosY] != 0 && PlayerInfo[playerid][pPosZ] != 0)
    {
        SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPosA]);
        SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
        SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVw]);
    }
}

CMD:savepos(playerid, params[])
{
    	new INI:file = INI_Open(Path(playerid));
	    INI_SetTag(file,"Player's Data");
   		INI_WriteFloat(file,"PositionX", PlayerInfo[playerid][pPosX]);
	    INI_WriteFloat(file,"PositionY", PlayerInfo[playerid][pPosY]);
	    INI_WriteFloat(file,"PositionZ", PlayerInfo[playerid][pPosZ]);
	    INI_WriteFloat(file,"Angle", PlayerInfo[playerid][pPosA]);
	    INI_WriteInt(file,"Interior", GetPlayerInterior(playerid));
	    INI_WriteInt(file,"VirtualWorld", GetPlayerVirtualWorld(playerid));
	    return 1;
}