Выдача MP5 при спавне, если нет primary оружия.

C

ComfortableZmServ

Здравствуйте.
Помогите пожалуйста, не знаю как выдать оружие при спавне, которое не стандартное, я пытался обращаться к weapon_mp5 и вписывать контрам и терам в gamemodes в primary weapon при спавне, но без успешно.:( Не знаю что еще можно сделать, чтобы выдавалась mp5, если нет основного оружия.
[CS:GO/ZP] ExtraItem: MP5 ver 3.1 - AlliedModders

C-подобный:
/**
* 
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <zombieplague>

#pragma newdecls required

/**
* Record plugin info.
**/
public Plugin myinfo =
{
    name            = "[ZP] ExtraItem: MP5",
    author          = "qubka (Nikita Ushakov)",     
    description     = "Add new extraitem to human",
    version         = "2.0",
    url             = "https://forums.alliedmods.net/showthread.php?t=272546"
}

/**
* @section Information about extra items.
**/
#define EXTRA_ITEM_NAME                "MP5"
#define EXTRA_ITEM_COST                5
#define EXTRA_ITEM_LEVEL            0
#define EXTRA_ITEM_ONLINE            0
#define EXTRA_ITEM_LIMIT            0

#define WEAPON_NAME                    "weapon_mp5"
#define WEAPON_REFERANCE            "weapon_mp9"

#define MODEL_WORLD                 "models/weapons/mp5/w_smg_mp5.mdl"
#define MODEL_VIEW                    "models/weapons/mp5/v_smg_mp5.mdl"

#define SOUND_FIRE1                    "weapons/mp5-1.mp3"
#define SOUND_FIRE2                    "weapons/mp5-2.mp3"

#define WEAPON_MULTIPLIER_DAMAGE     1.23
/**
* @endsection
**/

//*********************************************************************
//*           Don't modify the code below this line unless            *
//*               you know _exactly_ what you are doing!!!             *
//*********************************************************************
// Item index
int iItem;
bool bHasCustomWeapon[MAXPLAYERS+1];

// Weapon model indexes
int iViewModel;
int iWorldModel;

/**
* Plugin is loading.
**/
public void OnPluginStart()
{
    // Initilizate extra item
    iItem = ZP_RegisterExtraItem(EXTRA_ITEM_NAME, EXTRA_ITEM_COST, ZP_TEAM_HUMAN, EXTRA_ITEM_LEVEL, EXTRA_ITEM_ONLINE, EXTRA_ITEM_LIMIT);
   
    // Hook temp entity
    AddTempEntHook("Shotgun Shot", WeaponFireBullets);
}

/**
* The map is starting.
**/
public void OnMapStart(/*void*/)
{
    // Precache models
    iWorldModel = PrecacheModel(MODEL_WORLD);
    iViewModel  = PrecacheModel(MODEL_VIEW);
   
    // Precache sound
    char sSound[128];
    Format(sSound, sizeof(sSound), "*/%s", SOUND_FIRE1);
    AddToStringTable(FindStringTable("soundprecache"), sSound);
    Format(sSound, sizeof(sSound), "sound/%s", SOUND_FIRE1);
    AddFileToDownloadsTable(sSound);
    Format(sSound, sizeof(sSound), "*/%s", SOUND_FIRE2);
    AddToStringTable(FindStringTable("soundprecache"), sSound);
    Format(sSound, sizeof(sSound), "sound/%s", SOUND_FIRE2);
    AddFileToDownloadsTable(sSound);
   
    // Add models to download list
    AddFileToDownloadsTable("models/weapons/mp5/v_smg_mp5.mdl");
    AddFileToDownloadsTable("models/weapons/mp5/v_smg_mp5.dx90");
    AddFileToDownloadsTable("models/weapons/mp5/v_smg_mp5.vvd");
    AddFileToDownloadsTable("models/weapons/mp5/w_smg_mp5.mdl");
    AddFileToDownloadsTable("models/weapons/mp5/w_smg_mp5.dx90");
    AddFileToDownloadsTable("models/weapons/mp5/w_smg_mp5.phy");
    AddFileToDownloadsTable("models/weapons/mp5/w_smg_mp5.vvd");
   
    // Add textures to download list
    AddFileToDownloadsTable("materials/models/weapons/v_models/arby26/mp5/mp5_d.vtf");
    AddFileToDownloadsTable("materials/models/weapons/v_models/arby26/mp5/mp5_g.vtf");
    AddFileToDownloadsTable("materials/models/weapons/v_models/arby26/mp5/mp5_ns.vtf");
    AddFileToDownloadsTable("materials/models/weapons/v_models/arby26/mp5/mp5arby26.vmt");
}

/**
* Called after select an extraitem in equipment menu.
*
* @param clientIndex        The client index.
* @param extraitemIndex    Index of extraitem from ZP_RegisterExtraItem() native.
*
* @return                    Plugin_Handled to block purhase. Anything else
*                              (like Plugin_Continue) to allow purhase and taking ammopacks.
**/
public Action ZP_OnExtraBuyCommand(int clientIndex, int extraitemIndex)
{
    // Verify that the client is connected and alive
    if(!IsPlayerExist(clientIndex))
    {
        return Plugin_Handled;
    }
   
    // Check our item index
    if(extraitemIndex == iItem)
    {
        // Return ammopacks
        if(ZP_IsPlayerZombie(clientIndex) || ZP_IsPlayerSurvivor(clientIndex))
        {
            return Plugin_Handled;
        }

        //**********************************************
        //* GIVE WEAPON                                *
        //**********************************************
       
        // Get weapon index from slot
        int iSlot = GetPlayerWeaponSlot(clientIndex, WEAPON_SLOT_PRIMARY);

        // If weapon is valid, then drop
        if (iSlot != WEAPON_SLOT_INVALID)
        {
            CS_DropWeapon(clientIndex, iSlot, true, false);
        }
       
        // Give item
        bHasCustomWeapon[clientIndex] = true;
        GivePlayerItem(clientIndex, WEAPON_REFERANCE);
        FakeClientCommandEx(clientIndex, "use %s", WEAPON_REFERANCE);
    }
   
    // Allow buying
    return Plugin_Continue;
}

/**
* Set dropped model.
*
* @param weaponIndex        The weapon index.
**/
public void SetDroppedModel(int weaponIndex)
{
    // If weapon isn't custom
    if(!IsCustomItemEntity(weaponIndex))
    {
        return;
    }
   
    // Set dropped model
    SetEntityModel(weaponIndex, MODEL_WORLD);
}

/**
* Event callback (Shotgun Shot)
* The weapon is about to shoot.
*
* @param sTEName       Temp name.
* @param iPlayers      Array containing target player indexes.
* @param numClients    Number of players in the array.
* @param flDelay       Delay in seconds to send the TE.
**/
public Action WeaponFireBullets(const char[] sTEName, const int[] iPlayers, int numClients, float flDelay)
{
    // Initialize weapon index
    int weaponIndex;
   
    // Get all required event info
    int clientIndex = TE_ReadNum("m_iPlayer") + 1;

    // If weapon isn't custom
    if(!IsCustomItem(clientIndex, weaponIndex))
    {
        return;
    }
   
    // Initialize sound
    char sSound[128];
    Format(sSound, sizeof(sSound), "*/%s",GetRandomInt(0,1) ? SOUND_FIRE1 : SOUND_FIRE2);
   
    // Play sound
    EmitSoundToAll(sSound, clientIndex, SNDCHAN_WEAPON, SNDLEVEL_ROCKET);
    EmitSoundToAll(sSound, clientIndex, SNDCHAN_STATIC, SNDLEVEL_NORMAL);
}

//**********************************************
//* DAMAGE FUNCTIONS                           *
//**********************************************

/**
* Hook: OnTakeDamage
* Called right before damage is done.
*
* @param iVictim        The client index.
* @param iAttacker      The client index of the attacker.
* @param iInflicter     The entity index of the inflicter.
* @param flDamage       The amount of damage inflicted.
* @param pDamageBits    The type of damage inflicted.
**/
public Action WeaponTakeDamage(int iVictim, int &iAttacker, int &iInflicter, float &flDamage, int &pDamageBits)
{
    // Initialize weapon index
    int weaponIndex;

    // If weapon isn't custom
    if(!IsCustomItem(iAttacker, weaponIndex))
    {
        return Plugin_Continue;
    }
   
    // Change damage
    flDamage *= WEAPON_MULTIPLIER_DAMAGE;
    return Plugin_Changed;
}

/**
* Hook: WeaponSwitchPost
* Called, when player deploy any weapon.
*
* @param clientIndex     The client index.
* @param weaponIndex    The weapon index.
**/
public void WeaponDeployPost(int clientIndex, int weaponIndex)
{
    // If client just buy this custom weapon
    if(bHasCustomWeapon[clientIndex])
    {
        // Reset bool
        bHasCustomWeapon[clientIndex] = false;
       
        // Verify that the weapon is valid
        if(!IsValidEdict(weaponIndex))
        {
            return;
        }

        // Set custom name
        DispatchKeyValue(weaponIndex, "globalname", WEAPON_NAME);
    }
   
    // If weapon isn't valid, then stop
    if(!IsCustomItemEntity(weaponIndex))
    {
        return;
    }
   
    // Verify that the client is connected and alive
    if(!IsPlayerExist(clientIndex))
    {
        return;
    }

    // Set weapon models
    SetViewModel(weaponIndex, ZP_GetClientViewModel(clientIndex), iViewModel);
    SetWorldModel(weaponIndex, iWorldModel);
}

//**********************************************
//* OTHER FUNCTIONS                            *
//**********************************************

/**
* Called once a client is authorized and fully in-game, and
* after all post-connection authorizations have been performed. 
*
* This callback is gauranteed to occur on all clients, and always
* after each OnClientPutInServer() call.
*
* @param clientIndex        The client index.
**/
public void OnClientPutInServer(int clientIndex)
{
    SDKHook(clientIndex, SDKHook_WeaponDropPost,     WeaponDropPost)
    SDKHook(clientIndex, SDKHook_WeaponSwitchPost,  WeaponDeployPost);
    SDKHook(clientIndex, SDKHook_OnTakeDamage,       WeaponTakeDamage);
}

/**
* Called after dropping weapon.
*
* @param clientIndex        The client index.
* @param weaponIndex        The weapon index.
**/
public Action WeaponDropPost(int clientIndex, int weaponIndex)
{
    // Set dropped model on next frame
    RequestFrame(view_as<RequestFrameCallback>(SetDroppedModel), weaponIndex);
}

//**********************************************
//* STOCKS                                     *
//**********************************************


/**
* Validate custom weapon and player.
*
* @param clientIndex        The client index.
* @param weaponIndex        The weapon index.
* @return                     True if valid, false if not.
**/
stock bool IsCustomItem(int clientIndex, int &weaponIndex)
{
    // Validate client
    if (!IsPlayerExist(clientIndex))
    {
        return false;
    }
   
    // Get weapon index
    weaponIndex = GetEntPropEnt(clientIndex, Prop_Data, "m_hActiveWeapon");
   
    // Verify that the weapon is valid
    if(!IsValidEdict(weaponIndex))
    {
        return false;
    }
   
    // Get weapon classname
    char sClassname[32];
    GetEntityClassname(weaponIndex, sClassname, sizeof(sClassname));
   
    // If weapon classname isn't equal, then stop
    if(!StrEqual(sClassname, WEAPON_REFERANCE))
    {
        return false;
    }
   
    // Get weapon global name
    GetEntPropString(weaponIndex, Prop_Data, "m_iGlobalname", sClassname, sizeof(sClassname));

    // If weapon key isn't equal, then stop
    if(!StrEqual(sClassname, WEAPON_NAME))
    {
         return false;
    }
   
    // If it is custom weapon
    return true;
}

/**
* Validate custom weapon.
*
* @param weaponIndex        The weapon index.
* @return                     True if valid, false if not.
**/
stock bool IsCustomItemEntity(int weaponIndex)
{
    // Verify that the weapon is valid
    if(!IsValidEdict(weaponIndex))
    {
        return false;
    }
   
    // Get weapon classname
    char sClassname[32];
    GetEntityClassname(weaponIndex, sClassname, sizeof(sClassname));
   
    // If weapon classname isn't equal, then stop
    if(!StrEqual(sClassname, WEAPON_REFERANCE))
    {
        return false;
    }
   
    // Get weapon global name
    GetEntPropString(weaponIndex, Prop_Data, "m_iGlobalname", sClassname, sizeof(sClassname));

    // If weapon key isn't equal, then stop
    if(!StrEqual(sClassname, WEAPON_NAME))
    {
         return false;
    }
   
    // If it is custom weapon
    return true;
}
 
Последнее редактирование модератором:

inklesspen

Не пишу модули под LSD :с
Сообщения
1,775
Реакции
966
weapon_mp5 не существует. есть weapon_mp9
--- Добавлено позже ---
Кстати при выдачи у тебя крашится?
При выдачи weapon_usp на CS:GO идет краш. Так-же при weapon_sg560
 
C

ComfortableZmServ

weapon_mp5 не существует. есть weapon_mp9
--- Добавлено позже ---
Кстати при выдачи у тебя крашится?
При выдачи weapon_usp на CS:GO идет краш. Так-же при weapon_sg560
weapon_mp5 прописано в этом плагине, поэтмоу я подумал через эту фразу выдать это оружие, как-то же оно выдается при покупке в меню. Но надо чтобы оно давалось при спавне, как например броня.
 

inklesspen

Не пишу модули под LSD :с
Сообщения
1,775
Реакции
966
weapon_mp5 прописано в этом плагине, поэтмоу я подумал через эту фразу выдать это оружие, как-то же оно выдается при покупке в меню. Но надо чтобы оно давалось при спавне, как например броня.
weapon_mp5 это имя оружия, не его класс.
А так надо прописывать в самом аддоне на мп5
--- Добавлено позже ---
При покупке хукается смена оружия на него и идет замена моделей, не какой это не weapon_mp5
 
C

ComfortableZmServ

weapon_mp5 это имя оружия, не его класс.
А так надо прописывать в самом аддоне на мп5
--- Добавлено позже ---
При покупке хукается смена оружия на него и идет замена моделей, не какой это не weapon_mp5
А можно тогда это как-то провернуть всё равно? Выдать mp9 в начале раунда, а дальше всё так как в плагине? Очень нужно чтобы выдавался этот экстраитем при спавне, как глок террористу. Прямо аж трясёт как это нужно)
 

inklesspen

Не пишу модули под LSD :с
Сообщения
1,775
Реакции
966
А можно тогда это как-то провернуть всё равно? Выдать mp9 в начале раунда, а дальше всё так как в плагине? Очень хочу чтобы выдавался этот экстраитем при спавне, как глок террористу. Аж жопу рвёт.
прописывать в самом аддоне на мп5
 
C

ComfortableZmServ

weapon_mp5 это имя оружия, не его класс.
А так надо прописывать в самом аддоне на мп5
--- Добавлено позже ---
При покупке хукается смена оружия на него и идет замена моделей, не какой это не weapon_mp5
Извините, но я не совсем понял, где прописывать и как?
 
Последнее редактирование модератором:
Сверху Снизу