0% acharam este documento útil (0 voto)
28 visualizações8 páginas

Chatcmds CPP

O documento é um código fonte que implementa comandos para um mod de jogo, permitindo que os jogadores interajam com o sistema através de comandos de chat. Os comandos incluem informações sobre o mod, ajuda, e opções de compra de upgrades usando pontos acumulados. O código também gerencia a lógica de compra e verificação de pontos dos jogadores para diferentes upgrades e habilidades.

Enviado por

tellesbel933
Direitos autorais
© © All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato TXT, PDF, TXT ou leia on-line no Scribd
0% acharam este documento útil (0 voto)
28 visualizações8 páginas

Chatcmds CPP

O documento é um código fonte que implementa comandos para um mod de jogo, permitindo que os jogadores interajam com o sistema através de comandos de chat. Os comandos incluem informações sobre o mod, ajuda, e opções de compra de upgrades usando pontos acumulados. O código também gerencia a lógica de compra e verificação de pontos dos jogadores para diferentes upgrades e habilidades.

Enviado por

tellesbel933
Direitos autorais
© © All Rights Reserved
Levamos muito a sério os direitos de conteúdo. Se você suspeita que este conteúdo é seu, reivindique-o aqui.
Formatos disponíveis
Baixe no formato TXT, PDF, TXT ou leia on-line no Scribd

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * * * * * */
/* Copyright � 2013 Neox.
*/
/* If you are missing that file, acquire a complete release at
https://www.teeworlds.com/forum/viewtopic.php?pid=106934 */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * */

#include <game/server/gamecontext.h>
#include <engine/shared/config.h>
#include "entities/protector.h"
#include <stdio.h>

void CGameContext::ExecuteCommand(int ClientID, const char* pCmd)


{
CPlayer* pPlayer = m_apPlayers[ClientID];
pCmd ++; // Skip the '/'

if(!str_comp_nocase(pCmd, "cmdlist"))
{
SendChatTarget(ClientID, "✦------CMDLIST------✦");
SendChatTarget(ClientID, "/info - Informações sobre o mod");
SendChatTarget(ClientID, "/help - Ajuda com o mod");
SendChatTarget(ClientID, "/loja - Compre upgrades");
SendChatTarget(ClientID, "/sendpoints <player> <quantidade> - Envia pontos
pro player");
}
else if(!str_comp_nocase(pCmd, "info"))
{
SendChatTarget(ClientID, "✦------INFO------✦");
SendChatTarget(ClientID, "Mod feito por Neox");
SendChatTarget(ClientID, "Você pode baixar esse mod pelo fórum do
Teeworlds.");
}
else if(!str_comp_nocase(pCmd, "help"))
{
SendChatTarget(ClientID, "✦------Ajuda------✦");
SendChatTarget(ClientID, "Você precisa matar monstros, pegar pontos, e com
esses pontos você consegue comprar upgrades");
SendChatTarget(ClientID, "Esses upgrades irão te ajudar a matar os monstros
mais facilmente.");
SendChatTarget(ClientID, "Como um exemplo você pode comprar regeneração,
assim você pode ganhar vida ou armor a cada segundo.");
SendChatTarget(ClientID, "Suas kills são seus pontos. Então quando comprar
algo, você perderá pontos.");
SendChatTarget(ClientID, "Se quiser dar uma olhada na loja, digite
\"/loja\"");
SendChatTarget(ClientID, "Divirta-se.");
}
else if(!str_comp_nocase(pCmd, "loja"))
{
SendChatTarget(ClientID, "✦------LOJA------✦");
SendChatTarget(ClientID, "/TeeNinja - 10 pts");
SendChatTarget(ClientID, "/GetWeapons - 15 pts");
SendChatTarget(ClientID, "/Vida <Qntd> - 15 pts por vida");
SendChatTarget(ClientID, "/dano <Qntd> - 50 pts por dano extra");
SendChatTarget(ClientID, "/Regen - 20 pts");
SendChatTarget(ClientID, "/ArmasAuto - 20 pts");
SendChatTarget(ClientID, "/Mina - 30 pts");
SendChatTarget(ClientID, "/InfAmmo - 30 pts munição infinita");
SendChatTarget(ClientID, "/Vampirismo - 40 pts");
SendChatTarget(ClientID, "/Espalhar - 50 pts tiro espalhado");
SendChatTarget(ClientID, "/TiroRapido - 50 pts");
SendChatTarget(ClientID, "/Protetor - 60 pts");
SendChatTarget(ClientID, "/RefletirDano - 60 pts");
SendChatTarget(ClientID, "/PowerfulWeapons - 100 pts");
}
else if(!str_comp_nocase(pCmd, "teeninja"))
{
if(!GetPlayerChar(ClientID))
{
SendChatTarget(ClientID, "Espere renascer para fazer isso.");
return;
}
if(pPlayer->m_Score >= 10)
{
pPlayer->m_Score -= 10;
GetPlayerChar(ClientID)->GiveNinja();
}
else
SendChatTarget(ClientID, "Você precisa de pelo menos 10 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "getweapons"))
{
if(!GetPlayerChar(ClientID))
{
SendChatTarget(ClientID, "Espere renascer para fazer isso.");
return;
}
if(pPlayer->m_Score >= 15)
{
pPlayer->m_Score -= 15;
for(int i = 1; i < NUM_WEAPONS-1; i++)
GetPlayerChar(ClientID)->GiveWeapon(i, 10);
SendChatTarget(ClientID, "Agora você tem todas as armas.");
}
else
SendChatTarget(ClientID, "Você precisa de pelo menos 15 pontos para
comprar isso!");
}
else if(!str_comp_nocase_num(pCmd, "vida", 6))
{
int Amount;
if(sscanf(pCmd, "health %d", &Amount) != 1)
{
SendChatTarget(ClientID, "Porfavor use de acordo com a estrutura:");
SendChatTarget(ClientID, "/vida <Qntd>");
return;
}
if(Amount < 1)
{
SendChatTarget(ClientID, "O mínimo é 1.");
return;
}
if(Amount > 1000000)
{
SendChatTarget(ClientID, "A quantidade é muito grande.");
return;
}
char aBuf[128];
if(pPlayer->m_Score >= Amount * 15)
{
pPlayer->m_Score -= Amount * 15;
pPlayer->m_Upgrades.m_Health += Amount;
str_format(aBuf, sizeof(aBuf), "Você comprou %d de vida", Amount);
}
else
str_format(aBuf, sizeof(aBuf), "Se você quiser comprar %d de vida, vai
precisar de %d pontos", Amount, Amount * 15);

SendChatTarget(ClientID, aBuf);
}
else if(!str_comp_nocase_num(pCmd, "dano ", 4))
{
int Amount;
if(sscanf(pCmd, "dano %d", &Amount) != 1)
{
SendChatTarget(ClientID, "Porfavor use de acordo com a estrutura:");
SendChatTarget(ClientID, "/dano <amount>");
return;
}
if(Amount < 1)
{
SendChatTarget(ClientID, "O mínimo é 1.");
return;
}
if(Amount > 1000000)
{
SendChatTarget(ClientID, "A quantidade é muito grande.");
return;
}
char aBuf[128];
if(pPlayer->m_Score >= Amount * 50)
{
pPlayer->m_Score -= Amount * 50;
pPlayer->m_Upgrades.m_Dmg += Amount;
str_format(aBuf, sizeof(aBuf), "Você comprou %d de dano extra.",
Amount);
}
else
str_format(aBuf, sizeof(aBuf), "Se você quiser comprar %d de dano
extra, vai precisar de %d pontos", Amount, Amount * 50);

SendChatTarget(ClientID, aBuf);
}
else if(!str_comp_nocase(pCmd, "regen"))
{
if(pPlayer->m_Score >= 20 && !pPlayer->m_Upgrades.m_Regeneration)
{
pPlayer->m_Score -= 20;
pPlayer->m_Upgrades.m_Regeneration = true;
SendChatTarget(ClientID, "Você agora possui regeneração");
}
else if(pPlayer->m_Upgrades.m_Regeneration)
SendChatTarget(ClientID, "Você já tem regeneração");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 20 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "armasauto"))
{
if(pPlayer->m_Score >= 20 && !pPlayer->m_Upgrades.m_AutoWeapons)
{
pPlayer->m_Score -= 20;
pPlayer->m_Upgrades.m_AutoWeapons = true;
SendChatTarget(ClientID, "Você agora possui as armas automáticas");
}
else if(pPlayer->m_Upgrades.m_AutoWeapons)
SendChatTarget(ClientID, "Você já tem as armas automáticas");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 20 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "mina"))
{
if(pPlayer->m_Score >= 30 && !pPlayer->m_Upgrades.m_Mine)
{
pPlayer->m_Score -= 30;
pPlayer->m_Upgrades.m_Mine = true;
SendChatTarget(ClientID, "Você agora possui as minas");
}
else if(pPlayer->m_Upgrades.m_Mine)
SendChatTarget(ClientID, "Você já tem as minas");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 30 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "infammo"))
{
if(pPlayer->m_Score >= 30 && !pPlayer->m_Upgrades.m_InfAmmo)
{
pPlayer->m_Score -= 30;
pPlayer->m_Upgrades.m_InfAmmo = true;
SendChatTarget(ClientID, "Você agora possui munição infinita");
if(GetPlayerChar(ClientID))
{
for(int i = 1; i < NUM_WEAPONS-1; i ++)
{
if(GetPlayerChar(ClientID)->GotWeapon(i))
GetPlayerChar(ClientID)->SetAmmo(i, 10);
}
}
}
else if(pPlayer->m_Upgrades.m_InfAmmo)
SendChatTarget(ClientID, "Você já tem munição infinita");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 30 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "vampirismo"))
{
if(pPlayer->m_Score >= 40 && !pPlayer->m_Upgrades.m_Vampirism)
{
pPlayer->m_Score -= 40;
pPlayer->m_Upgrades.m_Vampirism = true;
SendChatTarget(ClientID, "Você agora possui o vampirismo");
}
else if(pPlayer->m_Upgrades.m_Vampirism)
SendChatTarget(ClientID, "Você já tem o vampirismo");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 40 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "espalhar"))
{
if(pPlayer->m_Score >= 50 && !pPlayer->m_Upgrades.m_Spread)
{
pPlayer->m_Score -= 50;
pPlayer->m_Upgrades.m_Spread = true;
SendChatTarget(ClientID, "Você agora possui as armas com tiro
espalhado");
}
else if(pPlayer->m_Upgrades.m_Spread)
SendChatTarget(ClientID, "Você já tem as armas com tiro espalhado");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 50 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "tirorapido"))
{
if(pPlayer->m_Score >= 50 && !pPlayer->m_Upgrades.m_ShootingSpeed)
{
pPlayer->m_Score -= 50;
pPlayer->m_Upgrades.m_ShootingSpeed = true;
SendChatTarget(ClientID, "Você agora possui os tiros rápidos");
}
else if(pPlayer->m_Upgrades.m_ShootingSpeed)
SendChatTarget(ClientID, "Você já tem os tiros rápidos");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 50 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "protetor"))
{
if(pPlayer->m_Score >= 60 && !pPlayer->m_Upgrades.m_Protector)
{
pPlayer->m_Score -= 60;
pPlayer->m_Upgrades.m_Protector = true;
SendChatTarget(ClientID, "Você agora possui o protetor");
if(GetPlayerChar(ClientID))
new CProtector(&m_World, ClientID);
}
else if(pPlayer->m_Upgrades.m_Protector)
SendChatTarget(ClientID, "Você já tem o protetor");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 60 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "refletirdano"))
{
if(pPlayer->m_Score >= 60 && !pPlayer->m_Upgrades.m_DmgReflect)
{
pPlayer->m_Score -= 60;
pPlayer->m_Upgrades.m_DmgReflect = true;
SendChatTarget(ClientID, "Você agora possui o refletir dano");
}
else if(pPlayer->m_Upgrades.m_DmgReflect)
SendChatTarget(ClientID, "Você já tem o refletir dano");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 60 pontos para
comprar isso!");
}
else if(!str_comp_nocase(pCmd, "powerfulweapons"))
{
if(pPlayer->m_Score >= 100 && !pPlayer->m_Upgrades.m_PowerfulWeapons &&
pPlayer->GotAll())
{
pPlayer->m_Score -= 100;
pPlayer->m_Upgrades.m_PowerfulWeapons = true;
SendChatTarget(ClientID, "Você agora possui os powerful weapons");
}
else if(pPlayer->m_Upgrades.m_PowerfulWeapons)
SendChatTarget(ClientID, "Você já tem os powerful weapons");
else if(!pPlayer->GotAll())
SendChatTarget(ClientID, "Você precisa ter toda a loja para comprar
isso");
else
SendChatTarget(ClientID, "Você precisa de pelo menos 100 pontos para
comprar isso!");
}
else if(!str_comp_nocase_num(pCmd, "sendpoints", 10))
{
int Amount;
char Amountchar[64];
char pCmdBuf[str_length(pCmd) + 1];
mem_copy(pCmdBuf, pCmd, str_length(pCmd) + 1);

if(str_length(pCmd) > 64)


{
SendChatTarget(ClientID, "sua mensagem é muito longa");
return;
}

for (int i = str_length(pCmd) - 1; true; i--) // cut off the number from
the chatmessage
{
pCmdBuf[i] = '\0'; // cut it off
if(!(pCmd[i] >= '0' && pCmd[i] <= '9'))
{
if(pCmd[i] == ' ')
{
mem_copy(Amountchar, &pCmd[i+1], str_length(pCmd) - i); // save
it in Amountchar
Amount = str_toint(Amountchar); // make int out of it
break;
}
else
{
SendChatTarget(ClientID, "Porfavor use de acordo com a
estrutura:");
SendChatTarget(ClientID, "/sendpoints <player> <Qntd>");
return;
}
}
}

if(str_length(pCmdBuf) <= 11) // check the player name


{
SendChatTarget(ClientID, "Porfavor use de acordo com a estrutura:");
SendChatTarget(ClientID, "/sendpoints <player> <Qntd>");
return;
}

char name[str_length(pCmdBuf) - 11 + 1];


mem_move(name, pCmdBuf + 11, str_length(pCmdBuf) - 11 + 1);

if(Amount < 1)
{
SendChatTarget(ClientID, "O mínimo é 1");
return;
}
if(Amount > pPlayer->m_Score)
{
SendChatTarget(ClientID, "Você não tem esses pontos todos");
return;
}
for(int i = 0; i <= 16; i++)
{
if(Server()->ClientIngame(i) && !str_comp(name, (Server()-
>ClientName(i))))
{
pPlayer->m_Score -= Amount;
m_apPlayers[i]->m_Score += Amount;
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "Você enviou %d ponto(s) para %s",
Amount, name); // Done \o/
SendChatTarget(ClientID, aBuf);

char aBuf2[256];
str_format(aBuf2, sizeof(aBuf2), "%s te enviou %d ponto(s)",
Server()->ClientName(ClientID), Amount);
SendChatTarget(i, aBuf2);
break;
}
if(i >= 16)
{
char aBuf3[256];
str_format(aBuf3, sizeof(aBuf3), "Esse jogador não existe
(\"%s\")", name);
SendChatTarget(ClientID, aBuf3);
}
}
}
else if(!str_comp_nocase_num(pCmd, "setwave", 7))
{
int number;
if(sscanf(pCmd, "setwave %d", &number) != 1)
{
SendChatTarget(ClientID, "Porfavor use de acordo com a estrutura:");
SendChatTarget(ClientID, "/setwave <número>");
return;
}
if(number < 1)
{
SendChatTarget(ClientID, "O mínimo é 1");
return;
}
if(number > 1000000)
{
SendChatTarget(ClientID, "O número é muito grande");
return;
}

if(m_VoteCloseTime)
{
SendChatTarget(ClientID, "Espere a votação acabar antes de iniciar
outra.");
return;
}

int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 -


Server()->Tick();
if(pPlayer->m_LastVoteCall && Timeleft > 0)
{
char aChatmsg[512] = {0};
str_format(aChatmsg, sizeof(aChatmsg), "Espere %d segundos antes
de fazer outra votação", (Timeleft/Server()->TickSpeed())+1);
SendChatTarget(ClientID, aChatmsg);
return;
}
else
{
char aBuf[32];
char aBuf2[32];
str_format(aBuf, sizeof(aBuf), "set_wave %d", number);
str_format(aBuf2, sizeof(aBuf2), "%d", number);

char aChatmsg [512] = {0};


str_format(aChatmsg, sizeof(aChatmsg), "'%s' votou para mudar a
opção do servidor '%s %s'", Server()->ClientName(ClientID), "set wave to:", aBuf2);
SendChat(-1, CGameContext::CHAT_ALL, aChatmsg);

StartVote("set wave to", aBuf, aBuf2);


pPlayer->m_Vote = 1;
pPlayer->m_VotePos = m_VotePos = 1;
m_VoteCreator = ClientID;
pPlayer->m_LastVoteCall = Server()->Tick();
}
}
else
{
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "Typed : /%s", pCmd);
SendChatTarget(ClientID, "Esse comando não existe, tente \"/cmdlist\".");
SendChatTarget(ClientID, aBuf);
}
}

Você também pode gostar