Erro ao adicionar um evento
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. Click Here To Register...]
Segue a baixo os codigos que usei
Matamata.cpp
Código:
#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
Código:
#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;