gTeam saving
#1

I am trying to set player to team from .ini file but the player can select team from selection class. Here is the code:

Код:
#define POLICE 0
#define POLICEE 1
new gTeam[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    new pname[128];  
    new file[128];      
    GetPlayerName(playerid, pname, sizeof(pname)); 
   format(file, sizeof(file), saves,pname); 
    if(!dini_Exists(file)) {
    dini_Create(file); 
 
    dini_IntSet(file, "Team", gTeam[playerid]);
   
    SetPlayerTeam(playerid, dini_Int(file, "Team"));
    }
    else {
    SetPlayerTeam(playerid, dini_Int(file, "Team"));
    }
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new pname[128]; 
    new file[128]; 
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), saves,pname);
    if(!dini_Exists(file)) { 
    }
    else { 
    dini_IntSet(file, "Team", gTeam[playerid]);
    }
    SaveStats(playerid);

	return 1;
}

public OnPlayerSpawn(playerid)
{
   SetPlayerTeam(playerid, dini_Int(file, "Team"));
    SetPlayerToTeamColour(playerid);

	return 1;
}
Reply
#2

*bump*
Reply
#3

You forgot to set gTeam to the team in the file at OnPlayerConnect

pawn Код:
enum {
    POLICE,
    POLICEE
}
stock gTeam[MAX_PLAYERS];
pawn Код:
public OnPlayerConnect(playerid)
{
    new file[128];      
    GetPlayerName(playerid, file, MAX_PLAYER_NAME);
    format(file, sizeof(file), saves, file);
    if(dini_Exists(file)) {
        gTeam[playerid] = dini_Int(file, "Team");
    } else {
        dini_Create(file);
        gTeam[playerid] = -1; //no team
    }
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128];
    GetPlayerName(playerid, file, MAX_PLAYER_NAME);
    format(file, sizeof(file), saves, file);
    dini_IntSet(file, "Team", gTeam[playerid]);
    SaveStats(playerid);
    return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
    SetPlayerTeam(playerid, gTeam[playerid]);
    SetPlayerToTeamColour(playerid);
    return 1;
}
Reply
#4

Thanks man! That works like charm, but how to make so i cant select other skins if player have .ini file ?
I have this:
Код:
GetPlayerName(playerid, name, sizeof(name));
     format(file, sizeof(file), saves, name);
     if(fexist(file))
     {
     SetPlayerTeam(playerid, gTeam[playerid]);
     SetPlayerToTeamColour(playerid);
     }
     if(!fexist(file))
     {
     // selected skin
     }
Reply
#5

Try to add on player request class
pawn Код:
public OnPlayerRequestClass(playerid,classid)
{
    new pname[128];  
    new file[128];      
    GetPlayerName(playerid, pname, sizeof(pname));
   format(file, sizeof(file), saves,pname);
    if(dini_Exists(file))
    {
        SpawnPlayer(playerid);
    }
    else
    {
      // code for request class as SetPlayerCameraPos
     }
    return 1;
}
Reply
#6

By the way, I use GetPlayerTeam instead, and it's working fine..
Reply
#7

@DRIFT_HUNTER still can select skin I made it now to save skin so i could spawn with it, but how to not allow to select skins if file exist ?
@Seven_of_Nine I was trying to do it too but messed up .
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)