Raised This Month: $ Target: $400
 0% 

[L4D2] Upgrade Packs with Ammo


Post New Thread Reply   
 
Thread Tools Display Modes
Author
bullet28
Member
Join Date: Apr 2012
Plugin ID:
7034
Plugin Version:
1.0
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Creates ammo pile at the place where the upgrade pack was deployed
    Old 04-08-2020 , 16:52   [L4D2] Upgrade Packs with Ammo
    Reply With Quote #1

    Name:  1.jpg
Views: 3088
Size:  91.4 KB

    No cvars.
    Attached Files
    File Type: sp Get Plugin or Get Source (lfd_coop_ammoStackSpawn.sp - 1101 views - 1.6 KB)
    bullet28 is offline
    SkiPlix
    Member
    Join Date: Dec 2016
    Location: Argentina
    Old 04-12-2020 , 22:48   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #2

    Can you add a config to easily change the model of the ammo can, and maybe the position of the model itself?
    SkiPlix is offline
    bullet28
    Member
    Join Date: Apr 2012
    Old 04-13-2020 , 01:58   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #3

    Quote:
    Originally Posted by SkiPlix View Post
    Can you add a config to easily change the model of the ammo can, and maybe the position of the model itself?
    I left the names of models on line 16 especially for such cases, you can easily replace it.
    Also, if you don't like position try to change values on lines 45-46 and 47-48 in source code.
    I'm not going to do position offset as a ConVar because it makes no sense to me.
    bullet28 is offline
    Shao
    Senior Member
    Join Date: Jan 2015
    Old 05-04-2020 , 05:12   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #4

    Another great plugin from you, keep it up!

    It pairs will with Gun Control from Atomic Stryker, although if I may recommend. Perhaps it would be a good thing to allow more special ammo mags within this plugin rather than having to be forced using Gun Control, or have a version without it.
    Shao is offline
    NoroHime
    Veteran Member
    Join Date: Aug 2016
    Location: bed
    Old 11-01-2022 , 05:47   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #5

    modify version, make ammo pile can use once time only

    PHP Code:
    #pragma semicolon 1
    #include <sourcemod>
    #include <sdkhooks>
    #include <sdktools>
    #pragma newdecls required

    public Plugin myinfo =
    {
        
    name "Upgrade Packs with Ammo (Once Time)",
        
    author "bullet28, NoroHime",
        
    description "Creates ammo pile at the place where the upgrade pack was deployed",
        
    version "1",
        
    url "https://forums.alliedmods.net/showthread.php?p=2691806"
    }

    #define MODEL_AMMO "models/props_unique/spawn_apartment/coffeeammo.mdl" // another model variants: "models/props/terror/ammo_stack.mdl" "models/props/de_prodigy/ammo_can_02.mdl"

    public void OnMapStart() {
        if (!
    IsModelPrecached(MODEL_AMMO)) {
            
    PrecacheModel(MODEL_AMMO);
        }
    }

    public 
    void OnEntityCreated(int entity, const char[] classname) {
        if (
    StrContains(classname"upgrade_ammo_") != -1)
            
    SDKHook(entitySDKHook_SpawnPostOnPostUpgradeSpawn);
    }

    public 
    void OnPostUpgradeSpawn(int entity) {
        if (!
    IsValidEntity(entity)) return;

        
    char classname[32];
        
    GetEdictClassname(entityclassnamesizeof(classname));
        if (
    StrContains(classname"upgrade_ammo_") == -1) return;

        
    int ammoStack CreateEntityByName("weapon_ammo_spawn");
        if (
    ammoStack <= 0) return;

        
    float origin[3];
        
    GetEntPropVector(entityProp_Send"m_vecOrigin"origin);
        
        
    origin[0] -= 10.0;
        
    origin[1] -= 10.0;
        
    TeleportEntity(entityoriginNULL_VECTORNULL_VECTOR);

        
    origin[0] += 20.0;
        
    origin[1] += 20.0;
        
    TeleportEntity(ammoStackoriginNULL_VECTORNULL_VECTOR);

        
    SetEntityModel(ammoStackMODEL_AMMO);
        
    DispatchSpawn(ammoStack);
        
    SDKHook(ammoStackSDKHook_UsePostOnUsePost);
    }

    void OnUsePost(int entityint activatorint callerUseType typefloat value) {
        
    /*if (GetRandomFloat() > 0.5) //if you want has chance to clear, lower mean high chance
            return;*/
        
    SDKUnhook(entitySDKHook_UsePostOnUsePost);
        
    SetVariantString("OnUser1 !self:Kill::0:-1");
        
    AcceptEntityInput(entity"AddOutput");
        
    AcceptEntityInput(entity"FireUser1");

    Attached Files
    File Type: sp Get Plugin or Get Source (lfd_coop_ammoStackSpawnOnce.sp - 151 views - 1.9 KB)
    __________________

    Last edited by NoroHime; 11-01-2022 at 05:55.
    NoroHime is offline
    BioHazardN7
    Member
    Join Date: Oct 2020
    Location: Укр
    Old 09-29-2023 , 05:25   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #6

    Quote:
    Originally Posted by NoroHime View Post
    modify version, make ammo pile can use once time only
    It's perfect!

    Can you make it so that all players on the server can take ammunition once, including servers with 5+ players? Please!
    BioHazardN7 is offline
    Silvers
    SourceMod Plugin Approver
    Join Date: Aug 2010
    Location: SpaceX
    Old 09-29-2023 , 05:55   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #7

    Quote:
    Originally Posted by NoroHime View Post
    modify version, make ammo pile can use once time only
    Please don't use StrContains in OnEntityCreated or other functions that are called often, what you want is strncmp to compare that first set of characters. StrContains will check every position of the string, it's not efficient for this purpose. You should really only use StrContains when you need to check for something within a string and you can't guarantee it's position. For the rest use strcmp or strncmp.

    There's no need to check the classname in OnPostUpgradeSpawn.

    The AcceptEntityInput kill part can be replaced with RemoveEntity() since you're removing it instantly without any delay. And also no need for SDKUnhook since you're removing it.
    __________________

    Last edited by Silvers; 09-29-2023 at 06:18.
    Silvers is offline
    BloodyBlade
    Senior Member
    Join Date: Feb 2018
    Old 05-09-2024 , 10:17   Re: [L4D2] Upgrade Packs with Ammo
    Reply With Quote #8

    Quote:
    Originally Posted by Silvers View Post
    Please don't use StrContains in OnEntityCreated or other functions that are called often, what you want is strncmp to compare that first set of characters. StrContains will check every position of the string, it's not efficient for this purpose. You should really only use StrContains when you need to check for something within a string and you can't guarantee it's position. For the rest use strcmp or strncmp.

    There's no need to check the classname in OnPostUpgradeSpawn.

    The AcceptEntityInput kill part can be replaced with RemoveEntity() since you're removing it instantly without any delay. And also no need for SDKUnhook since you're removing it.
    This?
    Code:
    #pragma semicolon 1
    #pragma newdecls required
    #include <sourcemod>
    #include <sdkhooks>
    #include <sdktools>
    
    public Plugin myinfo =
    {
        name = "Upgrade Packs with Ammo (Once Time)",
        author = "bullet28, NoroHime",
        description = "Creates ammo pile at the place where the upgrade pack was deployed",
        version = "1",
        url = "https://forums.alliedmods.net/showthread.php?p=2691806"
    }
    
    #define MODEL_AMMO "models/props_unique/spawn_apartment/coffeeammo.mdl" // another model variants: "models/props/terror/ammo_stack.mdl" "models/props/de_prodigy/ammo_can_02.mdl"
    
    public void OnMapStart()
    {
        if (!IsModelPrecached(MODEL_AMMO))
        {
            PrecacheModel(MODEL_AMMO);
        }
    }
    
    public void OnEntityCreated(int entity, const char[] classname)
    {
        if (strcmp(classname, "upgrade_ammo_") != -1)
        {
            SDKHook(entity, SDKHook_SpawnPost, OnPostUpgradeSpawn);
        }
    }
    
    public void OnPostUpgradeSpawn(int entity)
    {
        if (IsValidEntity(entity))
        {
            int ammoStack = CreateEntityByName("weapon_ammo_spawn");
            if (ammoStack > 0)
            {
                float origin[3];
                GetEntPropVector(entity, Prop_Send, "m_vecOrigin", origin);
                
                origin[0] -= 10.0;
                origin[1] -= 10.0;
                TeleportEntity(entity, origin, NULL_VECTOR, NULL_VECTOR);
            
                origin[0] += 20.0;
                origin[1] += 20.0;
                TeleportEntity(ammoStack, origin, NULL_VECTOR, NULL_VECTOR);
            
                SetEntityModel(ammoStack, MODEL_AMMO);
                DispatchSpawn(ammoStack);
                SDKHook(ammoStack, SDKHook_UsePost, OnUsePost);
            }
        }
    }
    
    void OnUsePost(int entity, int activator, int caller, UseType type, float value)
    {
        RemoveEntity(entity);
    }

    Last edited by BloodyBlade; 05-09-2024 at 10:21.
    BloodyBlade is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


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


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