gTeam saving - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: gTeam saving (
/showthread.php?tid=262300)
gTeam saving -
krisis32 - 17.06.2011
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;
}
Re: gTeam saving -
krisis32 - 17.06.2011
*bump*
AW: gTeam saving -
Nero_3D - 17.06.2011
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;
}
Re: gTeam saving -
krisis32 - 17.06.2011
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
}
Re: gTeam saving -
DRIFT_HUNTER - 17.06.2011
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;
}
Re: gTeam saving -
Seven_of_Nine - 17.06.2011
By the way, I use GetPlayerTeam instead, and it's working fine..
Re: gTeam saving -
krisis32 - 17.06.2011
@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 .