Nгo sou fracassado. Eu apenas sei diferenciar um GM que tem futuro e um que tem a probabilidade de nгo dar certo. Vocк tem que saber o que vocк precisa. Eu nгo estou te criticando.
Quer uma ajuda sobre organizaзхes? Ok.
Aprenda a usar variбveis. Sу com elas e um sistema de salvamento sгo o nucleo de um sistema de facзхes.
pawn Код:
#define MAX_FACTIONS 25
enum FACTION_RANK_INFO
{
fRank1[32],
fRank2[32],
fRank3[32],
fRank4[32],
fRank5[32],
fRank6[32],
fRank7[32],
fRank8[32],
fRank9[32],
fRank10[32],
fRank11[32],
fRank12[32],
fRank13[32],
fRank14[32],
fRank15[32]
}
enum FACTION_INFO
{
fName[64],
fType,
Float:fSpawn[3],
fSpawnProp,
fBank,
fRank[FACTION_RANK_INFO]
}
enum
{
FACTION_TYPE_CIV,
FACTION_TYPE_COP,
FACTION_TYPE_MEDIC,
FACTION_TYPE_LAW
}
new factionInfo[MAX_FACTIONS][FACTION_INFO];
Hook:Faction_OnPlayerConnect(playerid)
{
#if defined GAMEMODE_DEBUG
SendClientMessage(playerid, -1, "[DEBUG] Faction_OnPlayerConnect");
#endif
return 1;
}
public Faction_Init()
{
new Loaded;
printf("[FACTION] Faction_Init() - Executando consulta");
mysql_query("SELECT * FROM `game_factioninfo`");
mysql_store_result();
while(mysql_fetch_row(query))
{
new id, Name[64], Type, Float:Spawn[3], SpawnProp, Bank, Rank[15][32];
sscanf(query, "ds[32]da<f>[3]dda<s[32]>[15]", id, Name, Type, Spawn, SpawnProp, Bank, Rank);
if(!(id < MAX_FACTIONS))
continue;
Loaded++;
factionInfo[id][fName] = Name;
factionInfo[id][fType] = Type;
factionInfo[id][fSpawn] = Spawn;
factionInfo[id][fSpawnProp] = SpawnProp;
factionInfo[id][fBank] = Bank;
factionInfo[id][fRank][fRank1] = Rank[0];
factionInfo[id][fRank][fRank2] = Rank[1];
factionInfo[id][fRank][fRank3] = Rank[2];
factionInfo[id][fRank][fRank4] = Rank[3];
factionInfo[id][fRank][fRank5] = Rank[4];
factionInfo[id][fRank][fRank6] = Rank[5];
factionInfo[id][fRank][fRank7] = Rank[6];
factionInfo[id][fRank][fRank8] = Rank[7];
factionInfo[id][fRank][fRank9] = Rank[8];
factionInfo[id][fRank][fRank10] = Rank[9];
factionInfo[id][fRank][fRank11] = Rank[10];
factionInfo[id][fRank][fRank12] = Rank[11];
factionInfo[id][fRank][fRank13] = Rank[12];
factionInfo[id][fRank][fRank14] = Rank[13];
factionInfo[id][fRank][fRank15] = Rank[14];
printf("[FACTION] Faction_Init() - Facзгo %s[%d] carregada", id, Name);
}
printf("[FACTION] Faction_Init() - %d facзхes carregadas", Loaded);
mysql_free_result();
return 1;
}
public Faction_Save()
{
new i = MAX_FACTIONS;
while(i--)
if(strlen(factionInfo[i][fName]))
{
format(query, 80, "UPDATE `game_factioninfo` SET `bank`=%d WHERE `id`=%d", factionInfo[i][fBank], i);
mysql_query(query);
}
return 1;
}
public Faction_Reload()
{
Faction_Save();
Faction_Init();
}
// Otimizar com strcpy
stock Faction_GetRank(factionid, rankid)
{
new ret[32];
switch(rankid)
{
case 1: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank1]);
case 2: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank2]);
case 3: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank3]);
case 4: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank4]);
case 5: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank5]);
case 6: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank6]);
case 7: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank7]);
case 8: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank8]);//ret = factionInfo[factionid][fRank][fRank8];
case 9: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank9]);//ret = factionInfo[factionid][fRank][fRank9];
case 10: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank10]);//ret = factionInfo[factionid][fRank][fRank10];
case 11: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank11]);//ret = factionInfo[factionid][fRank][fRank11];
case 12: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank12]);//ret = factionInfo[factionid][fRank][fRank12];
case 13: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank13]);//ret = factionInfo[factionid][fRank][fRank13];
case 14: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank14]);//ret = factionInfo[factionid][fRank][fRank14];
case 15: format(ret, 32, "%s", factionInfo[factionid][fRank][fRank15]);//ret = factionInfo[factionid][fRank][fRank15];
}
return ret;
}
stock Player_GetRank(playerid)
{
return Faction_GetRank(playerInfo[playerid][pCharacter][cFaction], playerInfo[playerid][pCharacter][cFactionRank]);
}
CMD:rank(playerid, params[])
{
if(playerInfo[playerid][pStats] != PLAYER_STATS_INGAME)
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar no palco de jogo para executar este comando!");
if(!playerInfo[playerid][pCharacter][cFaction])
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar em uma facзгo para completar este comando!");
new f = playerInfo[playerid][pCharacter][cFaction];
new Player, Numero;
if(sscanf(params, "rd", Player, Numero))
{
format(query, 55, "_______ Ranks %s _______", factionInfo[f][fName]);
SendClientMessage(playerid, COLOR_GREEN, query);
new i = 0;
while(++i <= 15)
{
if(!strlen(Faction_GetRank(f, i)))
continue;
format(query, 40, "%d - %s", i, Faction_GetRank(f, i));
SendClientMessage(playerid, COLOR_GREY, query);
}
SendClientMessage(playerid, COLOR_GREY, "FactionCmd: /rank [playerid] [numero]");
return 1;
}
if(playerInfo[playerid][pCharacter][cFactionRank] > 3)
return SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /rank -{FFFFFF} Cargo insuficiente");
if(playerInfo[Player][pCharacter][cFaction] != f)
return SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /rank -{FFFFFF} Facзгo diferente!");
new Float:Pos[3];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
if(GetPlayerDistanceFromPoint(Player, Pos[0], Pos[1], Pos[2]) > 5.0)
return SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /rank -{FFFFFF} Vocк estб muito longe do playerid!");
format(query, QUERY_SIZE, "%s[ID:%d|AID:%d|CID:%d|SID:%d] setou o rank de %s[ID:%d|AID:%d|CID:%d|SID:%d] para %d(%s)", playerInfo[playerid][pName], playerid, playerInfo[playerid][pAid], playerInfo[playerid][pCharacter][cCid], playerInfo[playerid][pSession], playerInfo[Player][pName], Player, playerInfo[Player][pAid], playerInfo[Player][pCharacter][cCid], playerInfo[Player][pSession], Numero, Faction_GetRank(f, Numero));
format(query, QUERY_SIZE, "INSERT INTO `log_faction` (time, text, factionid) VALUES (%d, '%s', %d);", gettime(), query, f);
mysql_query(query);
playerInfo[Player][pCharacter][cFactionRank] = Numero;
format(query, 128, "(( %s %s promoveu/rebaixou %s %s para o cargo de %s ))", Player_GetRank(playerid), playerInfo[playerid][pName], Player_GetRank(Player), playerInfo[Player][pName], Faction_GetRank(f, Numero));
Player_ProxDetector(11.0, playerid, query, -1, -1, -1, -1, -1);
return 1;
}
CMD:faccao(playerid, params[])
{
if(playerInfo[playerid][pStats] != PLAYER_STATS_INGAME)
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar no palco de jogo para executar este comando!");
if(!playerInfo[playerid][pCharacter][cFaction])
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar em uma facзгo para completar este comando!");
SendClientMessage(playerid, COLOR_GREY, "Membros Online:");
foreach(new i : Player)
{
if(i == playerid)
continue;
if(playerInfo[i][pStats] != PLAYER_STATS_INGAME)
continue;
if(playerInfo[i][pCharacter][cFaction] != playerInfo[playerid][pCharacter][cFaction])
continue;
format(query, 80, "%s %s (Palco: %s)", Player_GetRank(i), playerInfo[i][pName], playerInfo[i][pCharacter][cName]);
SendClientMessage(playerid, COLOR_GREY, query);
}
format(query, 110, "Vocк: %s %s (Palco: %s)", Player_GetRank(playerid), playerInfo[playerid][pName], playerInfo[playerid][pCharacter][cName]);
SendClientMessage(playerid, COLOR_GREY, query);
return 1;
}
CMD:convidar(playerid, params[])
{
if(playerInfo[playerid][pStats] != PLAYER_STATS_INGAME)
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar no palco de jogo para executar este comando!");
if(!playerInfo[playerid][pCharacter][cFaction])
return SendClientMessage(playerid, COLOR_LIGHTRED, "Vocк precisa estar em uma facзгo para completar este comando!");
if(playerInfo[playerid][pCharacter][cFactionRank] > 3)
return SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /convidar {FFFFFF}- Cargo insuficiente");
new player;
if(sscanf(params, "rd", player))
return Player_SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /convidar [player]{FFFFFF}- Convida um determinado player para a facзгo (Status OOC/Fora de personagem)");
if(playerInfo[playerid][pStats] != PLAYER_STATS_INGAME)
return Player_SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /convidar [player]{FFFFFF}- O jogador nгo estб no Palco (IC)");
if(playerInfo[playerid][pCharacter][cFaction])
return Player_SendClientMessage(playerid, COLOR_LIGHTRED, "FactionCmd: /convidar [player]{FFFFFF}- O jogador jб estб em uma facзгo");
format(query, 150, "(( %s estб te convidando para a facзгo OOC %s. Digite /aceitar para se juntar а facзгo! ))", playerInfo[playerid][pName], factionInfo[playerInfo[playerid][pCharacter][cFaction]][fName]);
Player_SendClientMessage(player, COLOR_YELLOW, query);
format(query, 100, "(( Vocк acabou de convidar %s para a sua facзгo ))", playerInfo[player][pName]);
SendClientMessage(playerid, -1, query);
playerInfo[player][pInvite] = playerInfo[playerid][pCharacter][cFaction];
format(query, QUERY_SIZE, "%s[ID:%d|AID:%d|CID:%d|SID:%d] convidou %s[ID:%d|AID:%d|CID:%d|SID:%d] para a facзгo.", playerInfo[playerid][pName], playerid, playerInfo[playerid][pAid], playerInfo[playerid][pCharacter][cCid], playerInfo[playerid][pSession], playerInfo[player][pName], player, playerInfo[player][pAid], playerInfo[player][pCharacter][cCid], playerInfo[player][pSession]);
format(query, QUERY_SIZE, "INSERT INTO `log_faction` (time, text, factionid) VALUES (%d, '%s', %d);", gettime(), query, playerInfo[player][pInvite]);
mysql_query(query);
return 1;
}
CMD:aceitar(playerid, params[])
{
if(!playerInfo[playerid][pInvite])
return 1;
playerInfo[playerid][pCharacter][cFaction] = playerInfo[playerid][pInvite];
playerInfo[playerid][pCharacter][cFactionRank] = 15;
playerInfo[playerid][pInvite] = 0;
format(query, 130, "(( Parabйns, agora vocк й um membro da facзгo %s. Digite /ajuda para saber os comandos ))", factionInfo[playerInfo[playerid][pCharacter][cFaction]][fName]);
SendClientMessage(playerid, COLOR_YELLOW, query);
format(query, QUERY_SIZE, "%s[ID:%d|AID:%d|CID:%d|SID:%d] entrou para a facзгo.", playerInfo[playerid][pName], playerid, playerInfo[playerid][pAid], playerInfo[playerid][pCharacter][cCid], playerInfo[playerid][pSession]);
format(query, QUERY_SIZE, "INSERT INTO `log_faction` (time, text, factionid) VALUES (%d, '%s', %d);", gettime(), query, playerInfo[playerid][pInvite]);
mysql_query(query);
return 1;
}
/* ADMIN COMMANDS */
CMD:af(playerid, params[])
{
if(playerInfo[playerid][pRank] < PLAYER_RANK_ADMIN)
return SendClientMessage(playerid, COLOR_LIGHTRED, "AdmCmd: /(a)dmin(f)action {FFFFFF}- Vocк nгo tem permissгo para usar este comando!");
if(playerInfo[playerid][pStats] != PLAYER_STATS_ADMINDUTY)
return SendClientMessage(playerid, COLOR_LIGHTRED, "AdmCmd: /(a)dmin(f)action {FFFFFF}- Vocк deve sair do Palco e entrar no modo de Admin");
if(!strlen(params))
{
gt_Help:
SendClientMessage(playerid, COLOR_LIGHTRED, "AdmCmd: /(a)dmin(f)action [opзгo]:");
SendClientMessage(playerid, COLOR_LIGHTRED, "colocar [playerid] [facзгo] {FFFFFF}- Coloca o determinado player na determinada facзгo. (0 para tirar)");
SendClientMessage(playerid, COLOR_LIGHTRED, "rank [playerid] [rank(1-15)] {FFFFFF}- Seta o rank(cargo) de um determinado player em uma facзгo.");
SendClientMessage(playerid, COLOR_LIGHTRED, "respawn [facзгo] {FFFFFF}- Respawna os veнculos dessa facзгo.");
if(playerInfo[playerid][pRank] >= PLAYER_RANK_LEAD_ADMIN)
SendClientMessage(playerid, 0x1F4FB5FF, "recarregar [facзгo] {FFFFFF}- Recarrega a facзгo da database.");
return 1;
}
if(!strcmp(params, "colocar", true))
{
new player, faction;
if(sscanf(params, "{s[7]}rd", player, faction))
return SendClientMessage(playerid, COLOR_LIGHTRED, "AdmCmd: /af colocar [playerid] [facзгo] {FFFFFF}- Coloca o determinado player na determinada facзгo. (0 para tirar)");
if(!(0 <= faction < MAX_FACTIONS))
return SendClientMessage(playerid, 0x1F4FB5FF, "AdmCmd: /af colocar [playerid] [facзгo] {FFFFFF}- Essa facзгo nгo existe");
return 1;
}
else if(!strcmp(params, "rank", true))
{
return 1;
}
else if(!strcmp(params, "respawn", true))
{
return 1;
}
else if(!strcmp(params, "recarregar", true) && playerInfo[playerid][pRank] >= PLAYER_RANK_LEAD_ADMIN)
{
return 1;
}
else
goto gt_Help;
return 1;
}
Se vocк precisar de questхes referentes a erros de script, pode me mandar uma PM.