AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Bots using menu (https://forums.alliedmods.net/showthread.php?t=25868)

hellDzr 03-22-2006 09:09

Bots using menu
 
Hello, what would be the easiest way to make bots select random number from a menu? Eg. if there's map vote, the bots would choose 1 or 2 randomly.

Brad 03-22-2006 09:44

Code:
option = random_num(1, 2);

hellDzr 03-22-2006 10:18

Thank you Brad, but im new and not sure how to add that in the script.

Something like this maybe?
Code:
    if ( is_user_bot(id) ) {     option = random_num(1, 2);     }

I tried to compile one script with this included and it said 'error 017: undefined symbol "option"'

I would really appreciate it if someone could show me working example (In the game I'd start a vote and bots would vote randomly 1-2 or 1-9).

I hope it's not too complicated.

[ --<-@ ] Black Rose 03-22-2006 13:18

you would need to show hole script if you don't know how to do it yourself.

akysiev 03-22-2006 13:47

You'll have to change this within the source code of the script itself. First off, a bot won't ever receive a menu to choose from, and thus won't call the function that handles a menu choice. That means that you'll have to change the part of code that dispatches the menu to all the players. When it loops through all the players, you'll need to emulate a vote choice by directly calling the handling function.

Code:
public plugin_init() {     new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2     register_menucmd(register_menuid("Which useless choice"), keys, "handleMenu"); } // Fake menu maker public dispatchMenus() {     new iPlayers[32];     new iNumPlayers;     get_players(iPlayers, iNumPlayers);     for(new i = 0; i < iNumPlayers; i++)     {         // if its a bot, go straight to menu choice         // otherwise, show the menu         if (is_user_bot(iPlayers[i]))         {             handleMenu(iPlayers[i], random_num(0,2));         }         else         {             //menu crap             new menu[192];             format(menu, 191, "Which useless choice do you want?^n^n1. 1^n^n2. 2^n^n3. 3");             show_menu(id, keys, menu);         }     } } // takes care of menu choice public handleMenu(id, key) {     switch(key)     {         // all that other stuff     } }

Kinda like that. Just don't try to copy paste that cause it doesn't do jack.

hellDzr 03-22-2006 14:11

Thanks for your replies. My main idea is to make bots select random heros in superheromod. When a player level goes up, it shows a menu at start of the round. I know bots doesn't see the menu because of this:
Code:
//Don't show menu to bots if ( is_user_bot(id) ) return PLUGIN_HANDLED

Here should be the full menu script:
Code:
public menuSuperPowers(id, menuOffset) {     // Don't show menu if mod off or they're not connected     if ( !shModActive() || !is_user_connected(id) || gReadXPNextRound[id] ) return PLUGIN_HANDLED     //Don't show menu to bots     if ( is_user_bot(id) ) return PLUGIN_HANDLED     inMenu[id] = false     gPlayerMenuOffset[id] = 0     // show menu super power     new message[1801]     new temp[128]     new keys = 0     new heroIndex, heroLevel, playerpowercount     // check for cheat death     if ( !passCheatDeathCheck(id) ) {         client_print(id, print_center, "Get C/D From www.unitedadmins.com")         return PLUGIN_HANDLED // Just don't show the gui menu     }     if ( isPowerBanned[id] ) {         client_print(id, print_center, "You are not allowed to have powers")         return PLUGIN_HANDLED // Just don't show the gui menu     }     // Don't show menu if they already have enough powers     playerpowercount = getPowerCount(id)     if ( playerpowercount >= gPlayerLevel[id] || playerpowercount >= gMaxPowers ) return PLUGIN_HANDLED     // Figure out how many powers a person should be able to have     // Example: At level 10 a person can pick a max of 1 lvl 10 hero     //      and a max of 2 lvl 9 heroes, and a max of 3 lvl 8 heors, etc...     new LvlLimit = get_cvar_num("sh_lvllimit")     if (LvlLimit == 0) LvlLimit = SH_MAXLEVELS     for ( new x = 0; x <= gNumLevels; x++) {         if ( gPlayerLevel[id] >= x ) {             maxPowersLeft[id][x] = gPlayerLevel[id] - x + LvlLimit         }         else maxPowersLeft[id][x] = 0     }     // Now decrement the level powers that they've picked     for ( new x = 1; x <= getPowerCount(id) && x <= SH_MAXLEVELS; x++ ) {         heroIndex = gPlayerPowers[id][x]         if ( heroIndex < 0 || heroIndex > gSuperHeroCount) continue         heroLevel = getHeroLevel(heroIndex)         // Decrement all maxPowersLeft by 1 for the level hero they have and below         for ( new y = heroLevel; y >= 0; y-- ) {             if (--maxPowersLeft[id][y] < 0) maxPowersLeft[id][y] = 0             //If none left on this level, there should be none left on any higher levels             if (maxPowersLeft[id][y] <= 0 && y < SH_MAXLEVELS) {                 if (maxPowersLeft[id][y+1] != 0) {                     for ( new z = y; z <= gNumLevels; z++ ) {                         maxPowersLeft[id][z] = 0                     }                 }             }         }     }     // OK BUILD A LIST OF HEROES THIS PERSON CAN PICK FROM     gPlayerMenuChoices[id][0] = 0  // <- 0 choices so far     new count = 0, enabled = 0     new MaxBinds = min(get_cvar_num("sh_maxbinds"), SH_MAXBINDPOWERS)     new menuMode = get_cvar_num("sh_menumode")     new bool:thisEnabled     for ( new x = 0; x < gSuperHeroCount; x++ )  {         heroIndex = x         heroLevel = getHeroLevel(heroIndex)         thisEnabled = false         if ( gPlayerLevel[id] >= heroLevel ) {             if (maxPowersLeft[id][heroLevel] > 0 && !(gPlayerBinds[id][0] >= MaxBinds && gSuperHeros[heroIndex][requiresKeys])) {                 thisEnabled = true             }             // Don't want to present this power if the player already has it!             if ( !playerHasPower(id, heroIndex) && (thisEnabled || menuMode > 0)) {                 count++                 gPlayerMenuChoices[id][0] = count                 gPlayerMenuChoices[id][count] = heroIndex                 if (thisEnabled) enabled++             }         }     }     //menuOffset Stuff     if (menuOffset <= 0 || menuOffset > gPlayerMenuChoices[id][0]) menuOffset = 1     gPlayerMenuOffset[id] = menuOffset     new total = min ( gMaxPowers, gPlayerLevel[id] )     format(message,180, "\ySelect Super Power:%-16s\r(You've Selected %d/%d)^n^n", " ", playerpowercount, total )     // OK Display the Menu     for ( new x = menuOffset; x < menuOffset + 8; x++ ) {         // Only allow a selection from powers the player doesn't have         if (x > gPlayerMenuChoices[id][0]) {             add(message, 1800, "^n")             continue         }         heroIndex = gPlayerMenuChoices[id][x]         heroLevel = getHeroLevel(heroIndex)         if (maxPowersLeft[id][heroLevel] <= 0 || (gPlayerBinds[id][0] >= MaxBinds && gSuperHeros[heroIndex][requiresKeys])) {             add(message,1800,"\d")         }         else {             add(message,1800,"\w")         }         keys |= (1<<x-menuOffset) // enable this option         format(temp, 127, "%s (%d%s)",gSuperHeros[heroIndex][hero],heroLevel,gSuperHeros[heroIndex][requiresKeys] ? "b" : "")         format(temp, 127, "%d. %-20s- %s^n", x - menuOffset + 1, temp, gSuperHeros[heroIndex][superpower] )         add(message, 1800, temp)     }     if ( gPlayerMenuChoices[id][0] > 8 ) {         // Can only Display 8 heroes at a time         add(message, 1800, "\w^n9. More Heroes")         keys |= (1<<8)     }     else {         add(message, 1800, "^n")     }     // Cancel     add(message, 1800, "\w^n0. Cancel")     keys |= (1<<9)     if ((count > 0 && enabled > 0) || inMenu[id]) {         format(debugt, 127, "Displaying Menu - offset: %d - count: %d - enabled: %d", menuOffset, count, enabled)         debugMessage(debugt, id, 8)         inMenu[id] = true         show_menu(id, keys, message)     }     return PLUGIN_HANDLED }

And I really appreciate the script akysiev, I just need some time to fully understand it :)

akysiev 03-22-2006 14:39

Find the register_menu line in plugin_init that has "Select Super Power:" or something like that and post that plus the function it references to.

hellDzr 03-22-2006 14:50

This one?
Code:
    // Menus     gMenuID = register_menuid("Select Super Power")     new keys = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)     register_menucmd(gMenuID,keys,"selectedSuperPower")

And this?

Code:
public selectedSuperPower(id, key) {     if (!inMenu[id] || !shModActive()) return PLUGIN_HANDLED     inMenu[id] = false     if ( !passCheatDeathCheck(id) ) {         client_print(id, print_center, "Get C/D From www.unitedadmins.com")         return PLUGIN_HANDLED     }     if ( isPowerBanned[id] ) {         client_print(id, print_center, "You are not allowed to have powers")         return PLUGIN_HANDLED     }     // Next and Previous Super Hero Menus     if ( key == 8 ) {         menuSuperPowers(id, gPlayerMenuOffset[id] + 8)         return PLUGIN_HANDLED     }     // Cancel     if ( key == 9 ) {         gPlayerMenuOffset[id] = 0         return PLUGIN_HANDLED     }     // Hero was Picked!     new powerCount = getPowerCount(id)     if ( powerCount >= gNumLevels || powerCount >= gMaxPowers ) return PLUGIN_HANDLED     new heroIndex = gPlayerMenuChoices[id][key + gPlayerMenuOffset[id]]     // Just a crash check     if ( heroIndex < 0 || heroIndex > gSuperHeroCount ) return PLUGIN_HANDLED     new heroLevel = getHeroLevel(heroIndex)     new MaxBinds = get_cvar_num("sh_maxbinds")     if ((gPlayerBinds[id][0] >= MaxBinds && gSuperHeros[heroIndex][requiresKeys])) {         client_print(id, print_chat, "[SH] You cannot choose more than %d heroes that require binds",MaxBinds)         menuSuperPowers(id, gPlayerMenuOffset[id])         return PLUGIN_HANDLED     }     else if ( maxPowersLeft[id][heroLevel] <= 0 ) {         client_print(id, print_chat, "[SH] You cannot pick any more heroes from that level")         menuSuperPowers(id, gPlayerMenuOffset[id])         return PLUGIN_HANDLED     }     new message[256]     if ( !gSuperHeros[heroIndex][requiresKeys] ) {         format(message,256,"AUTOMATIC POWER: %s^n%s", gSuperHeros[heroIndex][superpower], gSuperHeros[heroIndex][help])     }     else {         format(message,256,"BIND KEY TO ^"+POWER%d^": %s^n%s", gPlayerBinds[id][0]+1, gSuperHeros[heroIndex][superpower], gSuperHeros[heroIndex][help])     }     // Show the Hero Picked     set_hudmessage(100,100,0,-1.0,0.2,0,1.0,5.0,0.1,0.2,84)     show_hudmessage( id, message)     // Bind Keys / Set Powers     gPlayerPowers[id][0] = powerCount + 1     gPlayerPowers[id][powerCount + 1] = heroIndex     //Init This Hero!     initHero(id, heroIndex)     displayPowers(id, true)     // Show the Menu Again if they don't have enough skills yet!     menuSuperPowers(id, gPlayerMenuOffset[id])     return PLUGIN_HANDLED }

Thanks for the support :)

akysiev 03-22-2006 14:59

Try this. I just deleted the bot block and added an extra conditional before it displays the menu.

Code:
public menuSuperPowers(id, menuOffset) {     // Don't show menu if mod off or they're not connected     if ( !shModActive() || !is_user_connected(id) || gReadXPNextRound[id] ) return PLUGIN_HANDLED     inMenu[id] = false     gPlayerMenuOffset[id] = 0     // show menu super power     new message[1801]     new temp[128]     new keys = 0     new heroIndex, heroLevel, playerpowercount     // check for cheat death     if ( !passCheatDeathCheck(id) ) {         client_print(id, print_center, "Get C/D From www.unitedadmins.com")         return PLUGIN_HANDLED // Just don't show the gui menu     }     if ( isPowerBanned[id] ) {         client_print(id, print_center, "You are not allowed to have powers")         return PLUGIN_HANDLED // Just don't show the gui menu     }     // Don't show menu if they already have enough powers     playerpowercount = getPowerCount(id)     if ( playerpowercount >= gPlayerLevel[id] || playerpowercount >= gMaxPowers ) return PLUGIN_HANDLED     // Figure out how many powers a person should be able to have     // Example: At level 10 a person can pick a max of 1 lvl 10 hero     //        and a max of 2 lvl 9 heroes, and a max of 3 lvl 8 heors, etc...     new LvlLimit = get_cvar_num("sh_lvllimit")     if (LvlLimit == 0) LvlLimit = SH_MAXLEVELS     for ( new x = 0; x <= gNumLevels; x++) {         if ( gPlayerLevel[id] >= x ) {             maxPowersLeft[id][x] = gPlayerLevel[id] - x + LvlLimit         }         else maxPowersLeft[id][x] = 0     }     // Now decrement the level powers that they've picked     for ( new x = 1; x <= getPowerCount(id) && x <= SH_MAXLEVELS; x++ ) {         heroIndex = gPlayerPowers[id][x]         if ( heroIndex < 0 || heroIndex > gSuperHeroCount) continue         heroLevel = getHeroLevel(heroIndex)         // Decrement all maxPowersLeft by 1 for the level hero they have and below         for ( new y = heroLevel; y >= 0; y-- ) {             if (--maxPowersLeft[id][y] < 0) maxPowersLeft[id][y] = 0             //If none left on this level, there should be none left on any higher levels             if (maxPowersLeft[id][y] <= 0 && y < SH_MAXLEVELS) {                 if (maxPowersLeft[id][y+1] != 0) {                     for ( new z = y; z <= gNumLevels; z++ ) {                         maxPowersLeft[id][z] = 0                     }                 }             }         }     }     // OK BUILD A LIST OF HEROES THIS PERSON CAN PICK FROM     gPlayerMenuChoices[id][0] = 0  // <- 0 choices so far     new count = 0, enabled = 0     new MaxBinds = min(get_cvar_num("sh_maxbinds"), SH_MAXBINDPOWERS)     new menuMode = get_cvar_num("sh_menumode")     new bool:thisEnabled     for ( new x = 0; x < gSuperHeroCount; x++ )  {         heroIndex = x         heroLevel = getHeroLevel(heroIndex)         thisEnabled = false         if ( gPlayerLevel[id] >= heroLevel ) {             if (maxPowersLeft[id][heroLevel] > 0 && !(gPlayerBinds[id][0] >= MaxBinds && gSuperHeros[heroIndex][requiresKeys])) {                 thisEnabled = true             }             // Don't want to present this power if the player already has it!             if ( !playerHasPower(id, heroIndex) && (thisEnabled || menuMode > 0)) {                 count++                 gPlayerMenuChoices[id][0] = count                 gPlayerMenuChoices[id][count] = heroIndex                 if (thisEnabled) enabled++             }         }     }     //menuOffset Stuff     if (menuOffset <= 0 || menuOffset > gPlayerMenuChoices[id][0]) menuOffset = 1     gPlayerMenuOffset[id] = menuOffset     new total = min ( gMaxPowers, gPlayerLevel[id] )     format(message,180, "\ySelect Super Power:%-16s\r(You've Selected %d/%d)^n^n", " ", playerpowercount, total )     // OK Display the Menu     for ( new x = menuOffset; x < menuOffset + 8; x++ ) {         // Only allow a selection from powers the player doesn't have         if (x > gPlayerMenuChoices[id][0]) {             add(message, 1800, "^n")             continue         }         heroIndex = gPlayerMenuChoices[id][x]         heroLevel = getHeroLevel(heroIndex)         if (maxPowersLeft[id][heroLevel] <= 0 || (gPlayerBinds[id][0] >= MaxBinds && gSuperHeros[heroIndex][requiresKeys])) {             add(message,1800,"\d")         }         else {             add(message,1800,"\w")         }         keys |= (1<<x-menuOffset) // enable this option         format(temp, 127, "%s (%d%s)",gSuperHeros[heroIndex][hero],heroLevel,gSuperHeros[heroIndex][requiresKeys] ? "b" : "")         format(temp, 127, "%d. %-20s- %s^n", x - menuOffset + 1, temp, gSuperHeros[heroIndex][superpower] )         add(message, 1800, temp)     }     if ( gPlayerMenuChoices[id][0] > 8 ) {         // Can only Display 8 heroes at a time         add(message, 1800, "\w^n9. More Heroes")         keys |= (1<<8)     }     else {         add(message, 1800, "^n")     }     // Cancel     add(message, 1800, "\w^n0. Cancel")     keys |= (1<<9)     if ((count > 0 && enabled > 0) || inMenu[id]) {         if (is_user_bot(id)) {             selectedSuperPower(id, random_num(0, 8));         }         else {             format(debugt, 127, "Displaying Menu - offset: %d - count: %d - enabled: %d", menuOffset, count, enabled)             debugMessage(debugt, id, 8)             inMenu[id] = true             show_menu(id, keys, message)         }     }     return PLUGIN_HANDLED }

Actually, I made a slight oversight. There's the case where the menu is shorter than 8 elements so it might not select anything. In that case, it may cause a runtime error. I'd like to fix it but I can't at the moment. Will see if I can do so later so remind me if I forget.

hellDzr 03-22-2006 15:53

Thank you, but I tried it and the bot didn't select anything, he had level 1 and start of the round. Should I test it again?

Oh and there's always more than 8 heros in the list you can pick from.


All times are GMT -4. The time now is 16:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.