All pastes #418280 Raw Edit

Someone

public text v1 · immutable
#418280 ·published 2007-03-31 15:10 UTC
rendered paste body
//you should understand later why i define this: 

#define X 0
#define Y 1
#define Z 2


//We will now create an enumeration :

enum PLAYER_INFOS
{
    bool:Logged,
    ClassID,
    SkinID,
    Float:Spawn_Pos[3]
}
new PlayerInfo[MAX_PLAYERS][PLAYER_INFOS];


// When the player choose a class, store his skin in the player info 'SkinID' and store his class in 'ClassID':

public OnPlayerRequestClass(playerid, classid)
{
    PlayerInfo[playerid][ClassID] = classid;
    
    switch (classid)
    {
        case 0: PlayerInfo[playerid][SkinID] = 1;
        case 1: PlayerInfo[playerid][SkinID] = 2;
	case 2: PlayerInfo[playerid][SkinID] = 49;
    }

    PlayerInfo[playerid][Spawn_Pos][X] =   719.9640;
    PlayerInfo[playerid][Spawn_Pos][Y] = -1447.8557;
    PlayerInfo[playerid][Spawn_Pos][Z] =    17.6953;
}


//When the player exit the game, you call SaveData(playerid); : 

SaveData(playerid)
{
    if (dini_Exists(FileName(playerid))) 
    {
        dini_IntSet(FileName(playerid),"skinid",PlayerInfo[playerid][SkinID]);
        dini_IntSet(FileName(playerid),"classid",PlayerInfo[playerid][ClassID]);
        dini_FloatSet(FileName(playerid),"spawn_x",PlayerInfo[playerid][Spawn_Pos][X]);
        dini_FloatSet(FileName(playerid),"spawn_y",PlayerInfo[playerid][Spawn_Pos][Y]);
        dini_FloatSet(FileName(playerid),"spawn_z",PlayerInfo[playerid][Spawn_Pos][Z]);
    }
    return 1;
}


//And when the player login, you call LoadData(playerid); :

LoadData(playerid)
{
    if (dini_Exists(FileName(playerid)))
    {
        PlayerInfo[playerid][SkinID]       = dini_Int(FileName(playerid),"skinid");
        PlayerInfo[playerid][ClassID]      = dini_Int(FileName(playerid),"classid");
        PlayerInfo[playerid][Spawn_Pos][X] = dini_Float(FileName(playerid),"spawn_x");
        PlayerInfo[playerid][Spawn_Pos][Y] = dini_Float(FileName(playerid),"spawn_y");
        PlayerInfo[playerid][Spawn_Pos][Z] = dini_Float(FileName(playerid),"spawn_z");
    }
    return 1;
}


// So now you can set the player pos and skin if he's logged, when he spawn :

public OnPlayerSpawn(playerid)
{
    if (PlayerInfo[playerid][Logged])
    {
        SetPlayerSkin(playerid,PlayerInfo[playerid][SkinID]);
        SetPlayerPos(playerid, PlayerInfo[playerid][Spawn_Pos][X],
                               PlayerInfo[playerid][Spawn_Pos][Y],
                               PlayerInfo[playerid][Spawn_Pos][Z]);
    }
}


// We call SaveData in OnlayerDisconnect :

public OnPlayerDisconnect(playerid)
{
    if(PlayerInfo[playerid][Logged]) SaveData(playerid);
}