04.09.2019, 13:29
Para o pessoal que quer manipular variбveis strings com strcmp.
PHP Code:
function CriarChaves(casaid)
{
/*
This function will create the house key.
Paramters:
casaid - From Iterator:House
*/
new FileChaves[50];
format(FileChaves, sizeof(FileChaves), PASTA_CHAVESCASAS, InfoCasa[casaid][ID]);
dini_Create(FileChaves);
// ------------------------------------------------------------------------------- //
new aString[MAX_NAME_PLAYER];
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
format(ChavesCasas[casaid][i], MAX_NAME_PLAYER, "Ninguem");
format(aString, sizeof(aString), "Chave%d", i);
dini_Set(FileChaves, aString, "Ninguem");
}
}
// ----------------------------------------------------------------------------------------------------------------------------------- //
function InserirChaveCasa(playerid, casaid)
{
/*
This function will enter a home key for a player.
Paramters:
playerid - The player
casaid - From Iterator:House
*/
new FileChaves[50];
format(FileChaves, sizeof(FileChaves), PASTA_CHAVESCASAS, InfoCasa[casaid][ID]);
// ------------------------------------------------------------------------------- //
new aString[MAX_NAME_PLAYER];
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
if(!strcmp(ChavesCasas[casaid][i], "Ninguem", false))
{
format(aString, sizeof(aString), "Chave%d", i);
dini_Set(FileChaves, aString, pNome(playerid));
return i;
}
}
return -1;
}
// ----------------------------------------------------------------------------------------------------------------------------------- //
function ContarChavesPlayer(playerid, casaid)
{
/*
This function will return how many keys a player has
from a certain house.
Paramters:
playerid - The Player
casaid - The house ID
*/
new Contar;
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
if(!strcmp(ChavesCasas[casaid][i], pNome(playerid), false))
{
Contar ++;
}
}
return Contar;
}
// ----------------------------------------------------------------------------------------------------------------------------------- //
function CarregarChavesCasas()
{
/*
This function will load all keys of a given house.
Paramters:
no Paramters
*/
new FileChaves[50], aString[50];
foreach(new c : House)
{
format(FileChaves, sizeof(FileChaves), PASTA_CHAVESCASAS, InfoCasa[c][ID]);
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
format(ChavesCasas[c][i], MAX_NAME_PLAYER, "Ninguem");
// ------------------------------------------------------------ //
format(aString, sizeof(aString), "Chave%d", i);
if(strcmp(dini_Get(FileChaves, aString), "Ninguem", false))
{
format(ChavesCasas[c][i], MAX_NAME_PLAYER, dini_Get(FileChaves, aString));
}
}
}
}
// ----------------------------------------------------------------------------------------------------------------------------------- //
function SalvarCasasChaves(casaid)
{
/*
This function will save all keys of a particular house.
Paramters:
casaid - The House ID
*/
new FileChaves[50], aString[15];
format(FileChaves, sizeof(FileChaves), PASTA_CHAVESCASAS, InfoCasa[casaid][ID]);
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
if(strcmp(ChavesCasas[casaid][i], "Ninguem", false))
{
format(aString, sizeof(aString), "Chave%d", i);
dini_Set(FileChaves, aString, ChavesCasas[casaid][i]);
}
}
}
// ----------------------------------------------------------------------------------------------------------------------------------- //
function DarChaves(playerid, id, casaid)
{
/*
This function will hand one of your keys to a
house to another player.
Paramters:
playerid - The Player ID
id - The player receiving the key
casaid - The Casa ID
*/
for(new i = 0; i < MAX_CHAVES_POR_CASA; ++ i)
{
if(!strcmp(ChavesCasas[casaid][i], pNome(playerid), false))
{
format(ChavesCasas[casaid][i], pNome(id));
return i;
}
}
// ------------------------------------------------------------------------------- //
SCMEx(playerid, 0xFF8D1CFF, "[ Chaves ]: Vocк deu uma chave da Casa ID: %d para o(a) jogador(a) %s.", casaid, pNome(id));
SCMEx(id, 0xFF8D1CFF, "[ Chaves ]: Vocк recebeu uma chave da Casa ID: %d do(a) jogador(a) %s.", casaid, pNome(playerid));
SalvarCasasChaves(casaid);
}