AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu Items not working (I have no idea why) (https://forums.alliedmods.net/showthread.php?t=20160)

Des12 11-02-2005 19:59

Menu Items not working (I have no idea why)
 
Hello, I am making a plugin for amxx v1.01, so I can't include any fancy 1.60 stuff in here just to let you know.

Anyways, I am modifiying a plugin for The Specialsits, it is the Gunshop plugin origionally devolped by Harbu. I have been grappling with it for about 2 weeks on and off now.



When I go to the coordinates, it does display the green text (you are near the admin gunshop)

And when I type amx_gunz, it displays the main menu, but after I press a key it completely dissapears.
Code:

/* This code is from Harbu, some from Remo Williams, modified by Dest Romano, Cleanup by Charr*/
#include <amxmodx>
#include <amxmisc>
#include <dbi>
#include <tsx>
#include <engine>
#include <engine_stocks>
#include <fun>
#include <tsxaddon>
// Don't know if all these are needed

//new gunshop[3] = {-655, 651, -395} //mecklenburg b8v6
new gunshop[3] = {-3216, 674, 282}  // simivalley final
new addons[33][5]      // Stores information of currently selected
new chosenweapon[33][3]
new Sql:dbc
new Result:result
new g_itemholder[33][10][3]


public plugin_init() {
  register_plugin("Admin Guns","1.2","Dest Romano")
 
  register_menucmd(register_menuid("Admin Gunshop Main Menu"),1023,"Admin_Gunshop_Main_Action")
  register_menucmd(register_menuid("Admin Gunshop - "),1023,"Admin_Gunshop_Weapon_Action")
  register_menucmd(register_menuid("Admin Weapon Addons - "),1023,"Admin_Addons_Action")
 
  //register_clcmd("say /buy","buystuff")
 
  register_clcmd("amx_gunz","buystuff")
  set_task(1.0,"sql_init")
  set_task(1.0,"nearmessage",0,"",0,"b")
}

/*
---------------------------------------------------------------------------------
 I was told

"No need to open another connection to the same MySQL DB       
Leave this commented unless this is the only plugin using the economy MySQL,  and if its the only one, add cvars for your conection vars."

But seems it is nesscery...
       
---------------------------------------------------------------------------------
*/
// Initializing the MySQL database (Originally Developed by: Harbu)
public sql_init() {
  new host[32], username[32], password[32], dbname[32], error[32]
  get_cvar_string("economy_mysql_host",host,32)
  get_cvar_string("economy_mysql_user",username,32)
  get_cvar_string("economy_mysql_pass",password,32)
  get_cvar_string("economy_mysql_db",dbname,32)
  dbc = dbi_connect(host,username,password,dbname,error,32)
  if (dbc == SQL_FAILED)
      server_print("[Adminguns] Could NOT Connect To SQL Database^n")
  else
      server_print("[Adminguns] Connected To SQL, Have A Nice Day!^n")
}


// Select string (Originally Developed by: Harbu)
public select_string(id,table[],index[],condition[],equals[],output[]) {
  new query[256]
  format(query,255,"SELECT %s FROM %s WHERE %s='%s'",index,table,condition,equals)
  result = dbi_query(dbc,query)
  if(dbi_nextrow(result) > 0)
      dbi_field(result,1,output,64)
 
  dbi_free_result(result)
}

// Explode  (Originally Developed by: BAILOPAN )
stock explode( output[][], input[], delimiter, textlen, maxMatches ) {
        new nIdx = 0
        new nLen = (1 + copyc( output[nIdx], textlen, input, delimiter ))
        new len = strlen(input)

        while( nLen < len && nIdx < maxMatches )
          nLen += (1 + copyc( output[++nIdx], textlen, input[nLen], delimiter ))
}


// Find user from database, must be registerd a playername
public is_user_database(id) {
  if(dbc < SQL_OK)
      return 0
 
  new authid[32], query[256]
  get_user_authid(id,authid,31)
  format(query,255,"SELECT name FROM money WHERE steamid='%s'",authid)
  result = dbi_query(dbc,query)
  if(dbi_nextrow(result) > 0)
      {
      dbi_free_result(result)
      return 1
  }
  dbi_free_result(result)
  return 0
}

/*

====================================================================
--------------------------------------------------------------------
// Function for adding/subtracting money from your wallet and Bank balance
public edit_value(id,table[],index[],func[],amount)
{
  if(dbc < SQL_OK) return PLUGIN_HANDLED
      new authid[32], query[256]
  get_user_authid(id,authid,31)
  if(equali(func,"="))
      {
      format(query,255,"UPDATE %s SET %s=%i WHERE steamid='%s'",table,index,amount,authid)
  }
  else
      {
      format(query,255,"UPDATE %s SET %s=%s%s%i WHERE steamid='%s'",table,index,index,func,amount,authid)
  }
  dbi_query(dbc,query)
  return PLUGIN_HANDLED
}
--------------------------------------------------------------------
====================================================================
*/

public print_text(id)
client_print(id,print_chat,"[AMXX] Write amx_regname <name> <password> in console to register and use plugins!^n")

///////////////////////////////////////////
//      SQL Gunshop        //
/////////////////////////////////////////


public buystuff(id) {
  new name[18]
  get_user_name( id, name, sizeof( name ) )
  new origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) <= 50.0)
      Gunshop_Main(id)
 
  return PLUGIN_HANDLED
}

// Gunshop Main Menu
public Gunshop_Main(id) {
  if(is_user_database(id) == 0) {
      print_text(id)
      return PLUGIN_HANDLED
  }
 
  new menu[256], origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
 
  new key = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<9)
  new len = format(menu,sizeof(menu),"Gunshop Main Menu^n^n")
 
  len += format(menu[len],sizeof(menu)-len,"1. Pistols^n")
  len += format(menu[len],sizeof(menu)-len,"2. Sub-Machine Guns^n")
  len += format(menu[len],sizeof(menu)-len,"3. Shotguns^n")
  len += format(menu[len],sizeof(menu)-len,"4. Rifles^n")
  len += format(menu[len],sizeof(menu)-len,"5. Heavy Weapons^n")
  len += format(menu[len],sizeof(menu)-len,"6. Special Weapons^n^n")
 
  len += format(menu[len],sizeof(menu)-len,"7. Free Ammo Refill^n")
  len += format(menu[len],sizeof(menu)-len,"8. Licenses^n^n")
 
  len += format(menu[len],sizeof(menu)-len,"0. Close Menu^n")
  new name2[18]
  get_user_name( id, name2, sizeof( name2 ) )
  show_menu(id,key,menu)
  return PLUGIN_HANDLED
}

public Admin_Gunshop_Main_Action(id,key)
{
  new origin[3]
  get_user_origin(id,origin)
 
  /*if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED*/
 
  new name3[18]
  get_user_name( id, name3, sizeof( name3 ) )
 
  switch(key) {
      case 0: Gunshop_Weapon(id,"Pistol")
      case 1: Gunshop_Weapon(id,"Sub-Machinegun")
      case 2: Gunshop_Weapon(id,"Shotgun")
      case 3: Gunshop_Weapon(id,"Rifle")
      case 4: Gunshop_Weapon(id,"Heavy")
      case 5: Gunshop_Weapon(id,"Special")
      case 6: Gunshop_Ammo(id)
      case 7: Gunshop_License(id)
  }
 
  return PLUGIN_HANDLED
}

// A Specific Weapon Menu, Building and Showing
public Gunshop_Weapon(id,type[]) {
  new origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
 
  for(new i=0;i < 10;i++) {
      g_itemholder[id][i][0] = 0
      g_itemholder[id][i][1] = 0
      g_itemholder[id][i][2] = 0
  }
 
  new body[256], query[256]
  new key = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9)
  new len = format(body,sizeof(body),"Gunshop - %ss ^n^n",type)
  format(query,255,"SELECT weaponid,name,price,banned FROM gunshop WHERE type='%s'",type)
  result = dbi_query(dbc,query)
  if(dbi_nextrow(result) > 0)
      {
      new rows = dbi_num_rows(result)
      for(new i=0;i < rows;i++)
      {
        new name[33]
        g_itemholder[id][i][0] = dbi_field(result,1)
        dbi_field(result,2,name,sizeof(name))
        g_itemholder[id][i][1] = dbi_field(result,3)
        g_itemholder[id][i][2] = dbi_field(result,4)
        len += format(body[len],sizeof(body)-len,"%i. %s ($%i)^n",i+1,name,g_itemholder[id][i][1])
        dbi_nextrow(result)
      }
      dbi_free_result(result)
      add(body,sizeof(body),"^n0.Previous Menu")
      show_menu(id,key,body)
  }
  dbi_free_result(result)
  return PLUGIN_HANDLED
}

public Gunshop_License(id) {
  new origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
 
  client_print(id,print_chat,"[GunShop] Admins don't need licenses.^n")
  return PLUGIN_HANDLED
}


public Admin_Gunshop_Weapon_Action(id,key)
{
  new origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
   
  if(key > 8) {
      Gunshop_Main(id)
      return PLUGIN_HANDLED
  }
  Purchase_Weapon(id,g_itemholder[id][key][0],g_itemholder[id][key][1],g_itemholder[id][key][2],1)
  return PLUGIN_HANDLED
}

// The actual buying of a Weapon or showing the addons menu
public Purchase_Weapon(id,weaponid,price,banned,scene)
{
 
  new origin[3]
  get_user_origin(id,origin,0)
 
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
 
  chosenweapon[id][0] = weaponid
  chosenweapon[id][1] = price
  chosenweapon[id][2] = banned
 
  if(banned == 1)
      {
      client_print(id,print_chat,"[GunShop] The weapon is currently banned.^n")
      return PLUGIN_HANDLED
  }
  new query[256],bullets,silencer,laser,flash,scope
 
  format(query,255,"SELECT bullets,silencer,laser,flash,scope FROM gunshop WHERE weaponid=%i",weaponid)
  result = dbi_query(dbc,query)

  dbi_free_result(result)
 
  if(dbi_nextrow(result) > 0)
      {
      bullets = dbi_field(result,1)
      silencer = dbi_field(result,2)
      laser = dbi_field(result,3)
      flash = dbi_field(result,4)
      scope = dbi_field(result,5)
      dbi_free_result(result)
  }
  else
      {
      dbi_free_result(result)
      return PLUGIN_HANDLED
  }
  if(scene == 1)
      {
      if(silencer == 1 || laser == 1 || flash == 1 || scope == 1)
        {
        for(new i=0;i < 5;i++) addons[id][i] = 0
        new body[256], name[33]
        new key = (1<<0|1<<1|1<<2|1<<3|1<<9)
        xmod_get_wpnname(weaponid,name,sizeof(name))
        new len = format(body,sizeof(body),"Weapon Addons - %s ^n^n",name)
       
        if(silencer == 1) {
            len += format(body[len],sizeof(body)-len,"1. Silencer ($2)^n")
            addons[id][1] = 1
        }
        if(laser == 1) {
            len += format(body[len],sizeof(body)-len,"2. Laser ($2)^n")
            addons[id][2] = 2
        }
        if(flash == 1) {
            len += format(body[len],sizeof(body)-len,"3. Flashlight ($2)^n")
            addons[id][3] = 4
        }
        if(scope == 1) {   
            len += format(body[len],sizeof(body)-len,"4. Scope ($3)^n")
            addons[id][4] = 8
        }
        add(body,sizeof(body),"^n0. Finish^n")
        show_menu(id,key,body)
        return PLUGIN_HANDLED
      }
      else
        {
        new name[33]
        xmod_get_wpnname(weaponid,name,sizeof(name))
        ts_giveweapon(id,weaponid,bullets,0)
        client_print(id,print_chat,"[GunShop] Purchased %s^n",name)
        return PLUGIN_HANDLED
      }
  }
  if(scene == 2) {
      if(!addons[id][1] && !addons[id][2] && !addons[id][3] && !addons[id][4]) {
        Purchase_Weapon(id,chosenweapon[id][0],chosenweapon[id][1],chosenweapon[id][2],3)
        return PLUGIN_HANDLED
      }
      new body[256], name[32]
      new key = (1<<0|1<<1|1<<2|1<<3|1<<9)
      xmod_get_wpnname(weaponid,name,sizeof(name))
      new len = format(body,sizeof(body),"Weapon Addons - %s^n^n",name)
      if(addons[id][1]) {
        len += format(body[len],sizeof(body)-len,"1. Silencer ($2)^n")
      }
      if(addons[id][2]) {
        len += format(body[len],sizeof(body)-len,"2. Laser ($2)^n")
      }
      if(addons[id][3]) {
        len += format(body[len],sizeof(body)-len,"3. Flashlight ($2)^n")
      }
      if(addons[id][4]) {       
        len += format(body[len],sizeof(body)-len,"4. Scope ($3)^n")
      }
      add(body,sizeof(body),"^n0. Finish^n")
      show_menu(id,key,body)
      return PLUGIN_HANDLED
  }
  if(scene == 3) {
      new name[33]
      xmod_get_wpnname(weaponid,name,sizeof(name))
      ts_giveweapon(id,weaponid,bullets,addons[id][0])
      client_print(id,print_chat,"[GunShop] Purchased %s^n",name)
      return PLUGIN_HANDLED
  }
  client_print(id,print_chat,"[Gunshop] Enjoy your weapon!^n")
  if(random_num(1,3) == 3)
      client_print(id,print_chat,"Plugin by Dest Romano, based on Harbu's code.")
 
  return PLUGIN_HANDLED
 
}

// Addons Action
public Admin_Addons_Action(id,key) {
  new name4[18]
  get_user_name( id, name4, sizeof( name4 ) )
  new origin[3]
  get_user_origin(id,origin)
  if(get_distance(origin,gunshop) > 50.0)
      return PLUGIN_HANDLED
 
  if(key == 9) Purchase_Weapon(id,chosenweapon[id][0],chosenweapon[id][1],chosenweapon[id][2],3)
      else {
      if(addons[id][key+1] > 0) {
        if(key+1 == 4)
            chosenweapon[id][2] += 3
        else
            chosenweapon[id][2] +=2
       
        addons[id][0] += addons[id][key+1]
        addons[id][key+1] = 0
        Purchase_Weapon(id,chosenweapon[id][0],chosenweapon[id][1],chosenweapon[id][2],2)
      }
      else Purchase_Weapon(id,chosenweapon[id][0],chosenweapon[id][1],chosenweapon[id][2],2)
      }
  return PLUGIN_HANDLED
}

// Buying weapon ammunation
public Gunshop_Ammo(id) {
  new name5[18]
  get_user_name(id,name5,sizeof(name5))
  new weaponid,ammo,clip,mode,extra
  weaponid = ts_getuserwpn(id,clip,ammo,mode,extra)
  if(weaponid == 0 || weaponid == 36) {
      client_print(id,print_chat,"[GunShop] You need to be wieliding a weapon to buy ammo for it^n")
      Gunshop_Main(id)
      return PLUGIN_HANDLED
  }
 
  new check, buffer[64], maxammo, authid[32], weaponame[64]
  if(weaponid == 24 || weaponid == 25 || weaponid == 35) check = clip
      else check = ammo
   
  num_to_str(weaponid,buffer,63)
  select_string(id,"gunshop","maxium","weaponid",buffer,buffer)
  select_string(id,"gunshop","name","weaponid",buffer,weaponame)
  maxammo = str_to_num(buffer)
 
  if(check >= maxammo) {
      client_print(id,print_chat,"[GunShop] You have already full ammo for this gun^n")
      Gunshop_Main(id)
      return PLUGIN_HANDLED
  }
 
  get_user_authid(id,authid,31)
  client_print(id,print_chat,"[GunShop] Your weapon has been refilled!^n")
 
  ts_setuserammo(id,weaponid,maxammo)
  return PLUGIN_HANDLED
}

public nearmessage(id) {
  new num, players[32],origin[3]
  get_players(players,num,"ac")
  for(new i = 0;i < num; i++) {
      get_user_origin(i,origin)
      if(get_distance(origin,gunshop) <= 50.0) {
        set_hudmessage(0,175,0,-1.5,0.95,2,0.0,99.9,0.0,0.0,2)
        show_hudmessage(i,"You are near the admin gunshop")
      }
  }
  return PLUGIN_HANDLED
}


haimmaik 11-02-2005 20:51

1. put the keys u want b4 the registeration of the menu and put key in the registerations

Code:
      new key = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<9)    register_menucmd(register_menuid("Admin Gunshop Main Menu"),key,"Admin_Gunshop_Main_Action")    register_menucmd(register_menuid("Admin Gunshop - "),key,"Admin_Gunshop_Weapon_Action")    register_menucmd(register_menuid("Admin Weapon Addons - "),key,"Admin_Addons_Action")

2.now in the menu functions make sure that the first
line in the format will be exactly the menuid of the current menu
[EXAMPLE]:

Code:
new len = format(menu,sizeof(menu),"Gunshop Main Menu^n^n")
turnes into
Code:
new len = format(menu,sizeof(menu),"Admin Gunshop Main Menu^n^n")

also make sure that ur function has no other errors

3.if it doesnt work use another style to register ur keys

Code:

new keys = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5......
insted of
Code:

new key = (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<9)

Charr 11-02-2005 21:20

The problem is that the menu isn't executing any funcitons, it just closes when something is selected.

XxAvalanchexX 11-02-2005 22:54

Code:
register_menuid("Admin Gunshop Main Menu")
Code:
format(menu,sizeof(menu),"Gunshop Main Menu^n^n")

I'm just waiting for the rest of the community to catch on to menu titles.

Des12 11-03-2005 18:28

The plugin didn't work even before I changed the names, but I will try to fix them now. Thanks guys!


All times are GMT -4. The time now is 23:42.

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