Catalog News Guides Community For contributors
Everything for CS 1.6 / CSS / CS:GO servers - Plugins | Builds | Models | Maps » Articles » Articles about CS 1.6 » Pawn Additional grenade. Example code for training

Pawn Additional grenade. Example code for training

01.06.2023, 22:47adminViews: 172Comments: 0
Pawn Additional grenade. Example code for training

About this content

Pawn  Дополнительная граната. Пример кода для обучения

This code defines several constants that define the access flag of the team "b" (TEAM_FLAG), the maximum number of grenades a player can have (MAX_GRANADES), the path to the custom grenade model (CUSTOM_GRENADE_MODEL) and the path to the custom grenade sound (CUSTOM_GRENADE_SOUND).

The function plugin_init() registers the plugin and the command buygrenade2. This command will be called when a player buys a grenade in the additional slot.

The function DeathMsg() handles the player death event and checks whether the attacking player has the "b" access flag. If so, the number of grenades held by the attacking player is checked and one grenade is added if the number does not exceed MAX_GRANADES.

The function buygrenade2(id) performs the purchase of a grenade in the additional slot for players with the "b" access flag. It checks the player's access flag, team, and number of grenades, then adds one grenade if possible. The grenade sound is played using the function emit_sound, and the player is shown a message about buying a grenade.

After compiling and installing the plugin on the Counter-Strike 1.6 server, players with the "b" access flag will be able to buy and use an additional grenade in the game without replacing the standard grenade.

#include < amxmodx >
#include < amxmisc >

new const TEAM_FLAG = 'b';
new const MAX_GRANADES = 1;
new const CUSTOM_GRENADE_MODEL[] = "models/custom_grenade.mdl";
new const CUSTOM_GRENADE_SOUND[] = "sound/custom_grenade.wav";

public plugin_init()
{
register_plugin("b_custom_grenade", "1.0", "Your Name");
register_clcmd("buygrenade2", "buygrenade2");
register_event("DeathMsg", "DeathMsg", "be", "1=0,1=0");
}

public DeathMsg()
{
new victim = read_data(1), attacker = read_data(2);
new const flag = get_user_flags(attacker);

if (victim > 0 && attacker > 0 && (flag & ADMIN_KICK))
{
new const attacker_team = get_user_team(attacker);
if (attacker_team == TEAM_FLAG)
{
new const attacker_grenades = get_user_grenades(attacker, CS_WEAPON_HEGRENADE);
if (attacker_grenades < MAX_GRANADES)
{
set_user_grenades(attacker, CS_WEAPON_HEGRENADE, attacker_grenades + 1);
}
}
}
}

public buygrenade2(id)
{
new const flag = get_user_flags(id);

if (flag & ADMIN_KICK)
{
new const team = get_user_team(id);
if (team == TEAM_FLAG)
{
new const grenades = get_user_grenades(id, CS_WEAPON_HEGRENADE);
if (grenades < MAX_GRANADES)
{
set_user_grenades(id, CS_WEAPON_HEGRENADE, grenades + 1);
emit_sound(id, CHAN_ITEM, CUSTOM_GRENADE_SOUND, 1.0, ATTN_NORM, 0, 100);
client_print(id, print_chat, "You bought an extra grenade!");
return PLUGIN_HANDLED;
}
else
{
client_print(id, print_chat, "You already have the maximum number of grenades!");
return PLUGIN_STOP;
}
}
}
return PLUGIN_CONTINUE;
}


Comments (0)

Add comment

Leave a comment

New content by email

Subscription with email confirmation. No more than one email per day. Unsubscribe via the link in any email.

Join the community

Register · Reset password