AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   passing variables to a menu (https://forums.alliedmods.net/showthread.php?t=10953)

Mugsy 03-05-2005 22:11

passing variables to a menu
 
Here is my plugin to give a menu to the victim of a team killer. In my handle_option() function I need to pass the variable vindex to it, how would I pass that variable to it?

Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>

#define MAX_NAME 33

//Declare three string variables
new PLUGIN[]="TK Revenge"
new AUTHOR[]="Shawn Wallis"
new VERSION[]="1.00"

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    new keys = MENU_KEY_1|MENU_KEY_2
    register_menucmd(register_menuid("Forgive?"), keys, "handle_option")
    register_event("DeathMsg", "event_tk", "a")

}

public event_tk(id)
{
  new kindex = read_data(1) //get the first message parameter
  new kteam = entity_get_int(kindex, EV_INT_team)
  new kname[MAX_NAME]
  get_user_name(kindex, kname, MAX_NAME)

  new vindex = read_data(2) //get the second message parameter
  new vteam = entity_get_int(vindex, EV_INT_team)
  new vname[MAX_NAME]
  get_user_name(kindex, vname, MAX_NAME)

  new weapon[32]
  read_data(3, weapon, 31)  //get the weapon name

  /* if killer is alive, not himself, and on same team */
 // if (kindex && (kindex != vindex) && (kteam == vteam)) {
    new params[2]
    params[0] = vindex
    params[1] = kindex
    set_task(0.2, "show_tkmenu", 0, params, 1)

    client_print(kindex, print_chat, "%s has team killed %s", kname, vname)
 // }

  return PLUGIN_HANDLED
}

public show_tkmenu(params[]) {
  new kname[MAX_NAME]
  get_user_name(params[1], kname, MAX_NAME)
  new tkmenu[192]
  new keys = MENU_KEY_1|MENU_KEY_2

//  format(tkmenu, 191, "You have been team killed by %s.^n^n1. Forgive^n2. Do not forgive", kname)
  format(tkmenu, 191, "Forgive?^n^n1. Forgive^n2. Do not forgive", kname)
  show_menu(params[0], keys, tkmenu)

  return PLUGIN_HANDLED
}

public handle_option(id, key) {
  new tkname[MAX_NAME]
  get_user_name(id, tkname, MAX_NAME)
  if (key == 0)
  {
    client_print(0, print_chat, "%s has forgiven", tkname)
  } else if (key == 1) {
    client_print(0, print_chat, "%s has not forgiven", tkname)
  }
}


xeroblood 03-05-2005 22:56

make vindex a global variable.. then both functions can access it


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

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