19.01.2010, 18:38
Bem estou aqui a alterar um sistema de gangs que encontrei na net..
mas preciso de ajuda aqui numa coisa...
Por exemplo: Eu crio um gang (cmd: /gang create NtK) depois convido jogadores, mas depois de todos os jogadores sairem do servidor...
o gang deixa de existir e quando se voltar a entrar tem de se criar um novo alguem sabe como fazer para este fazer com que os gangs fiquem guardados nos scriptfiles
mas preciso de ajuda aqui numa coisa...
Por exemplo: Eu crio um gang (cmd: /gang create NtK) depois convido jogadores, mas depois de todos os jogadores sairem do servidor...
o gang deixa de existir e quando se voltar a entrar tem de se criar um novo alguem sabe como fazer para este fazer com que os gangs fiquem guardados nos scriptfiles
pawn Code:
#include <a_samp>
#include <core>
#include <float>
#pragma tabsize 0
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA //white
#define COLOR_BLUE 0x33CCFFAA //blue
#define COLOR_GREY 0xAFAFAFAA //grey
#define COLOR_LIGHTBLUE 0x33CCFFAA //light blue
#define COLOR_ORANGE 0xFF9900AA //orange
#define COLOR_GRAD1 0xB4B5B7AA
#define COLOR_GRAD2 0xBFC0C2AA
#define COLOR_GRAD3 0xCBCCCEAA
#define FILTERSCRIPT
#define NUMVALUES 4
forward PlayerLeaveGang(playerid);
forward isPlayerInArea(playerID, Float:data[4]);
forward PayPlayerInArea(playerID, Float:x1, Float:y1, Float:x2, Float:y2, cash);
forward SendPlayerFormattedText(playerid, const str[], define);
forward SendAllFormattedText(playerid, const str[], define);
new playerColors[100] = {
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x48C000FF,0x2A51E2FF,0xE3AC12FF,
0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
0x3FE65CFF
};
#define MAX_GANGS 32
#define MAX_GANG_MEMBERS 6
#define MAX_GANG_NAME 16
new gangMembers[MAX_GANGS][MAX_GANG_MEMBERS];
new gangNames[MAX_GANGS][MAX_GANG_NAME];
new gangInfo[MAX_GANGS][3]; //0-created,1-members,2-color
new gangBank[MAX_GANGS];
new playerGang[MAX_PLAYERS];
new gangInvite[MAX_PLAYERS];
main()
{
print("\n--------------------------------------");
print(" BANK+PROPS+GANGS+BOUNTY");
print("--------------------------------------\n");
}
public PlayerLeaveGang(playerid) {
new string[256];
new playername[MAX_PLAYER_NAME];
new gangnum = playerGang[playerid];
if(gangnum > 0) {
for(new i = 0; i < gangInfo[gangnum][1]; i++) {
if(gangMembers[gangnum][i]==playerid) {
//One less gang member
gangInfo[gangnum][1]--;
for(new j = i; j < gangInfo[gangnum][1]; j++) {
//Shift gang members
gangMembers[gangnum][j]=gangMembers[gangnum][j+1];
}
//Disband gang if no more members
if(gangInfo[gangnum][1]<1) {
gangInfo[gangnum][0]=0;
gangInfo[gangnum][1]=0;
gangBank[gangnum]=0;
}
//Notify other members
for(new j = 0; j < gangInfo[gangnum][1]; j++) {
GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
format(string, sizeof(string),"[Gang|News] %s saiu do teu gang.", playername);
SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
}
format(string, sizeof(string),"[Gang|News] Sais-te do gang '%s' (id: %d)", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_ORANGE, string);
playerGang[playerid]=0;
SetPlayerColor(playerid,playerColors[playerid]);
return;
}
}
} else {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Nгo estбs num gang.");
}
}
public isPlayerInArea(playerID, Float:data[4])
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerID, X, Y, Z);
if(X >= data[0] && X <= data[2] && Y >= data[1] && Y <= data[3]) {
return 1;
}
return 0;
}
public PayPlayerInArea(playerID, Float:x1, Float:y1, Float:x2, Float:y2, cash)
{
if(IsPlayerConnected(playerID))
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerID, X, Y, Z);
if(X >= x1 && X <= x2 && Y >= y1 && Y <= y2)
{
GivePlayerMoney(playerID, cash);
return 1;
}
}
return 0;
}
//------------------------------------------------------------------------------------------------------
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new cmd[256];
new giveplayerid, idx;
new playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/gang", true) == 0) {
new tmp[256];
new gangcmd, gangnum;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USA: /gang [criar/entrar/convidar/sair] [nome/numero]");
return 1;
}
giveplayerid = strval(tmp);
if(strcmp(tmp, "criar", true)==0)
gangcmd = 1;
else if(strcmp(tmp, "convidar", true)==0)
gangcmd = 2;
else if(strcmp(tmp, "entrar", true)==0)
gangcmd = 3;
else if(strcmp(tmp, "sair", true)==0)
gangcmd = 4;
tmp = strtok(cmdtext, idx);
if(gangcmd < 3 && !strlen(tmp)) {
if(gangcmd==0)
SendClientMessage(playerid, COLOR_WHITE, "USA: /gang [criar/entrar/convidar/sair] [nome/numero]");
else if(gangcmd==1)
SendClientMessage(playerid, COLOR_WHITE, "USA: /gang [criar] [nome]");
else if(gangcmd==2)
SendClientMessage(playerid, COLOR_WHITE, "USA: /gang [convidar] [playerID]");
return 1;
}
//Create Gang//
if(gangcmd==1) {
if(playerGang[playerid]>0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Jб estбs num gang!");
return 1;
}
for(new i = 1; i < MAX_GANGS; i++) {
if(gangInfo[i][0]==0) {
//name gang
format(gangNames[i], MAX_GANG_NAME, "%s", tmp);
//Gang exists
gangInfo[i][0]=1;
//There is one member
gangInfo[i][1]=1;
//Gang color is player's color
gangInfo[i][2]=playerColors[playerid];
//Player is the first gang member
gangMembers[i][0] = playerid;
format(string, sizeof(string),"[Gang|News] Crias-te o gang '%s' (id: %d)", gangNames[i], i);
SendClientMessage(playerid, COLOR_GREEN, string);
playerGang[playerid]=i;
return 1;
}
}
return 1;
//Join Gang//
} else if (gangcmd==3) {
gangnum = gangInvite[playerid];
if(playerGang[playerid]>0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Jб estбs num gang!");
return 1;
}
if(gangInvite[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Nгo recebes-te nenhum convite para entrar num gang.");
return 1;
}
if(gangInfo[gangnum][0]==0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Esse gang nгo existe!");
return 1;
}
if(gangInfo[gangnum][1] < MAX_GANG_MEMBERS) {
new i = gangInfo[gangnum][1];
gangInvite[playerid]=0;
gangMembers[gangnum][i] = playerid;
GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
for(new j = 0; j < gangInfo[gangnum][1]; j++) {
format(string, sizeof(string),"[Gang|News] %s entrou no teu gang.", sendername);
SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
}
gangInfo[gangnum][1]++;
playerGang[playerid] = gangnum;
SetPlayerColor(playerid,gangInfo[gangnum][2]);
format(string, sizeof(string),"[Gang|News] Entras-te no gang '%s' (id: %d)", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Esse gang estб cheio.");
return 1;
//Invite to Gang//
} else if (gangcmd==2) {
giveplayerid = strval(tmp);
if(playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Nгo estбs num gang!");
return 1;
}
if(gangMembers[playerGang[playerid]][0]!=playerid) {
SendClientMessage(playerid, COLOR_RED, "Precisas de ser Lider do Gang para poderes enviar um convite.");
return 1;
}
if(IsPlayerConnected(giveplayerid)) {
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string),"[Gang|News] Envias-te um convite para o/a %s para entrar no gang.", giveplayer);
SendClientMessage(playerid, COLOR_GREEN, string);
format(string, sizeof(string),"[Gang|News] Recebes-te um convite para entrar no gang %s do/a '%s' (id: %d)", sendername, gangNames[playerGang[playerid]],playerGang[playerid]);
SendClientMessage(giveplayerid, COLOR_GREEN, string);
gangInvite[giveplayerid]=playerGang[playerid];
} else
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Esse jogador nгo existe!");
//Leave Gang//
} else if (gangcmd==4) {
PlayerLeaveGang(playerid);
}
return 1;
}
//------------------- /ganginfo
if(strcmp(cmd, "/ganginfo", true) == 0) {
new tmp[256];
new gangnum;
tmp = strtok(cmdtext, idx);
if(!strlen(tmp) && playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_WHITE, "USA: /ganginfo [numero]");
return 1;
} else if (!strlen(tmp))
gangnum = playerGang[playerid];
else
gangnum = strval(tmp);
if(gangInfo[gangnum][0]==0) {
SendClientMessage(playerid, COLOR_RED, "[Gang|News] Esse gang nгo existe!");
return 1;
}
format(string, sizeof(string),"'%s' Membros do Gang (id: %d)", gangNames[gangnum], gangnum);
SendClientMessage(playerid, COLOR_GREEN, string);
for(new i = 0; i < gangInfo[gangnum][1]; i++) {
GetPlayerName(gangMembers[gangnum][i], giveplayer, sizeof(giveplayer));
format(string, sizeof(string),"%s (%d)", giveplayer, gangMembers[gangnum][i]);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}
//------------------- /gangs
if(strcmp(cmd, "/gangs", true) == 0)
{
new x;
SendClientMessage(playerid, COLOR_GREEN, "[Gang|News] Code-R3D | O Teu Mundo (GANGS) :");
for(new i=0; i < MAX_GANGS; i++) {
if(gangInfo[i][0]==1) {
format(string, sizeof(string), "%s%s(%d) - %d membros", string,gangNames[i],i,gangInfo[i][1]);
x++;
if(x > 2) {
SendClientMessage(playerid, COLOR_YELLOW, string);
x = 0;
format(string, sizeof(string), "");
} else {
format(string, sizeof(string), "%s, ", string);
}
}
}
if(x <= 2 && x > 0) {
string[strlen(string)-2] = '.';
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}
return 0;
}
public OnPlayerText(playerid, text[])
{
if(text[0] == '!') {
if(playerGang[playerid] > 0) {
new gangChat[256];
new string[256];
// for(new i = 1; i < strlen(text)+1; i++)
// gangChat[i]=text[i];
strmid(gangChat,text,1,strlen(text));
format(string, sizeof(string),"(Gang|Chat) %s: %s", gangChat);
for(new i = 0; i < gangInfo[playerGang[playerid]][1]; i++) {
SendClientMessage(gangMembers[playerGang[playerid]][i], COLOR_LIGHTBLUE, string);
}
}
return 0;
}
return 1;
}
//------------------------------------------------------------------------------------------------------
public OnFilterScriptInit()
{
SetTimer("SavedUpdate",60017, 1);
return 1;
}
public SendPlayerFormattedText(playerid, const str[], define)
{
new tmpbuf[256];
format(tmpbuf, sizeof(tmpbuf), str, define);
SendClientMessage(playerid, 0xFFFF00AA, tmpbuf);
}
public SendAllFormattedText(playerid, const str[], define)
{
new tmpbuf[256];
format(tmpbuf, sizeof(tmpbuf), str, define);
SendClientMessageToAll(0xFFFF00AA, tmpbuf);
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}