Item weight and inventory stats - Wants to make item weigh less than 1 lbs.

Discussion in 'Fallout General Modding' started by Zorchar, Oct 11, 2020.

  1. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    Okay, you guys.. I need your help again.

    My current script is causing me issues.

    Code:
    procedure start begin
    
       variable orig_owner;
       variable the_item;
       variable num_removed_objects;
       variable reason_removed;
       variable dest_obj;
       // variable item_extra_weight;
       variable extra_weight_ground_obj;
       variable amount_to_destroy;
       variable stimpaks_amount_before;
       variable stimpaks_amount_after;
       variable stimpaks_weight;
       variable i;
    
    
       if (game_loaded)  then begin
              register_hook(HOOK_REMOVEINVENOBJ);
       end
    
       else begin
          orig_owner := get_sfall_arg;
          the_item := get_sfall_arg;
          num_removed_objects := get_sfall_arg;
        //  reason_removed := get_sfall_arg;
      //    dest_obj := get_sfall_arg;
       //checks how many stimpaks in dude's inver originally
          stimpaks_amount_before:= obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK);
       //checks how many extra_weight items are in dude's inven
          amount_to_destroy:= obj_is_carrying_obj_pid(dude_obj, PID_EXTRA_WEIGHT);
       //when moving from dude's inven
            if orig_owner == dude_obj then begin
               //if has extra weight
               if amount_to_destroy > 0 then begin
                  // remove all extra weight items
                  restock_amt :=   rm_mult_objs_from_inven(dude_obj, obj_carrying_pid_obj(dude_obj, PID_EXTRA_WEIGHT), amount_to_destroy);
               end
               //checks how much total amount after transfer
               stimpaks_amount_after := (stimpaks_amount_before - num_removed_objects);
               //checks to see if stimpaks_amount_after divides by 4 (currently not enabled "4")
               display_msg("stim amount before" + obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK));
               display_msg("stim amount after" + stimpaks_amount_after);
               //checks total stimpak weight after transfer
               stimpaks_weight := (stimpaks_amount_after);
               //adds extra weight items according to stimpaks weight
               give_pid_qty(dude_obj, PID_EXTRA_WEIGHT, stimpaks_weight)
            end
         restock_amt := 0;
         restock_obj := 0;
         extra_weight_ground_obj:= 0;
         amount_to_destroy:= 0;
         stimpaks_amount_before:= 0;
         stimpaks_amount_after:= 0;
         stimpaks_weight:= 0;
       end
    end
    
    
    Don't laugh at the code:). I've been messing around with it a lot.

    I'm experimenting with HOOK_REMOVEINVENOBJ for an entire day now. It seems it fires up more times then it should. I will explain:

    At first, I thought the script goes crazy because it can't handle "/", "%","*" when calculating integers, but this was strange to me, since I have a few different scripts which, as far as I know, are working fine. So, I got rid of these functions, and just used this simple script.

    Now, look at the results: This is the first stimpak move. Working as intended. (sorry, cant figure out how to upload straight to here)
    https://ibb.co/DWDHyDc

    The second time I transfered one stimpak, this happened:
    https://ibb.co/gDLm5LN
    https://ibb.co/hYVfNYD

    Its running 7 times, until it finally (8th try) reaches the desired "stim amount after34". From there on, 8 tries each time.

    Now, again, I'm not sure if this is actually a problem or it's just me, but this seems to mess up the function's other calculations, and the variables become weird. Like negative and stuff. So when I try to use "/" or "%" to find the amount of weight I should add, the items and variables goes crazy.

    So, please help me out. Did I break the script somehow?
     
    Last edited: Oct 17, 2020
  2. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    About "ceil", "round", "floor" - Do they even work?

    I tried these simple lines:
    Code:
    display_msg("number" + ceil(4 / 5));
    display_msg("number" + round(4 / 5));
    display_msg("number" + floor(4 / 5));
    
    All displayed "number0".
     
  3. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    ceil(4 / 5.0)
     
    • [Rad] [Rad] x 1
  4. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    Cool.
    So how would I do it if these are two variables?
    Code:
    display_msg("number" + ceil(a / b));
    
     
  5. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    I don't really understand how you want to make items weighing less than one. adding special invisible items is a bad idea and not viable for the engine. the only scripted option is to subtract values from the player's maximum weight, and this is also a slightly bad implementation.
     
  6. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    My intention is to add "real" items, that weigh 1 lbs., to the dude's inventory. The number of added items will depend on the number of stimpaks you have in your inventory. So if you have 1 stimpak, it will add 1 "real" item to your inventory, and it will weigh 1 lbs..
    If you get one more stimpak, no item will be added.
    If you add 3 more, so you have 5 stimpaks, another "real" item will be added, and you now have 2 lbs. in your inventory.

    That's okay. It isn't a must for me. It would just be a little bit more comfortable. But really this is totally negligible and not important.
     
  7. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    Try adding "0.0" to one of them before doing the division.
     
    • [Rad] [Rad] x 1
  8. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    your error in rm_mult_objs_from_inven
    when deleting objects, a nested hook run always occurs.
     
  9. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    enable debugging messages to see your errors. now you are like a blind mole do not know anything that surrounds you.
     
  10. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    So what does it mean? I can't use this function? should I have done something different?
    BTW, I tried using destroy_mult_objs, but I can't get it to work (expecting";" error).
    Also, I tried using loops to use the regular remove action, but I don't know how to run a simple loop. So what should I do?.

    I will find out now how to do this. Thanks.
     
  11. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    For now, only thing I get is this spam massage:
    https://ibb.co/Pc7TdLW
     
  12. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    during deletion, you should not process the nested hook.
    something like
    Code:
    stop_hook = true;
    rm_mult_objs_from_inven
    stop_hook = false;
    read about recursive methods in programming.
     
    • [Rad] [Rad] x 1
  13. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    I tried scripting a loop, but it's not working.

    Code:
    procedure delete_extra_weights(variable weight_amount) begin
       if (weight_amount<1) then begin
         return;
       end
    
        while(weight_amount!= 0) do begin
           if obj_carrying_pid_obj(dude_obj, PID_EXTRA_WEIGHT) >0  then begin
           move_to(obj_carrying_pid_obj(dude_obj, PID_EXTRA_WEIGHT),0,0);
            weight_amount:=weight_amount-1;
           end
        end
    end
    procedure start begin
    
       variable orig_owner;
       variable the_item;
       variable num_removed_objects;
       variable reason_removed;
       variable dest_obj;
       // variable item_extra_weight;
       variable extra_weight_ground_obj;
       variable amount_to_destroy;
       variable stimpaks_amount_before;
       variable stimpaks_amount_after;
       variable stimpaks_weight;
       variable i;
    
    
       if (game_loaded)  then begin
              register_hook(HOOK_REMOVEINVENOBJ);
       end
    
       else begin
          orig_owner := get_sfall_arg;
          the_item := get_sfall_arg;
          num_removed_objects := get_sfall_arg;
        //  reason_removed := get_sfall_arg;
      //    dest_obj := get_sfall_arg;
       //checks how many stimpaks in dude's inver originally
          stimpaks_amount_before:= obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK);
       //checks how many extra_weight items are in dude's inven
          amount_to_destroy:= obj_is_carrying_obj_pid(dude_obj, PID_EXTRA_WEIGHT);
       //when moving from dude's inven
            if orig_owner == dude_obj then begin
               //if has extra weight
               if amount_to_destroy > 0 then begin
                  // remove all extra weight
                  call delete_extra_weights(amount_to_destroy);
    
               end
               //checks how much total amount after transfer
               stimpaks_amount_after := (stimpaks_amount_before - num_removed_objects);
               //checks to see if stimpaks_amount_after divides by 4
               display_msg("stim amount before" + obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK));
               display_msg("stim amount after" + stimpaks_amount_after);
               //checks total stimpak weight after transfer
               stimpaks_weight := (stimpaks_amount_after);
               //adds extra weight items according to stimpaks weight
               give_pid_qty(dude_obj, PID_EXTRA_WEIGHT, stimpaks_weight)
            end
         restock_amt := 0;
         restock_obj := 0;
         extra_weight_ground_obj:= 0;
         amount_to_destroy:= 0;
         stimpaks_amount_before:= 0;
         stimpaks_amount_after:= 0;
         stimpaks_weight:= 0;
       end
    end
    
    
    So I guess something wrong in the syntax. It doesn't move any item.
    If I change to "destroy_object(obj_carrying_pid_obj(dude_obj, PID_EXTRA_WEIGHT)" it crashes for me.


    Also, I didn't get this one. Is there an explanation for noobs?
     
    Last edited: Oct 17, 2020
  14. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    move_to does not move items from/to inventory.
     
  15. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    Update. I got the loop to work(with destroy_object), I think. The game got stuck, so I guess the loop is working and my function is buggy.
    The debug screen says: "[sfall] the hook id 9 could not be executed"
     
  16. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    if (game_loaded) then begin
    register_hook(HOOK_REMOVEINVENOBJ);
    end

    else begin
    if (stop_hook) return;
    orig_owner := get_sfall_arg;
    the_item := get_sfall_arg;
    num_removed_objects := get_sfall_arg;
    //reason_removed := get_sfall_arg;
    //dest_obj := get_sfall_arg;
    ....
    stop_hook = true;
    rm_mult_objs_from_inven
    stop_hook = false;

    ...
    end
    end
     
  17. Zorchar

    Zorchar Still Mildly Glowing

    236
    Jun 18, 2018
    Code:
    procedure start begin
    
       variable orig_owner;
       variable the_item;
       variable num_removed_objects;
       variable reason_removed;
       variable dest_obj;
       // variable item_extra_weight;
       variable extra_weight_ground_obj;
       variable amount_to_destroy;
       variable stimpaks_amount_before;
       variable stimpaks_amount_after;
       variable stimpaks_weight;
       variable i;
       variable stop_hook;
    
    
       if (game_loaded)  then begin
              register_hook(HOOK_REMOVEINVENOBJ);
       end
    
       else begin
        if (stop_hook) then return;
    
          orig_owner := get_sfall_arg;
          the_item := get_sfall_arg;
          num_removed_objects := get_sfall_arg;
       //checks how many stimpaks in dude's inver originally
          stimpaks_amount_before:= obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK);
       //checks how many extra_weight items are in dude's inven
          amount_to_destroy:= obj_is_carrying_obj_pid(dude_obj, PID_EXTRA_WEIGHT);
       //when moving from dude's inven
            if orig_owner == dude_obj then begin
               //if has extra weight
               if amount_to_destroy > 0 then begin
                  // remove all extra weight remove_pid_qty(who_obj, the_pid, pid_qty)
               stop_hook = true;
               restock_amt :=   rm_mult_objs_from_inven(dude_obj, obj_carrying_pid_obj(dude_obj, PID_EXTRA_WEIGHT), amount_to_destroy);
               stop_hook = false;
               end
               //checks how much total amount after transfer
               stimpaks_amount_after := (stimpaks_amount_before - num_removed_objects);
               //checks to see if stimpaks_amount_after divides by 4
               display_msg("stim amount before" + obj_is_carrying_obj_pid(dude_obj, PID_STIMPAK));
               display_msg("stim amount after" + stimpaks_amount_after);
               //checks total stimpak weight after transfer
               stimpaks_weight := (stimpaks_amount_after);
               //adds extra weight items according to stimpaks weight
               give_pid_qty(dude_obj, PID_EXTRA_WEIGHT, stimpaks_weight)
            end
         restock_amt := 0;
         restock_obj := 0;
         extra_weight_ground_obj:= 0;
         amount_to_destroy:= 0;
         stimpaks_amount_before:= 0;
         stimpaks_amount_after:= 0;
         stimpaks_weight:= 0;
       end
    end
    
    
    Did I do it right? Still no change from without the stop_hook.
     
  18. Cyrus

    Cyrus It Wandered In From the Wastes

    121
    Nov 5, 2015
    var = 5 / 2
    display var will show 2

    var = 5 / 2.0
    display var will show 2.500000

    5 / 2 * 1.0

    display var will show 2.500000

    replacing any number with a var is the same thing. This way you can ensure float operations.



    I don't think you can control how many times a hook gets triggered, but you can control how many times it should go through the whole function. You can create a condition check at beginning that distinguishes when its necessary for the procedure to get fully executed and when not.

    Do discover how often a hook or function is getting called add a simple display message at the beginning of the procedure. if you want you can also create a counter that adds 1 to var everytime hook runs and then displays var.

    Also don't use onscreen debug. As you can see its useless. To use debug use the debug.log. Display to in-game message area is ok too for testing if you want instant feedback.
     
  19. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    Code:
    variable stop_hook;
    the variable must be taken out the start procedure, i.e. make variable statistical.
     
  20. Mr.Stalin

    Mr.Stalin Agent of Enclave Modder

    384
    Oct 29, 2015
    It is useless to use it on the Restoration Project. noobsmoders did not use it there, and left a lot of problems in the game.