PDA

View Full Version : |Suporte| Erro ao adicionar um evento



richardj
01/09/2015, 01:24 PM
Oi galera gostaria de uma ajuda sou leigo nesse assunto de programação estou tentando colocar um evento automático de (Matamata) mas esta dando uns erros Segue abaixo o Print do erro


[Only registered and activated users can see links]



Segue a baixo os codigos que usei

Matamata.cpp


#include "StdAfx.h"


cMataMata cMata;


void cMataMata::ResetMEvent()
{
InitTime = 0;
InitSeconds = 0;
TimeStage = 0;
SecondsStage = 0;
pCount = 0;
mtRunning = false;
Activated = false;
NextStage = false;
Finalize = false;
CurStage = 0;
TotalStages = 0;


for (int m = 0; m < MAXMTSTAGE; m++)
{
sMata[m].InCurse = false;
sMata[m].playerCount = 0;
sMata[m].InRound[0] = -1;
sMata[m].InRound[1] = -1;


for (int x = 4800; x < 5800; x++)
{
psPlayer[x].inMataEvent = 0;
psPlayer[x].WinnerLoser = 0;
psPlayer[x].MoveTime = 0;
psPlayer[x].pFighting = false;
psPlayer[x].pWaiting = false;
psPlayer[x].pScore = 0;
psPlayer[x].Index = -1;
psPlayer[x].pStage = 0;
sMata[m].sPlayer[x].Index = 0;
}
}
}


void cMataMata::Load()
{
ResetMEvent();
}


void cMataMata::GmCmdInit(LPOBJ lpObj, char* msg)
{
int aIndex = lpObj->m_Index;
int TempTime = atoi(msg);




if (TempTime < 1)
{
MsgOutput(aIndex, "Erro na configuração do evento!");
return;
}


InitTime = TempTime * 60;


if (pObj[aIndex].mAutority < 1)
{
MsgOutput(aIndex, "Você não tem autoridade para isso.");
return;
}


else if (Activated == true)
{
MsgOutput(aIndex, "Mata-Mata já está ativado.");
return;
}
else if(mtRunning == true)
{
MsgOutput(aIndex, "Mata-Mata já está rolando.");
return;
}
else if (psPlayer[aIndex].inMataEvent != 0)
{
MsgOutput(aIndex, "Você já éstá ocupado");
return;
}
else
{
psPlayer[aIndex].inMataEvent = 2;
Activated = true;
CurStage = 1;
AllServerAnnounce("%s iniciou o Mata-Mata", lpObj->Name);
MsgOutputAll("digite [/ir] para participar");
}
}


void cMataMata::PlayerCmdIWant(LPOBJ lpObj)
{
int aIndex = lpObj->m_Index;


if (mtRunning == true)
{
MsgOutput(aIndex, "Mata-Mata já está rolando.");
return;
}
else if (Activated == false)
{
MsgOutput(aIndex, "Mata-Mata não está ativado.");
return;
}
else if (psPlayer[aIndex].inMataEvent != 0)
{
MsgOutput(aIndex, "Você já está %s", (sMata->sPlayer[aIndex].inMataEvent == 1) ? "no evento" : "ocupado");
return;
}
else if (psPlayer[aIndex].pWaiting == true)
{
MsgOutput(aIndex, "Você já está aguardando.");
return;
}
else
{

psPlayer[aIndex].pWaiting = true;
psPlayer[aIndex].pStage = CurStage;
psPlayer[aIndex].inMataEvent = 1;
int id = GetPlayerCount();
sMata[CurStage].aIndex[id] = aIndex;

MsgOutput(aIndex, "Você entrou no Mata-Mata %d", id);
MsgOutput(aIndex, "Fique atento que vai começar!");
gObjTeleport(aIndex, 6, 72, 160);
sMata[CurStage].playerCount++;
}
}


void cMataMata::MataMataStart()
{

if (Activated == true && InitTime > 0)
InitSeconds++;


int TempRest;
TempRest = InitSeconds == (InitTime - 59) ? 1 : InitSeconds == (InitTime - 119) ? 2 : InitSeconds == (InitTime - 179) ? 3 : 4;
if (InitSeconds == (InitTime - 59) || InitSeconds == (InitTime - 119) || InitSeconds == (InitTime - 179) || InitSeconds == (InitTime - 239))
AllServerAnnounce("Mata-Mata começará em %d minuto(s)", TempRest);

if (InitSeconds == InitTime && mtRunning == false && Activated == true)
{
Activated = false;
InitSeconds = 0;
InitTime = 0;
TimeStage = 0;
SecondsStage = 0;
mtRunning = true;

sMata[CurStage].InCurse = true;
TotalStages = TotalStage();
AllServerAnnounce("MataMata Começou! %d", GetPlayerCount());
}


if (mtRunning == true)
{

if (NextStage == true)
{
if (TimeStage > 0)
SecondsStage++;


if (SecondsStage == TimeStage)
{
if (CurStage < TotalStages)
{
if (sMata[CurStage].InCurse == false)
{
CurStage++;
sMata[CurStage].InCurse = true;
TotalStages = TotalStage();


AllServerAnnounce("%s", (TotalStages - CurStage) == 0 ? "[Mata-mata]Última Rodada" : (TotalStages - CurStage) == 1 ? "[Mata-mata]Penultima Rodada" : "[Mata-mata]Próxima Rodada");
}
}
else
{
if (Finalize == true)
{
AllServerAnnounce("Mata-mata acabou!");
ResetMEvent();
}
}


NextStage = false;
TimeStage = 0;
SecondsStage = 0;
}
}
}
}


void cMataMata::SetPlayerToFight(LPOBJ lpObj)
{
int aIndex = lpObj->m_Index;

if (mtRunning == true && Activated == false && sMata[CurStage].InCurse == true)
{
if (lpObj->Connected == 3)
{
int TempContage = CountStagePlayer(CurStage);
int pRander;

if (TempContage > 1)
{
if (sMata[CurStage].InRound[0] == -1)
{
srand((unsigned)time(NULL));
pRander = 1 + (rand() % CountStagePlayer(CurStage));


if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage)
{
if (sMata[CurStage].aIndex[pRander] == aIndex && psPlayer[aIndex].pFighting == false)
{
psPlayer[aIndex].pWaiting = false;
psPlayer[aIndex].pFighting = true;
gObjTeleport(aIndex, 6, 121, 115);
lpObj->PkLevel = 6;
GCPkLevelSend(aIndex, 6);
sMata[CurStage].InRound[0] = aIndex;


}
}
}
if (sMata[CurStage].InRound[1] == -1)
{
srand((unsigned)time(NULL));
pRander = 1 + (rand() % CountStagePlayer(CurStage));
if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage)
{
if (sMata[CurStage].aIndex[pRander] == aIndex && psPlayer[aIndex].pFighting == false)
{
psPlayer[aIndex].pWaiting = false;
psPlayer[aIndex].pFighting = true;
gObjTeleport(aIndex, 6, 121, 116);
lpObj->PkLevel = 6;
GCPkLevelSend(aIndex, 6);
sMata[CurStage].InRound[1] = aIndex;
MsgOutputAll("%s X %s", gObj[sMata[CurStage].InRound[0]].Name, gObj[sMata[CurStage].InRound[1]].Name);
}
}
}
}
else if (TempContage == 1) // quando sobrar 1, joga ele pra próxima fase
{
srand((unsigned)time(NULL));
int TempCont = 1 + (rand() % CountStagePlayer(CurStage));


if (psPlayer[aIndex].pWaiting == true && psPlayer[aIndex].pStage == CurStage && psPlayer[aIndex].pFighting == false)
{


psPlayer[aIndex].pStage++;
sMata[psPlayer[aIndex].pStage].aIndex[CountStagePlayer(psPlayer[aIndex].pStage)] = aIndex;
MsgOutputAll("%s foi para próxima fase por W.O", lpObj->Name);
}
}
else
{

}
}
}
}


void cMataMata::SetPlayerEstage(LPOBJ lpObj, LPOBJ lpTarget)
{
int aIndex = lpObj->m_Index;
int tIndex = lpTarget->m_Index;
int Contp,TempCont;


if (mtRunning == true)
{
if (sMata[CurStage].InCurse == true)
{
if (psPlayer[aIndex].inMataEvent > 0 && psPlayer[tIndex].inMataEvent > 0 && psPlayer[aIndex].pFighting && psPlayer[tIndex].pFighting)
{
sMata[CurStage].sPlayer[aIndex].pScore++;
AllServerAnnounce("%s %d X %d %s", lpObj->Name, sMata[CurStage].sPlayer[aIndex].pScore, sMata[CurStage].sPlayer[tIndex].pScore, lpTarget->Name);

if (sMata[CurStage].sPlayer[aIndex].pScore == 3)
{

psPlayer[aIndex].pStage++;
TempCont = CountStagePlayer(psPlayer[aIndex].pStage);
psPlayer[aIndex].WinnerLoser = 1;
psPlayer[tIndex].WinnerLoser = 2;
psPlayer[aIndex].pFighting = false;
psPlayer[aIndex].pWaiting = false;
sMata[CurStage].sPlayer[aIndex].pScore = 0;
sMata[psPlayer[aIndex].pStage].aIndex[TempCont] = aIndex;



sMata[CurStage].sPlayer[tIndex].pScore = 0;
psPlayer[tIndex].inMataEvent = 0;
psPlayer[tIndex].pFighting = false;
psPlayer[tIndex].pWaiting = false;
psPlayer[tIndex].pStage = 0;

AllServerAnnounce("%s Venceu %s no Mata-mata", lpObj->Name,lpTarget->Name);

if (CountStagePlayer(CurStage) == 0)
{
if (CurStage == TotalStages)
{
AllServerAnnounce("%s Ganhou o Mata-mata", lpObj->Name);
TimeStage = 12;
Finalize = true;
NextStage = true;
}
else
{
TimeStage = 12;
if (GetPlayerCount() > 1)
{
NextStage = true;
sMata[CurStage].InCurse = false;
}
sMata[CurStage].InRound[0] = -1;
sMata[CurStage].InRound[1] = -1;
}
}
}
}
}
}
}


void cMataMata::MoveOfFightArea(LPOBJ lpObj)
{
int aIndex = lpObj->m_Index;
if (this->Activated == true || this->mtRunning)
{
if (psPlayer[aIndex].WinnerLoser != 0)
{
psPlayer[aIndex].MoveTime++;
if (psPlayer[aIndex].MoveTime >= 6)
{
if (psPlayer[aIndex].WinnerLoser == 1)
{


gObjTeleport(aIndex, 6, 72, 160);
psPlayer[aIndex].WinnerLoser = 0;
psPlayer[aIndex].MoveTime = 0;
psPlayer[aIndex].pWaiting = true;
}
else
{
lpObj->PkLevel = 3;
GCPkLevelSend(aIndex, 3);
gObjTeleport(aIndex, 6, 69, 93);
psPlayer[aIndex].WinnerLoser = 0;
psPlayer[aIndex].MoveTime = 0;
}

}
}
}
}


int cMataMata::CountStagePlayer(BYTE Stage)
{
int cont = 0;
if (this->Activated == true || this->mtRunning)
{
for (int i = 4800; i < 5800; i++)
{
if (gObj[i].Connected == 3)
{
if (psPlayer[i].inMataEvent == 1 && psPlayer[i].pStage == Stage)
{
cont++;
}
}
}
}
return cont;
}


int cMataMata::GetPlayerCount()
{
int cont = 0;
if (this->Activated == true || this->mtRunning)
{
for (int i = 4800; i < 5800; i++)
{
if (gObj[i].Connected == 3)
{
if (psPlayer[i].inMataEvent == 1)
{
cont++;
}
}
}
}
return cont;
}


int cMataMata::GetPlayerWaiting()
{
int cont = 0;
if (this->Activated == true || this->mtRunning)
{
for (int i = 4800; i < 5800; i++)
{
if (gObj[i].Connected == 3)
{
if (psPlayer[i].inMataEvent == 1 && psPlayer[i].pWaiting == true)
{
cont++;
}
}
}
}
return cont;
}


BYTE cMataMata::TotalStage()
{
int stage = 0;
int totalplayer = GetPlayerWaiting();




if (totalplayer >= 2)
{
if (totalplayer % 2 != 0)
stage = (totalplayer + 1) / 2;
else
stage = totalplayer / 2;
}
else
{
stage = 1;
}

return stage;
}



Matamata.h


#pragma once


#define MAXMTSTAGE 20
#define MAXMTPLAYER 20


struct sMTPlayer
{
BYTE inMataEvent; // 0 = no, 1 = player, 2 = gm
BYTE WinnerLoser; // 0 neutro, 1 = win, 2 = lose
bool pWaiting; // user
bool pFighting; // user
short pScore; // user
BYTE pStage; // user
int Index;


BYTE MoveTime;
};


struct sMataMata
{
sMTPlayer sPlayer[5800];
bool InCurse;
int aIndex[MAXMTPLAYER];
int InRound[2];
short playerCount;
};






class cMataMata
{
public:
void Load();
void GmCmdInit(LPOBJ lpObj, char* msg);
void PlayerCmdIWant(LPOBJ lpObj);
void MataMataStart();
void SetPlayerEstage(LPOBJ lpObj, LPOBJ lpTarget);
void SetPlayerToFight(LPOBJ lpObj);
void MoveOfFightArea(LPOBJ lpObj);


private:


void ResetMEvent();

int GetPlayerCount();
int CountStagePlayer(BYTE Stage);
BYTE TotalStage();
int GetPlayerWaiting();

short InitTime;
short InitSeconds;


short TimeStage, SecondsStage;


int pCount;
BYTE CurStage;
BYTE TotalStages;
bool mtRunning;
bool Activated;
bool NextStage;
bool Finalize;
sMataMata sMata[MAXMTSTAGE];
sMTPlayer psPlayer[5800];

};


extern cMataMata cMata;

s00x
01/09/2015, 01:33 PM
Você não declarou MsgOutput, MsgOutputAll nem AllServerAnnoun, da source que você removeu isto, da um F12 sobre cada função e veja a declaração que citei, e declara na sua custom.

richardj
01/09/2015, 01:46 PM
Eu nao peguei esse codigo de nem uma Source ele foi postado aqui no forum

E valeu por me falar do F12 isso vai me ajudar a tentar pegar o OffTrade de uma Source para tentar colocar nessa

s00x
01/09/2015, 01:56 PM
Certo, caso não encontre as declarações avise para podermos ajudar.

richardj
01/09/2015, 02:14 PM
eu nao achei se poder ajuda agradeço

s00x
01/09/2015, 04:42 PM
Bom, vamos la.

Arquivo .CPP


FUNCTION cFunctions;

void FUNCTION::SendMsgOut(DWORD aIndex,char *szMsg ...)
{
char Text[150];
va_list pArgs;
va_start(pArgs, szMsg);
vsprintf(Text,szMsg,pArgs);
va_end(pArgs);
GCServerMsgStringSend(Text, aIndex, 1);
}

void FUNCTION::SendMsgOutAll(char*Text, int type )
{
for(int i=OBJECT_MIN;i<OBJECT_MAX;i++)
{
OBJECTSTRUCT *lpObj = (OBJECTSTRUCT*)OBJECT_POINTER(i);

if(lpObj->Connected == 3)
{
GCServerMsgStringSend(Text,i,type);
}
}
}

void FUNCTION::ConnectSystem(int aIndex)
{
OBJECTSTRUCT * lpObj = (OBJECTSTRUCT*)OBJECT_POINTER(aIndex);

char Message[150];
sprintf(Message,"Ola [%s], Seja bem Vindo ao Servidor!",lpObj->Name);
GCServerMsgStringSend(Message, aIndex,0);
}


Arquivo .H


class FUNCTION{
public:
static void SendMsgOut(DWORD aIndex,char *szMsg ...);
static void SendMsgOutAll(char*Text, int type );
static void ConnectSystem(int aIndex);
};

extern FUNCTION cFunctions;


Para o ConnectSystem funcionar, você deve chamar ele no seu ProtocolCore na case 0x03

Só colocar isso aqui la FUNCTION::ConnectSystem(aIndex);


Obs; estou sem VS onde estou, fiz pelo Bloca de Notas, mais acho que é isso mesmo.

richardj
01/09/2015, 04:58 PM
colocando o FUNCTION::ConnectSystem(aIndex); tiro aqueles erros agora esse codigo que vc colocou .cpp .h eu tenho que criar eles tipo Funçao.cpp ou colocar o .cpp junto com o matamata.cpp

Vi que agora ficou um outro erro no Arquivo matamata.cpp
[Only registered and activated users can see links]




OBS: Obrigado pela ajuda que vc esta me dando

s00x
02/09/2015, 10:46 AM
Bom desculpa pela demora, fui em um casamento cheguei tarde e não entrei.

Sim, você deve ter o arquivo functions.cpp e functions.h .

Bom provavelmente seu ponteiro de acesso a Struct não deve estar feito corretamente ou não foi declarado, então eu teria que ver o código.
você pode solucionar isso chamando o ponteiro na requisição citada ai, no caso o ponteiro correto seria da seguinte forma.



OBJECTSTRUCT * gObj = (OBJECTSTRUCT*)OBJECT_POINTER(aIndex);


Seria legal você passar seu Skype para melhor poder te ajudar.

richardj
02/09/2015, 12:51 PM
pode add ai o Skype

SKYPE REMOVIDO

Contatos devem ser enviados apenas via MP

Maykon
02/09/2015, 03:40 PM
Você precisa também fazer uma thread para rodar o sistema!

richardj
02/09/2015, 06:49 PM
To tentando aprender um pouco com o tutorial postado aqui o Tutorial Dev Servidor mas ele ta todo misturado isso complica para quem nao tem conhecimento como eu

konvict
02/09/2015, 09:14 PM
Eu recomendo vc primeiro pegar alguma apostila de C/C++ antes de partir pra source de mu...
Se quiser realmente aprender, se não vai ficar só fazendo gambiarra e juntando códigos já existentes.
Lendo uma apostila básica, vc aprenderá o básico, tipos de dados, funções, chamar funções, structs, criar arquivos .cpp, .h etc...
Assim garanto que mais da metade das dúvidas que vc tem, serão resolvidas por vc mesmo. E conseguirá interpretar as sources existentes..

Fica aí minha dica, pois é como construir uma casa, é preciso o básico (alicerce), pra depois subir as paredes em cima dele...

richardj
02/09/2015, 09:34 PM
VLW eu ja baxei uma apostila aqui para dar uma lida o foda que nao tenho muito tempo para isso minha lan consome muito tempo mas msm assim vou lendo aos poucos e lendo tbm o tutorial postado aqui apesar dele ser confuso e Essa Source do Kinho que tou usando parece ser complicada que as outras

OBS: vcs aki da perfect foram os unicos que ajudaram postei esse msm problema em o utros forum e nada nem uma resposta

Maykon
02/09/2015, 10:39 PM
Caso ainda queira colocar o sistema, deixo aqui a thread :)


void ThreadMataMata(void *lpParam)
{
while (true) // Iniciar loop infinito
{
cMata.MataMataStart(); // Chamar função

for (int i = OBJECT_MIN; i < OBJECT_MAX;i++) // Loop players
{
if(gObj[i].Connected == 3) // Verifica se está logado
{
cMata.SetPlayerToFight(i); // Chamar função 2
}
}

Sleep(1000); // Espere 1 segundo para retornar ao inicio da função
}

_endthread(); // Exita thread
}

iris
09/09/2015, 07:55 PM
@Maykon Poderia Da Suporte Para Min Corrigem Erro Meu !!