scripted unload ammo?

Discussion in 'Fallout General Modding' started by Nirran, Apr 22, 2018.

  1. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    is it possible?
     
  2. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    Here's a quick-n-dirty demo script of the "unload" key:
    Code:
    procedure start;
    #include ".\HEADERS\DEFINE.H"
    #include ".\HEADERS\COMMAND.H"
    #include ".\HEADERS\sfall.h"
    #include ".\HEADERS\define_extra.h"
    #include ".\HEADERS\dik.h"
    
    procedure start begin
       if game_loaded then begin
          register_hook(HOOK_KEYPRESS);
       end else begin
          variable
             event := get_sfall_arg,
             keyDX := get_sfall_arg,
             item, ammoPID, ammoCount, ammoPacks, ammoObj;
    
          if (event == 1) and (keyDX == DIK_V) then begin
             // get item object in active hand
             if (critter_inven_obj(dude_obj, INVEN_TYPE_RIGHT_HAND) > 0) then begin
                item := critter_inven_obj(dude_obj, INVEN_TYPE_RIGHT_HAND);
             end else if (critter_inven_obj(dude_obj, INVEN_TYPE_LEFT_HAND) > 0) then begin
                item := critter_inven_obj(dude_obj, INVEN_TYPE_LEFT_HAND);
             end
    
             if (obj_item_subtype(item) == item_type_weapon) then begin
                ammoPID := get_weapon_ammo_pid(item);
                ammoCount := get_weapon_ammo_count(item);
                if (ammoPID > 0) and (ammoCount > 0) then begin
                   ammoPacks := ammoCount / get_proto_data(ammoPID, PROTO_AM_PACK_SIZE);
                   if ammoPacks then begin
                      add_mult_objs_to_inven(dude_obj, create_object(ammoPID, 0, 0), ammoPacks);
                   end
                   ammoPacks := ammoCount % get_proto_data(ammoPID, PROTO_AM_PACK_SIZE);
                   if ammoPacks then begin
                      ammoObj := create_object(ammoPID, 0, 0);
                      set_weapon_ammo_count(ammoObj, ammoPacks);
                      add_obj_to_inven(dude_obj, ammoObj);
                   end
                   set_weapon_ammo_count(item, 0);
                   intface_redraw;
                   display_msg("You unloaded your weapon.");
                end
             end
          end
       end
    end
    Pressing V key will unload your wielding weapon.
     
  3. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    thnx!

    Nirran
     
  4. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    boo tried to loop through inven and unload,hangs forever,had to crash the vdd to cancel it

    edit : heh was looping while ahs item in inven,doh

    thnx for the help novarain

    nirran
     
    Last edited: Apr 23, 2018