.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Enhancement Workshop > Metamod and metamod plugins
Metamod and metamod plugins Plugins and improvements for the metamod server-side mod

Reply
 
Thread Tools
Turn the CS 1.6 twisted buy menu to old one
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Turn the CS 1.6 twisted buy menu to old one - 13-02-2004

Code:
 //
 // Oldbuy metamod plugin
 // Written by: Wei Mingzhi, February 2004
 //
 // This plugin should only be used in CS 1.6
 // it can turn CS 1.6 twisted buy menu to old CS 1.5 buy menu
 //
 // Note: (1) VGUI menu is not supported because it is in client.dll
 //	   (2) It will affect all clients connected to this server
 //
 //////////////////////////////////////////////////////////////
 
 #include "extdll.h"
 #include "dllapi.h"
 #include "meta_api.h"
 #include "h_export.h"
 
 enginefuncs_t g_engfuncs;
 globalvars_t *gpGlobals;
 enginefuncs_t meta_engfuncs;
 
 DLL_FUNCTIONS gFunctionTable;
 
 meta_globals_t *gpMetaGlobals;
 gamedll_funcs_t *gpGamedllFuncs;
 mutil_funcs_t *gpMetaUtilFuncs;
 
 char g_argv[1024];
 bool isFakeClientCommand = FALSE;
 int fake_arg_count;
 
 typedef enum
 {
    Menu_Buy,
    Menu_BuyPistol,
    Menu_BuyRifle,
    Menu_BuyMachineGun,
    Menu_BuyShotgun,
    Menu_BuySubMachineGun,
    Menu_BuyItem,
    Menu_None
 } menu_state_t;
 
 menu_state_t g_CurMenuState = Menu_None;
 
 char *Buy =
 {
 "\\yBuy Item\\w\n\n"
 "1. Handgun\n"
 "2. Shotgun\n"
 "3. Sub-Machine Gun\n"
 "4. Rifle\n"
 "5. Machine Gun\n\n"
 "6. Primary weapon ammo\n"
 "7. Secondary weapon ammo\n\n"
 "8. Equipment\n\n"
 "0. Exit"
 };
 
 char *BuyItem =
 {
 "\\yBuy Equipment\\R$   Cost\n\n"
 "\\w1. Kevlar Vest\\y\\R650\n"
 "\\w2. Kevlar Vest & Helmet\\y\\R1000\n"
 "\\w3. Flashbang\\y\\R200\n"
 "\\w4. HE Grenade\\y\\R300\n"
 };
 char *BuyItem_2 =
 {
 "\\w5. Smoke Grenade\\y\\R300\n"
 "\\w6. Defuse Kit\\y\\R200\n"
 "\\w7. NightVision Goggles\\y\\R1250\n\n"
 "\\w8. Tactical Shield\\y\\R2200\n\n"
 "\\w0. Exit"
 };
 
 char *BuyPistol =
 {
 "\\yBuy Handgun\\R$   Cost\n"
 "(Secondary weapon)\n\n"
 "\\w1. H&K USP .45 Tactical\\y\\R500\n"
 "\\w2. Glock18 Select Fire\\y\\R400\n"
 "\\w3. Desert Eagle .50AE\\y\\R650\n"
 };
 char *BuyPistol_2 =
 {
 "\\w4. SIG P228\\y\\R600\n"
 "\\w5. Dual Beretta 96G Elite\\y\\R1000\n"
 "\\w6. FN Five-Seven\\y\\R750\n\n"
 "\\w0. Exit"
 };
 
 char *BuyShotgun =
 {
 "\\yBuy Shotgun\\R$   Cost\n"
 "(Primary weapon)\n\n"
 "\\w1. Benelli M3 Super90\\y\\R1700\n"
 "\\w2. Benelli XM1014\\y\\R3000\n\n"
 "\\w0. Exit"
 };
 
 char *BuyRifle =
 {
 "\\yBuy Assault Rifle (Primary weapon)\\R$   Cost\n\n"
 "\\w1. AK-47\\y\\R2500\n"
 "\\w2. Sig SG-552 Commando\\y\\R3500\n"
 "\\w3. Colt M4A1 Carbine\\y\\R3100\n"
 "\\w4. Steyr Aug\\y\\R3500\n"
 };
 char *BuyRifle_T =
 "\\w9. IDF Defender\\y\\R2250\n\n";
 char *BuyRifle_CT =
 "\\w9. Clarion 5.56\\y\\R2000\n\n";
 char *BuyRifle_2 =
 {
 "\\yBuy Sniper Rifle (Primary weapon)\n\n"
 "\\w5. Steyr Scout\\y\\R2750\n"
 };
 char *BuyRifle_3 =
 {
 "\\w6. AI Arctic Warfare/Magnum\\y\\R4750\n"
 "\\w7. H&K G3/SG-1 Sniper Rifle\\y\\R5000\n"
 "\\w8. Sig SG-550 Sniper\\y\\R4200\n\n"
 "\\w0. Exit"
 };
 
 char *BuySubMachineGun =
 {
 "\\yBuy Sub-Machine Gun\\R$   Cost\n"
 "(Primary weapon)\n\n"
 "\\w1. H&K MP5-Navy\\y\\R1500\n"
 "\\w2. Steyr Tactical Machine Pistol\\y\\R1250\n"
 "\\w3. FN P90\\y\\R2350\n"
 };
 char *BuySubMachineGun_2 =
 {
 "\\w4. Ingram MAC-10\\y\\R1400\n"
 "\\w5. H&K UMP45\\y\\R1700\n\n"
 "\\w0. Exit"
 };
 
 char *BuyMachineGun =
 {
 "\\yBuy Machine Gun\\R$   Cost\n"
 "(Primary weapon)\n\n"
 "\\w1. FN M249 Para\\y\\R5750\n\n"
 "\\w0. Exit"
 };
 
 META_FUNCTIONS gMetaFunctionTable = {
 	NULL,
 	NULL,
 	GetEntityAPI2,
 	NULL,
 	NULL,
 	NULL,
 	GetEngineFunctions,
 	NULL,
 };
 
 plugin_info_t Plugin_info = {
 	META_INTERFACE_VERSION,
 	"oldbuy",
 	"1.0",
 	__DATE__,
 	"Wei Mingzhi",
 	"weimz2001@yahoo.co.kr",
 	"OLDBUY",
 	PT_ANYTIME,
 	PT_ANYPAUSE,
 };
 
 C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
 {
    gpMetaUtilFuncs = pMetaUtilFuncs;
    *pPlugInfo = &Plugin_info;
    return TRUE;
 }
 
 C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
 {
    gpMetaGlobals = pMGlobals;
    memcpy (pFunctionTable, &gMetaFunctionTable, sizeof (META_FUNCTIONS));
    gpGamedllFuncs = pGamedllFuncs;
    return TRUE;
 }
 
 C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
 {
    return TRUE;
 }
 
 void FakeClientCommand(edict_t *pBot, char *arg1, char *arg2, char *arg3)
 {
    int length, i;
 
    i = 0;
    while (i < 256)
    {
 	  g_argv[i] = NULL;
 	  i++;
    }
 
    if ((arg1 == NULL) || (*arg1 == 0))
 	  return;
 
    if ((arg2 == NULL) || (*arg2 == 0))
    {
 	  length = sprintf (&g_argv[0], "%s", arg1);
 	  fake_arg_count = 1;
    }
    else if ((arg3 == NULL) || (*arg3 == 0))
    {
 	  length = sprintf (&g_argv[0], "%s %s", arg1, arg2);
 	  fake_arg_count = 2;
    }
    else
    {
 	  length = sprintf (&g_argv[0], "%s %s %s", arg1, arg2, arg3);
 	  fake_arg_count = 3;
    }
 
    strcpy (&g_argv[64], arg1);
 
    if (arg2)
 	  strcpy (&g_argv[128], arg2);
 
    if (arg3)
 	  strcpy (&g_argv[192], arg3);
 
    g_argv[length] = NULL;  // null terminate just in case
 
    isFakeClientCommand = TRUE;
    MDLL_ClientCommand(pBot); // allow the MOD DLL to execute the ClientCommand...
    isFakeClientCommand = FALSE;
 }
 
 void ShowMenu(edict_t *pEdict, int slots, int displaytime, bool needmore, char *pText)
 {
    if (GET_USER_MSG_ID(PLID, "ShowMenu", NULL) == 0)
 	  REG_USER_MSG ("ShowMenu", -1);
 
    MESSAGE_BEGIN (MSG_ONE, GET_USER_MSG_ID (PLID, "ShowMenu", NULL), NULL, pEdict);
    WRITE_SHORT(slots);
    WRITE_CHAR(displaytime);
    WRITE_BYTE(needmore);
    WRITE_STRING(pText);
    MESSAGE_END();
 }
 
 const char *pfnCmd_Args(void)
 {
    if (isFakeClientCommand)
 	  RETURN_META_VALUE(MRES_SUPERCEDE, &g_argv[0]);
 
    RETURN_META_VALUE(MRES_IGNORED, NULL);
 }
 
 
 const char *pfnCmd_Argv(int argc)
 {
    if (isFakeClientCommand)
    {
 	  if (argc == 0)
 		 RETURN_META_VALUE(MRES_SUPERCEDE, &g_argv[64]);
 	  else if (argc == 1)
 		 RETURN_META_VALUE(MRES_SUPERCEDE, &g_argv[128]);
 	  else if (argc == 2)
 		 RETURN_META_VALUE(MRES_SUPERCEDE, &g_argv[192]);
 	  else
 		 RETURN_META_VALUE(MRES_SUPERCEDE, "???");
    }
 
    RETURN_META_VALUE(MRES_IGNORED, NULL);
 }
 
 int pfnCmd_Argc(void)
 {
    if (isFakeClientCommand)
 	  RETURN_META_VALUE(MRES_SUPERCEDE, fake_arg_count);
 
    RETURN_META_VALUE(MRES_IGNORED, 0);
 }
 
 C_DLLEXPORT int GetEngineFunctions (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion)
 {
    meta_engfuncs.pfnCmd_Args = pfnCmd_Args;
    meta_engfuncs.pfnCmd_Argv = pfnCmd_Argv;
    meta_engfuncs.pfnCmd_Argc = pfnCmd_Argc;
    memcpy (pengfuncsFromEngine, &meta_engfuncs, sizeof (enginefuncs_t));
    return (TRUE);
 }
 
 int GetTeam(edict_t *pEntity)
 {
    char *infobuffer;
    char model_name[32];
 
    infobuffer = (*g_engfuncs.pfnGetInfoKeyBuffer) (pEntity);
    strcpy (model_name, (g_engfuncs.pfnInfoKeyValue (infobuffer, "model")));
 
    if ((strcmp(model_name, "terror") == 0)
 	   || (strcmp(model_name, "leet") == 0)
 	   || (strcmp(model_name, "arctic") == 0)
 	   || (strcmp(model_name, "guerilla") == 0))
 	  return 0;
    return 1;
 }
 
 void ClientCommand(edict_t *pEntity)
 {
    if (pEntity->v.deadflag != DEAD_NO || pEntity->v.health <= 0)
 	  RETURN_META(MRES_IGNORED);
 
    if (pEntity->v.flags & (FL_FAKECLIENT | (1<<27) | (1<<28)))
 	  RETURN_META(MRES_IGNORED);
 
    const char *pcmd = CMD_ARGV(0);
    const char *arg1 = CMD_ARGV(1);
 
    if (FStrEq(pcmd, "buy"))
    {
 	  g_CurMenuState = Menu_Buy;
 	  ShowMenu(pEntity, 0x7ff, -1, 0, Buy); 
 	  RETURN_META(MRES_SUPERCEDE);
    }
    else if (FStrEq(pcmd, "buyequip"))
    {
 	  g_CurMenuState = Menu_BuyItem;
 	  ShowMenu(pEntity, 0x7ff, -1, 1, BuyItem);
 	  ShowMenu(pEntity, 0x7ff, -1, 0, BuyItem_2);
 	  RETURN_META(MRES_SUPERCEDE);
    }
    else if (FStrEq(pcmd, "menuselect"))
    {
 	  int iMenuSelect = atoi(arg1);
 
 	  if (g_CurMenuState == Menu_Buy)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			g_CurMenuState = Menu_BuyPistol;
 			ShowMenu(pEntity, 0x7ff, -1, 1, BuyPistol);
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuyPistol_2);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 2:
 			g_CurMenuState = Menu_BuyShotgun;
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuyShotgun);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 3:
 			g_CurMenuState = Menu_BuySubMachineGun;
 			ShowMenu(pEntity, 0x7ff, -1, 1, BuySubMachineGun);
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuySubMachineGun_2);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 4:
 			g_CurMenuState = Menu_BuyRifle;
 			ShowMenu(pEntity, 0x7ff, -1, 1, BuyRifle);
 			if (GetTeam(pEntity) == 0)
 			   ShowMenu(pEntity, 0x7ff, -1, 1, BuyRifle_T);
 			else
 			   ShowMenu(pEntity, 0x7ff, -1, 1, BuyRifle_CT);
 			ShowMenu(pEntity, 0x7ff, -1, 1, BuyRifle_2);
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuyRifle_3);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 5:
 			g_CurMenuState = Menu_BuyMachineGun;
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuyMachineGun);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 6:
 			g_CurMenuState = Menu_None;
 			FakeClientCommand(pEntity, "primammo", NULL, NULL);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 7:
 			g_CurMenuState = Menu_None;
 			FakeClientCommand(pEntity, "secammo", NULL, NULL);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 case 8:
 			g_CurMenuState = Menu_BuyItem;
 			ShowMenu(pEntity, 0x7ff, -1, 1, BuyItem);
 			ShowMenu(pEntity, 0x7ff, -1, 0, BuyItem_2);
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 default:
 			g_CurMenuState = Menu_None;
 			RETURN_META(MRES_SUPERCEDE);
 			break;
 		 }
 	  }
 	  else if (g_CurMenuState == Menu_BuyPistol)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "usp", NULL, NULL);
 			break;
 		 case 2:
 			FakeClientCommand(pEntity, "glock", NULL, NULL);
 			break;
 		 case 3:
 			FakeClientCommand(pEntity, "deagle", NULL, NULL);
 			break;
 		 case 4:
 			FakeClientCommand(pEntity, "p228", NULL, NULL);
 			break;
 		 case 5:
 			FakeClientCommand(pEntity, "elites", NULL, NULL);
 			break;
 		 case 6:
 			FakeClientCommand(pEntity, "fiveseven", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
 	  else if (g_CurMenuState == Menu_BuyRifle)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "ak47", NULL, NULL);
 			break;
 		 case 2:
 			FakeClientCommand(pEntity, "sg552", NULL, NULL);
 			break;
 		 case 3:
 			FakeClientCommand(pEntity, "m4a1", NULL, NULL);
 			break;
 		 case 4:
 			FakeClientCommand(pEntity, "aug", NULL, NULL);
 			break;
 		 case 5:
 			FakeClientCommand(pEntity, "scout", NULL, NULL);
 			break;
 		 case 6:
 			FakeClientCommand(pEntity, "awp", NULL, NULL);
 			break;
 		 case 7:
 			FakeClientCommand(pEntity, "g3sg1", NULL, NULL);
 			break;
 		 case 8:
 			FakeClientCommand(pEntity, "sg550", NULL, NULL);
 			break;
 		 case 9:
 			if (GetTeam(pEntity))
 			   FakeClientCommand(pEntity, "famas", NULL, NULL);
 			else
 			   FakeClientCommand(pEntity, "galil", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
 	  else if (g_CurMenuState == Menu_BuyMachineGun)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "m249", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
 	  else if (g_CurMenuState == Menu_BuyShotgun)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "m3", NULL, NULL);
 			break;
 		 case 2:
 			FakeClientCommand(pEntity, "xm1014", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
 	  else if (g_CurMenuState == Menu_BuySubMachineGun)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "mp5", NULL, NULL);
 			break;
 		 case 2:
 			FakeClientCommand(pEntity, "tmp", NULL, NULL);
 			break;
 		 case 3:
 			FakeClientCommand(pEntity, "p90", NULL, NULL);
 			break;
 		 case 4:
 			FakeClientCommand(pEntity, "mac10", NULL, NULL);
 			break;
 		 case 5:
 			FakeClientCommand(pEntity, "ump45", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
 	  else if (g_CurMenuState == Menu_BuyItem)
 	  {
 		 switch(iMenuSelect)
 		 {
 		 case 1:
 			FakeClientCommand(pEntity, "vest", NULL, NULL);
 			break;
 		 case 2:
 			FakeClientCommand(pEntity, "vesthelm", NULL, NULL);
 			break;
 		 case 3:
 			FakeClientCommand(pEntity, "flash", NULL, NULL);
 			break;
 		 case 4:
 			FakeClientCommand(pEntity, "hegren", NULL, NULL);
 			break;
 		 case 5:
 			FakeClientCommand(pEntity, "sgren", NULL, NULL);
 			break;
 		 case 6:
 			FakeClientCommand(pEntity, "defuser", NULL, NULL);
 			break;
 		 case 7:
 			FakeClientCommand(pEntity, "nvgs", NULL, NULL);
 			break;
 		 case 8:
 			FakeClientCommand(pEntity, "shield", NULL, NULL);
 			break;
 		 }
 		 g_CurMenuState = Menu_None;
 		 RETURN_META(MRES_SUPERCEDE);
 	  }
    }
    else if (FStrEq(pcmd, "radio1") ||
 			FStrEq(pcmd, "radio2") ||
 			FStrEq(pcmd, "radio3") ||
 			FStrEq(pcmd, "chooseteam"))
    {
 	  g_CurMenuState = Menu_None;
 	  ShowMenu(pEntity, 0, -1, 0, "");
    }
 
    RETURN_META(MRES_IGNORED);
 }
 
 C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
 {
    gFunctionTable.pfnClientCommand = ClientCommand;
    memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
    return TRUE;
 }
 
 #ifndef __linux__
 void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
 #else
 extern "C" EXPORT void GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
 #endif
 {
    memcpy (&g_engfuncs, pengfuncsFromEngine, sizeof (enginefuncs_t));
    gpGlobals = pGlobals;
 }
Note: the compiled version can be found at my homepage: http://groups.msn.com/weimingzhi

Last edited by Whistler; 13-02-2004 at 11:21..
  
Reply With Quote
Re: Turn the CS 1.6 twisted buy menu to old one
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: Turn the CS 1.6 twisted buy menu to old one - 13-02-2004

Neat stuff, Wei !!!



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: Turn the CS 1.6 twisted buy menu to old one
Old
  (#3)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: Turn the CS 1.6 twisted buy menu to old one - 22-02-2004

One thing can be simplified:

use g_engfuncs.pfnClientCommand instead of botman's stuff
  
Reply With Quote
Re: Turn the CS 1.6 twisted buy menu to old one
Old
  (#4)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: Turn the CS 1.6 twisted buy menu to old one - 06-03-2004

omg, there's a big fat bug out there !
I should keep a list for each client instead using only one global variable
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com