1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Other Universal Ammo Script

Discussion in 'Development' started by NoahtheBoah36™, Nov 30, 2017.

  1. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    So, I made this specifically because I was having trouble with getting some custom weapon scripts to work and load ammo that was made using the ammo_base, or just the pre-made HL2 ammo, so I figured I'd share it in case some other poor sap comes across the same problem as me. It's really simple: I kind of re-invented the wheel and removed the potential for getting cockblocked by not having a proper weapon equipped.

    Code:
    -- Created by NoahtheBoah36 AKA Noah Engelmann
    -- Rights to redistribute/reuse/modify are granted, provided credit is given.
    
    local ITEM = Clockwork.item:New();
    ITEM.name = "Ammo Box";
    ITEM.model = "models/clutter/ammobox.mdl";
    ITEM.weight = 0.5;
    ITEM.useText = "Open";
    ITEM.category = "Ammo";
    ITEM.business = true;
    ITEM.access = "B";
    ITEM.description = "A box filled with lots of ammo of various kinds.";
    
    -- Dropping the item.
    function ITEM:OnDrop(player, position) end;
    
    -- Using the item.
    function ITEM:OnUse(player, itemEntity)
        player:GiveAmmo(100, "ar2");
        player:GiveAmmo(100, "smg1");
        player:GiveAmmo(100, "pistol");
        player:GiveAmmo(100, "buckshot");
        player:GiveAmmo(100, "357");
        player:GiveAmmo(100, "xbowbolt");
        player:GiveAmmo(100, "rpg_round");
        player:GiveAmmo(100, "smg1_grenade");
        player:GiveAmmo(100, "ar2altfire");
    end;
    
    ITEM:Register();
    
    As the comments say, feel free to use this if you're having trouble implementing custom weapons onto your server that use some specific kind of ammo, and feel free to edit it to your preferences by removing ammo types or adding ammo types from other things. The current state of it, however, has all default hl2 ammo types included, with the exception of "grenade" and "slam" ammo, since such things aren't really ammo so I didn't think of including it.

    P.S. That model is part of a special model pack as I'm using this for something specific, so make sure you change the model path to something else!
     
    • Like Like x 1
  2. Aberidius

    Aberidius Chief Technology Officer Staff Member Administrator Store Support

    Hate to be a buzzkill, I'm glad you had your issue sorted but for a starter
    Code:
    -- Created by NoahtheBoah36 AKA Noah Engelmann
    -- Rights to redistribute/reuse/modify are granted, provided credit is given.
    I mean, you've only made it give x100 of each ammo type, not written a whole plugin that is built around that sort of thing. It looks off putting, imo.
     
    • Agree Agree x 2
    • Disagree Disagree x 1
  3. Zig

    Zig Guest

    I don't even know why you care as if you're going to use NoahtheBoah (copywrited) plugins
     
    • Funny Funny x 3
  4. RJ

    RJ no pay Legend Clockwork Customer

    Licensing code is standard practice as a programmer (no matter how small or large). Frankly, it'd be more off putting for a developer if that wasn't included because "all rights reserved" is assumed if no license is given, i.e. no one is allowed to use the code unless given explicit permission by the creator.
     
    • Disagree Disagree x 2
    • Agree Agree x 1
  5. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    I always put that in as a standard practice on every piece of code I write, for the reasons RJ mentioned. It's just standard practice. Hell, I've yet to do anything impressive with Clockwork, at all. I do it nevertheless because it's a good practice.
     
    • Disagree Disagree x 1
    • Funny Funny x 1

Previous Readers (Total: 0)