AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [ZP] Buy Limit Armor (https://forums.alliedmods.net/showthread.php?t=338604)

BerkayF 07-16-2022 05:41

[ZP] Buy Limit Armor
 
1 Attachment(s)
[ZP] Buy Limit Armor

Hello guys
I'm Making an Armor Limit
I'm stuck somewhere
Current Problem: The problem is that the limit of players is not renewed when they move to the new round

Problem lines:
PHP Code:

public round_start()
{
    new 
players[32]
    
get_players(players)
    
    
g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)



Full SMA:
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Anti-Infection Armor" }
const 
g_item_cost 20                // Armor Cost

new const g_sound_buyarmor[] = { "items/tr_kevlar.wav" }
const 
g_armor_amount 100           // Armor Amount
const g_armor_limit 250            // Armor Limit
new g_armor_buy[33]                  // Armor Buy Limit
new cvar_armor_limit

/*============================================================================*/

// Item IDs
new g_itemid_humanarmor

public plugin_precache()
{
    
precache_sound(g_sound_buyarmor)
}

public 
plugin_init()
{
    
register_plugin("[ZP] Extra: Anti-Infection Armor""1.0""MeRcyLeZZ")
    
register_event("HLTV","round_start","a","1=0","2=0")
    
register_clcmd("reset_buy_armor_id""reset_buy_armor_id")
    
cvar_armor_limit register_cvar("zp_armor_limit""5")
    
g_itemid_humanarmor zp_register_extra_item(g_item_nameg_item_costZP_TEAM_HUMAN)
}

// Human buys our upgrade, give him some armor
public zp_extra_item_selected(playeritemid)
{
    
    if (
g_armor_buy[player] <= get_pcvar_num(cvar_armor_limit) && g_armor_buy[player] != 0)
    {
    if (
itemid == g_itemid_humanarmor)
    {
        
g_armor_buy[player]--
        
set_pev(playerpev_armorvaluefloat(min(pev(playerpev_armorvalue)+g_armor_amountg_armor_limit)))
        
engfunc(EngFunc_EmitSoundplayerCHAN_BODYg_sound_buyarmor1.0ATTN_NORM0PITCH_NORM)
        
client_print(playerprint_chat"[ZP] Your remaining armor purchase limit: %d/%d"g_armor_buy[player], get_pcvar_num(cvar_armor_limit))
    }
    }
    
    if (
g_armor_buy[player] < 1)
    {
    if (
itemid == g_itemid_humanarmor)
    {
        
zp_set_user_ammo_packs(player,zp_get_user_ammo_packs(player) + g_item_cost);
        
client_print(playerprint_chat"[ZP] We have reached the armor purchase limit")
    }
    }
}

public 
round_start()
{
    new 
players[32]
    
get_players(players)
    
    
g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)
}

public 
client_putinserver(player)
{
    
g_armor_buy[player] = get_pcvar_num(cvar_armor_limit)



lexzor 07-16-2022 11:48

Re: [ZP] Buy Limit Armor
 
PHP Code:

public round_start()
{
    static 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayeriNum"ch");

    for(static 
iiPlayeriNumi++)
    {
        
iPlayer iPlayers[i];

        if(
is_user_alive(iPlayer))
            
g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)
    }



BerkayF 07-16-2022 14:18

Re: [ZP] Buy Limit Armor
 
I'll try it right away

Quote:

Originally Posted by lexzor (Post 2783913)
PHP Code:

public round_start()
{
    static 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayeriNum"ch");

    for(static 
iiPlayeriNumi++)
    {
        
iPlayer iPlayers[i];

        if(
is_user_alive(iPlayer))
            
g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)
    }




BerkayF 07-16-2022 14:26

Re: [ZP] Buy Limit Armor
 
https://cdn.discordapp.com/attachmen...716_212241.jpg
This code has been tried now
but the error was encountered

Quote:

Originally Posted by lexzor (Post 2783913)
PHP Code:

public round_start()
{
    static 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayeriNum"ch");

    for(static 
iiPlayeriNumi++)
    {
        
iPlayer iPlayers[i];

        if(
is_user_alive(iPlayer))
            
g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)
    }



Error:
Code:

77  public round_start()
78  {
79    static iPlayers[MAX_PLAYERS], iNum;
80    get_players(iPlayer, iNum, "ch");
81
82    for(static i, iPlayer; i < iNum; i++)
83    {
84        iPlayer = iPlayers[i];
85
86        if(is_user_alive(iPlayer))
87            g_armor_buy[players] = get_pcvar_num(cvar_armor_limit)
88    }
89  }


lexzor 07-17-2022 07:20

Re: [ZP] Buy Limit Armor
 
PHP Code:

public round_start()
{
    static 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayersiNum"ch");

    for(static 
iiPlayeriNumi++)
    {
        
iPlayer iPlayers[i];

        if(
is_user_alive(iPlayer))
            
g_armor_buy[iPlayer] = get_pcvar_num(cvar_armor_limit)
    }



JUSTINR 07-17-2022 12:38

Re: [ZP] Buy Limit Armor
 
100% WORKING
Code:

/*================================================================================
       
        -------------------------------------------------
        -*- [ZP] Extra Item: Anti-Infection Armor 1.0 -*-
        -------------------------------------------------
       
        ~~~~~~~~~~~~~~~
        - Description -
        ~~~~~~~~~~~~~~~
       
        This item gives humans some armor that offers protection
        against zombie injuries.
       
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Anti-Infection armor" }
const g_item_cost = 15
new count[33]
new g_Maxplayers

new const g_sound_buyarmor[] = { "items/tr_kevlar.wav" }
const g_armor_amount = 100
const g_armor_limit = 800

/*============================================================================*/

// Item IDs
new g_itemid_humanarmor

public plugin_precache()
{
        precache_sound(g_sound_buyarmor)
}

public plugin_init()
{
        register_plugin("[ZP] Extra: Anti-Infection Armor", "1.0", "MeRcyLeZZ")
        register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
        g_itemid_humanarmor = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_HUMAN)
        g_Maxplayers = get_maxplayers()
}

public Event_NewRound ( )
{
      for(new player;player<g_Maxplayers;player++)
      count[player]= 0;
}

// Human buys our upgrade, give him some armor
public zp_extra_item_selected(player, itemid)
{
        if (itemid == g_itemid_humanarmor)
        {
                if (count[player] >= 5)
                    {
                client_print(player, print_chat, "You can buy this item only 5 times per Round")
                return ZP_PLUGIN_HANDLED; //give ammo packs back
                }
                set_pev(player, pev_armorvalue, float(min(pev(player, pev_armorvalue)+g_armor_amount, g_armor_limit)))
                engfunc(EngFunc_EmitSound, player, CHAN_BODY, g_sound_buyarmor, 1.0, ATTN_NORM, 0, PITCH_NORM)
                count[player]++
        }       
        return PLUGIN_CONTINUE;
}


BerkayF 07-17-2022 13:11

Re: [ZP] Buy Limit Armor
 
You're amazing.
Thank you very much :)

Quote:

Originally Posted by JUSTINR (Post 2783979)
100% WORKING
Code:

/*================================================================================
       
        -------------------------------------------------
        -*- [ZP] Extra Item: Anti-Infection Armor 1.0 -*-
        -------------------------------------------------
       
        ~~~~~~~~~~~~~~~
        - Description -
        ~~~~~~~~~~~~~~~
       
        This item gives humans some armor that offers protection
        against zombie injuries.
       
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Anti-Infection armor" }
const g_item_cost = 15
new count[33]
new g_Maxplayers

new const g_sound_buyarmor[] = { "items/tr_kevlar.wav" }
const g_armor_amount = 100
const g_armor_limit = 800

/*============================================================================*/

// Item IDs
new g_itemid_humanarmor

public plugin_precache()
{
        precache_sound(g_sound_buyarmor)
}

public plugin_init()
{
        register_plugin("[ZP] Extra: Anti-Infection Armor", "1.0", "MeRcyLeZZ")
        register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
        g_itemid_humanarmor = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_HUMAN)
        g_Maxplayers = get_maxplayers()
}

public Event_NewRound ( )
{
      for(new player;player<g_Maxplayers;player++)
      count[player]= 0;
}

// Human buys our upgrade, give him some armor
public zp_extra_item_selected(player, itemid)
{
        if (itemid == g_itemid_humanarmor)
        {
                if (count[player] >= 5)
                    {
                client_print(player, print_chat, "You can buy this item only 5 times per Round")
                return ZP_PLUGIN_HANDLED; //give ammo packs back
                }
                set_pev(player, pev_armorvalue, float(min(pev(player, pev_armorvalue)+g_armor_amount, g_armor_limit)))
                engfunc(EngFunc_EmitSound, player, CHAN_BODY, g_sound_buyarmor, 1.0, ATTN_NORM, 0, PITCH_NORM)
                count[player]++
        }       
        return PLUGIN_CONTINUE;
}




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

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