Member
Join Date: Feb 2019
Location: Italy / Albania
|
06-04-2019
, 20:20
Re: [ZP] Donate Ammopacks
|
#2
|
Hi, haven't tested it, but it should work. You can put different amounts on the "menuPos" array
PHP Code:
#include <amxmodx>
#include <zombieplague>
new const VERSION[] = "1.0.1"
new const menuPos[][] = {
"100",
"250",
"500",
"1000",
"5000",
"CUSTOM"
}
new gGiving[ 33 ]
public plugin_init(){
register_plugin("[ZP] Donate Menu", VERSION, "DusT")
register_clcmd("say /donate", "donateMenu")
register_clcmd("_donate_ammo", "cusDonation")
}
public donateMenu(id){
static menuid, menu[32], buffer[2]
new players[32], num, name[32]
menuid = menu_create("Donate Menu", "menuHandler")
get_players(players, num)
buffer[1] = 0
for(new i = 0; i < num; i++){
if(id == players[i]) continue
buffer[0] = players[i]
get_user_name(players[i], name, charsmax(name))
formatex(menu, charsmax(menu), "%s", name)
menu_additem(menuid, menu, buffer)
}
menu_display(id, menuid, 0)
}
public menuHandler(id, menuid, item){
if(!is_user_connected(id) || item == MENU_EXIT){
gGiving[id] = 0
menu_destroy(menuid)
return PLUGIN_HANDLED
}
new buffer[2], dummy
menu_item_getinfo(menuid, item, dummy, buffer, charsmax(buffer), _, _, dummy)
gGiving[id] = buffer[0]
menu_destroy(menuid)
chooseAmmo(id)
return PLUGIN_HANDLED
}
public chooseAmmo(id){
static menuid, menu[32]
menuid = menu_create("How much AmmoPacks to donate", "ammoHandler")
for(new i = 0; i < sizeof(menuPos); i++){
formatex(menu, charsmax(menu), "%s %s", menuPos[i], equali(menuPos[i], "custom")? "": "AmmoPack(s)")
menu_additem(menuid, menu)
}
menu_display(id, menuid, 0)
}
public ammoHandler(id, menuid, item){
if(!is_user_connected(id) || item == MENU_EXIT){
gGiving[id] = 0
menu_destroy(menuid)
return PLUGIN_HANDLED
}
new pid
if( equali(menuPos[item], "CUSTOM")){
menu_destroy(menuid)
customAmmo(id)
return PLUGIN_HANDLED
}
pid = gGiving[id]
gGiving[id] = 0
menu_destroy(menuid)
giveAmmo(id, pid, str_to_num(menuPos[item]))
return PLUGIN_HANDLED
}
public customAmmo( id ){
client_cmd(id, "messagemode _donate_ammo")
}
public cusDonation(id){
if(!gGiving[id])
return PLUGIN_HANDLED
new ammo[32], pid
pid = gGiving[id]
gGiving[id] = 0
read_args(ammo, charsmax(ammo))
remove_quotes(ammo)
giveAmmo(id, pid, str_to_num(ammo))
return PLUGIN_HANDLED
}
public giveAmmo(id, playerid, ammo){
if(!is_user_connected(id) || !is_user_connected(playerid))
return PLUGIN_HANDLED
if(zp_get_user_ammo_packs(id) < ammo){
client_print(id, print_chat, "[ZP] You don't have enough AmmoPacks")
return PLUGIN_HANDLED
}
if(!ammo || ammo < 0)
return PLUGIN_HANDLED
new name[32]
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - ammo)
zp_set_user_ammo_packs(playerid, zp_get_user_ammo_packs(playerid) + ammo)
get_user_name(playerid, name, charsmax(name))
client_print(id, print_chat, "[ZP] You donated %d AmmoPacks to '%s'", ammo, name)
get_user_name(id, name, charsmax(name))
client_print(playerid, print_chat, "[ZP] '%s' donated you %d AmmoPacks", name, ammo)
return PLUGIN_HANDLED
}
EDIT: while looking at it, it seemed pretty badly formatted and written. this is the same plugin basically, but only works for 1.8.3+
PHP Code:
#include <amxmodx>
#include <zombieplague>
new const VERSION[] = "1.1";
// put max or min to 0 to disable.
new const MIN_DONATION = 50;
new const MAX_DONATION = 0;
new const PREFIX[] = "^4[TeamNexium]^1";
new const menuPos[][] =
{
"50",
"100",
"250",
"500",
"1000",
"5000"
}
new gGiving[ 33 ];
public plugin_init()
{
register_plugin( "Donate Menu", VERSION, "DusT" );
register_clcmd( "say /donate", "CmdDonateMenu" );
register_clcmd( "say donate", "CmdDonateMenu" );
register_clcmd( "_donate_ammo", "CusDonation" );
}
public CmdDonateMenu(id){
if( MIN_DONATION && zp_get_user_ammo_packs( id ) < MIN_DONATION )
{
client_print_color( id, print_team_red, "%s You don't have enough AmmoPacks to donate.", PREFIX );
return PLUGIN_HANDLED;
}
new players[ 32 ], num;
new buffer[ 2 ];
new menuid = menu_create( "Donate Menu", "MenuHandler" );
get_players( players, num );
buffer[ 1 ] = 0;
for( new i; i < num; i++ )
{
if( id == players[ i ] ) continue;
buffer[ 0 ] = players[ i ];
menu_additem( menuid, fmt( "%n", buffer[ 0 ] ), buffer );
}
gGiving[ id ] = 0; // just a safe way to be sure it's 0
menu_display( id, menuid );
return PLUGIN_HANDLED;
}
public MenuHandler( id, menuid, item )
{
if( is_user_connected( id ) && item != MENU_EXIT )
{
new buf[ 2 ];
menu_item_getinfo( menuid, item, _, buf, charsmax( buf ) );
gGiving[ id ] = buf[ 0 ];
ChooseAmmoMenu( id );
}
else
gGiving[ id ] = 0;
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
ChooseAmmoMenu( id )
{
new menuid;
menuid = menu_create( "How much AmmoPacks to donate", "AmmoHandler" );
for( new i; i < sizeof menuPos; i++ )
menu_additem(menuid, fmt( "%s AmmoPacks", menuPos[ i ] ) );
menu_additem( menuid, "Custom" );
menu_display( id, menuid );
}
public AmmoHandler( id, menuid, item )
{
if( gGiving[ id ] && is_user_connected( id ) && is_user_connected( gGiving[ id ] ) && item != MENU_EXIT )
{
if( item == sizeof menuPos )
client_cmd( id, "messagemode _donate_ammo" );
else
GiveAmmo( id, gGiving[ id ], str_to_num( menuPos[ item ] ) );
}
else
gGiving[ id ] = 0;
menu_destroy( menuid );
return PLUGIN_HANDLED;
}
public CusDonation( id )
{
if( !gGiving[ id ] )
return PLUGIN_HANDLED;
new ammo[ 32 ];
read_args( ammo, charsmax( ammo ) );
remove_quotes( ammo );
GiveAmmo( id, gGiving[ id ], str_to_num( ammo ) );
return PLUGIN_HANDLED;
}
GiveAmmo( id, playerid, ammo )
{
if( !is_user_connected( id ) || !is_user_connected( playerid ) )
return;
if( MIN_DONATION && MIN_DONATION > ammo )
{
client_print_color( id, print_team_red, "%s You can't donate less than %s AmmoPacks.", PREFIX, MIN_DONATION );
return;
}
if( MAX_DONATION && MAX_DONATION < ammo )
{
client_print_color( id, print_team_red, "%s You can't donate more than %s AmmoPacks.", PREFIX, MAX_DONATION );
return;
}
if( zp_get_user_ammo_packs( id ) < ammo )
{
client_print_color( id, print_team_red, "%s You don't have enough AmmoPacks to donate.", PREFIX );
return;
}
if( ammo <= 0 )
{
client_print_color( id, print_team_red, "%s You can't donate that amount.", PREFIX );
return;
}
zp_set_user_ammo_packs( id, zp_get_user_ammo_packs( id ) - ammo );
zp_set_user_ammo_packs( playerid, zp_get_user_ammo_packs( playerid ) + ammo );
client_print_color( id, print_team_red, "%s You donated %d AmmoPacks to %n", ammo, playerid );
client_print_color( playerid, print_team_red, "%s %n donated you %d AmmoPacks", id, ammo );
}
Last edited by AmXDusT; 02-13-2020 at 19:06.
|
|