id 1+ not spawning correctly
#1

Hey so I've implemented a reg/login system, that spawns you at Cranberry Station, allows you to choose your skin, using mSelection, and then allows you to play, saving your details (location, cash etc) upon disconnecting. However atm theres a really weird thing happening, where if there is more than 1 acc registered in the Accounts folder, the spawn location doesn't work and it spawns you at BB. Any help would be appreciated, it works perfectly for 1 player being registered, but once more than 1 acc is created it just stops.
Код:
enum pInfo
{
    pPass[129],
    pCash,
    pAdmin,
	Float:pXPos,
	Float:pYPos,
	Float:pZPos,
	Float:pAPos,
	pSkin,
    pUCAdmin,
	TotalTime,
	ConnectTime,
	hours,
	minutes,
	seconds,
	pDriverLicense,
	pInJail,
	pInJailTime,
	pBanned,
 	pBannedBy[30],
 	pReason[128],
    BannedIP[22]
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward SaveAccountStats(playerid);
public SaveAccountStats(playerid)
{
	if(LoggedIn[playerid] == 1)
    {
    new
        INI:File = INI_Open(UserPath(playerid))
    ;
    INI_SetTag(File,"data"); //Settings tags in y_ini is very important!

    PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
    new
        Float:x,
        Float:y,
        Float:z
    ;
    GetPlayerPos(playerid,x,y,z);
    PlayerInfo[playerid][pXPos] = x;
    PlayerInfo[playerid][pYPos] = y;
    PlayerInfo[playerid][pZPos] = z;
	new h, m, s;
    TotalGameTime(playerid, h, m, s);
	INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
	INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
	INI_WriteFloat(File, "PosX", PlayerInfo[playerid][pXPos]);
	INI_WriteFloat(File, "PosY", PlayerInfo[playerid][pYPos]);
	INI_WriteFloat(File, "PosZ", PlayerInfo[playerid][pZPos]);
	INI_WriteFloat(File, "PosA", PlayerInfo[playerid][pAPos]);
	INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
	INI_WriteInt(File, "UCAdmin", PlayerInfo[playerid][pUCAdmin]);
	INI_WriteInt(File, "DriversLicense", PlayerInfo[playerid][pDriverLicense]);
	INI_WriteInt(File, "Hours", PlayerInfo[playerid][hours] + h);
	INI_WriteInt(File, "Minutes", PlayerInfo[playerid][minutes]+ m);
	INI_WriteInt(File, "Seconds", PlayerInfo[playerid][seconds] + s);
	INI_WriteInt(File, "pInJail", PlayerInfo[playerid][pInJail]);
	INI_WriteInt(File, "pInJailTime", PlayerInfo[playerid][pInJailTime]);
	INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]);
	INI_WriteString(File, "BannedBy", PlayerInfo[playerid][pBannedBy]);
	INI_WriteString(File, "Reason", PlayerInfo[playerid][pReason]);


    INI_Close(File);
    }
    return 1;
}

function SaveAccounts()

{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SaveAccountStats(i); //Will be used to save the account stats
        }
    }
}

public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
	INI_Float("XPos",PlayerInfo[playerid][pXPos]);
	INI_Float("YPos",PlayerInfo[playerid][pYPos]);
	INI_Float("ZPos",PlayerInfo[playerid][pZPos]);
	INI_Float("APos",PlayerInfo[playerid][pAPos]);
	INI_Int("UCAdmin",PlayerInfo[playerid][pUCAdmin]);
	INI_Int("DriverLicense",PlayerInfo[playerid][pDriverLicense]);
	INI_Int("Hours",PlayerInfo[playerid][hours]);
	INI_Int("Minutes",PlayerInfo[playerid][minutes]);
	INI_Int("Seconds",PlayerInfo[playerid][seconds]);
	INI_Int("InJail",PlayerInfo[playerid][pInJail]);
	INI_Int("InJailTime",PlayerInfo[playerid][pInJailTime]);
	INI_Int("Banned", PlayerInfo[playerid][pBanned]);
	INI_String("BannedBy", PlayerInfo[playerid][pBannedBy],30);
	INI_String("ReasonBanned", PlayerInfo[playerid][pReason], 128);
    return 1;
}
Код:
stock UserPath(playerid)
{
    new string[128], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
Код:
public OnPlayerConnect(playerid)
{
	if(IsPlayerNPC(playerid)) return 1;
	if(fexist(UserPath(playerid))) 
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); //Loads the data from the user's textfile (password)
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","Type your password below in order to login.","Login","Quit");
    }
    else //If the path for Twizted in the Scriptfiles/Accounts directory is non-existent, the user is prompted to register or quit
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"Register","Type your password below in order to register a new account.","Register","Quit");
    }
	SetPlayerColor(playerid,COLOR_PLAYER);
	TogglePlayerSpectating(playerid, true);
	SendConnectionMessage(playerid, 1);
    stimer[playerid] = SetTimerEx("Speedometer", 100, true, "i", playerid);
    Speedo = CreatePlayerTextDraw(playerid, 530.0, 340.5," ");
    PlayerTextDrawShow(playerid,Speedo);
//    --- Zone
	for(new i=0; i<MAX_PLAYERS; i++){
	TextDrawHideForPlayer(i, Zones[i]);}
	//----Total Time in server
	//PlayerInfo[playerid][ConnectTime] = gettime();
	//----
   
    return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid); //If the player clicks the second button
            if(response) //If he clicks the first button
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit"); //This happens if the user has input no password. You can add limits here.
                new buf[129]; //Now we'll use our Whirlpool hashing
                new INI:File = INI_Open(UserPath(playerid)); //Opening the user file
                INI_SetTag(File,"data"); //Settings tags
                WP_Hash(buf, sizeof(buf), inputtext); //Hashing the inputtext (password)
                INI_WriteString(File,"Password", buf); //Writes a string, the password, hashed
             	INI_WriteInt(File, "Cash",0);
				INI_WriteInt(File, "Admin", 0);
				INI_WriteFloat(File, "PosX", 0);
				INI_WriteFloat(File, "PosY", 0);
				INI_WriteFloat(File, "PosZ", 0);
				INI_WriteFloat(File, "PosA", 0);
				INI_WriteInt(File,"Skin",0);
				INI_WriteInt(File, "UCAdmin", 0);
				INI_WriteInt(File, "DriversLicense",0);
				INI_WriteInt(File, "Hours",0);
				INI_WriteInt(File, "Minutes",0);
				INI_WriteInt(File, "Seconds", 0);
				INI_WriteInt(File, "pInJail",0);
				INI_WriteInt(File, "pInJailTime",0);
				INI_WriteInt(File, "Banned",0);
         
                INI_Close(File);

                pNewlyRegged[playerid] = true; //Changing the value of our boolean
				GivePlayerCash(playerid, 15000); //Gives a $15,000 ammount of starting cash
				SaveAccountStats(playerid); //Saves the player's account stats
				TogglePlayerSpectating(playerid, false);
				SetTimer("SpectateFix", 350, false); //Fixes a bug that needs this timer in order to successfully use mSelection
                SendPlayerFormattedText(playerid, COLOR_YELLOW,"Account '%s' created. You have been logged in automatically!", GetName(playerid), "");
                SendAllFormattedText(COLOR_GREEN, "%s has registered a new account. Welcome to our server!", GetName(playerid), "");
            }
        }
        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid ); //If the player clicks the second button
            if( response )
            {
                new hashpass[129];
                WP_Hash(hashpass,sizeof(hashpass),inputtext);
                if(!strcmp(hashpass, PlayerInfo[playerid][pPass], false))  //Compares the inputtext to the player's pass, pPass.
                {
                    TogglePlayerSpectating(playerid, false);
					pNewlyRegged[playerid] = false;
                    SetTimerEx("UnsetFirstSpawn", 5000, false, "i", playerid); //We're using this for other purposes, to fix a bug in skin selection (OnPlayerRequestClass)
                    SetPlayerCash(playerid, PlayerInfo[playerid][pCash]); //Gives the player the cash he has
                    SetSpawnInfo(playerid, 0 /*Because the player has no team*/, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pXPos], PlayerInfo[playerid][pYPos], PlayerInfo[playerid][pZPos], 1.0, -1, -1, -1, -1, -1, -1); //Sets the player's spawn information
					SpawnPlayer(playerid);
					
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit"); //If the player has entered an invalid password, he's prompted to retype his password
                }
                return false;
            }
        }
    }
    return 1;
   
}
Код:
public OnPlayerSpawn(playerid)
{
	if(pNewlyRegged[playerid]) //If the player is a newly registered player
    {
        ShowModelSelectionMenu(playerid, skinlist, "Skin Selection"); //Shows the skin selection menu for the player
    }
    
    if(PlayerInfo[playerid][pXPos] == 0 && PlayerInfo[playerid][pYPos] == 0) //Pretty much means that if the player isn't registered, his position is set to the position indicated in RandomSpawnLoc function
    {
		
        SetPlayerPos(playerid,-1969.3101,137.8635,27.6875);
		LoggedIn[playerid] = 1; //Changes the value of our variable "Logged" to 1("true").
    }
   
	for(new i=0; i<MAX_PLAYERS; i++){TextDrawShowForPlayer(i, Zones[i]);}

	return 1;
}
public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if(listid == skinlist)
    {
        if(response)
        {
            new string[129];
            format(string, sizeof(string), "{3685BA}SERVER: {FFFFFF}You have set your skin to ID %d!", modelid);
            SendClientMessage(playerid, -1, string);
            SetPlayerSkin(playerid, modelid);
            new INI:File = INI_Open(UserPath(playerid));
   			INI_SetTag(File,"data");
   			INI_WriteInt(File,"Skin",modelid);
   			INI_Close(File);
        }

        else
		{
			SendClientMessage(playerid, -1, "{3685BA}SERVER: {FFFFFF}You must select a skin.");
			ShowModelSelectionMenu(playerid, skinlist, "Skin Selection");
			return 1;
		}
    }
    return 1;
}
Код:
public OnPlayerRequestClass(playerid, classid)
{
	SpawnPlayer(playerid);
    return 1;
}
public OnPlayerRequestSpawn(playerid) {

	SetSpawnInfo(playerid, NO_TEAM, PlayerInfo[playerid][pSkin],PlayerInfo[playerid][pXPos], PlayerInfo[playerid][pYPos], PlayerInfo[playerid][pZPos],PlayerInfo[playerid][pAPos], 0, 0, 0, 0, 0, 0);
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)