How do I add a new item to a merchant script? (Megamod)

Bulletti

First time out of the vault
So, I created two new ammo stacks, one caliber, and a weapon for them. Nirran helped me earlier, but megamod's scripts for example SF gun merch, are 100% different and 500% more complex.

[spoiler:455d6546f5]procedure random_ammo_town_six
begin
random_ammo_six := op_random(1, 4);
if ((random_ammo_six == 1) and (ammo_twentyfour == 0)) then
begin
ammo_twentyfour := 1;
case := 358;
end
else if ((random_ammo_six == 2) and (ammo_twentyfive == 0)) then
begin
ammo_twentyfive := 1;
case := 359;
end
else if ((random_ammo_six == 3) and (ammo_twentysix == 0)) then
begin
ammo_twentysix := 1;
case := 382;
end
else if ((random_ammo_six == 4) and (ammo_twentyseven == 0)) then
begin
ammo_twentyseven := 1;
case := 578;
end
else
case := -1;
random_ammo_six := 0;
return(case);
end[/spoiler:455d6546f5]

Is as far as I got. case := 358; is 2mm EC ammo, and as I read the script, if the town level is high enough, it is guaranteed to have EC ammo, and the others as well.

Number 578 bothers me - it is something added by megamod (most likely the AM rifle round) and it is not in the header file (surprise, surprise) so I can't be sure what it is. Thus, I cannot backtrack and investigate how to add my own just by reading the scripts. finding similarities and cross-checking. Help!

EDIT: Script here is FIGUNTB.int decompiled using FSE v1.5a into an SSL file.
 
this is the function that actualy adds the items in any mod i wrote

Code:
procedure restock_items(variable item_pid, variable min, variable max, variable pecent) begin
   restock_amt := random(min, max);
   if (obj_is_carrying_obj_pid(self_obj, item_pid) <restock_amt>= random(1, 100)) then 
            begin
               if (obj_is_carrying_obj_pid(self_obj, item_pid) <restock_amt> restock_amt) then 
                        begin
                           removed_qty := obj_is_carrying_obj_pid(self_obj, item_pid);
                           if ((obj_is_carrying_obj_pid(self_obj, item_pid) - restock_amt) <removed_qty> 0) then 
                              begin
                                 restock_obj := obj_carrying_pid_obj(self_obj, item_pid);
                                 if (obj_type(self_obj) == 1) then 
                                    begin
                                       restock_obj := obj_carrying_pid_obj(self_obj, item_pid);
                                       if (critter_inven_obj(self_obj, 0) == restock_obj) then 
                                          begin
                                             if (obj_item_subtype(critter_inven_obj(self_obj, 0)) == 0) then 
                                                begin
                                                   restock_obj := critter_inven_obj(self_obj, 0);
                                                   debug_msg("armour pid == " + obj_pid(restock_obj));
                                                   rm_obj_from_inven(self_obj, restock_obj);
                                                   add_obj_to_inven(self_obj, restock_obj);
                                                end
                                          end
                                       else 
                                          begin
                                             if ((critter_inven_obj(self_obj, 2) == restock_obj) or (critter_inven_obj(self_obj, 1) == restock_obj)) then 
                                                begin
                                                   metarule(43, self_obj);
                                                end
                                          end
                                    end
                                 restock_amt := rm_mult_objs_from_inven(self_obj, restock_obj, removed_qty);
                                 destroy_object(restock_obj);
                              end
                           restock_obj := 0;
                           restock_amt := 0;
                        end
                     else 
                        begin
                           restock_obj := 0;
                        end
                  end
            end
      end
   else 
      begin
         if (obj_is_carrying_obj_pid(self_obj, item_pid) <restock_amt> restock_amt) then 
                  begin
                     removed_qty := obj_is_carrying_obj_pid(self_obj, item_pid);
                     if ((obj_is_carrying_obj_pid(self_obj, item_pid) - restock_amt) <removed_qty> 0) then 
                        begin
                           restock_obj := obj_carrying_pid_obj(self_obj, item_pid);
                           if (obj_type(self_obj) == 1) then 
                              begin
                                 restock_obj := obj_carrying_pid_obj(self_obj, item_pid);
                                 if (critter_inven_obj(self_obj, 0) == restock_obj) then 
                                    begin
                                       if (obj_item_subtype(critter_inven_obj(self_obj, 0)) == 0) then 
                                          begin
                                             restock_obj := critter_inven_obj(self_obj, 0);
                                             debug_msg("armour pid == " + obj_pid(restock_obj));
                                             rm_obj_from_inven(self_obj, restock_obj);
                                             add_obj_to_inven(self_obj, restock_obj);
                                          end
                                    end
                                 else 
                                    begin
                                       if ((critter_inven_obj(self_obj, 2) == restock_obj) or (critter_inven_obj(self_obj, 1) == restock_obj)) then 
                                          begin
                                             metarule(43, self_obj);
                                          end
                                    end
                              end
                           restock_amt := rm_mult_objs_from_inven(self_obj, restock_obj, removed_qty);
                           destroy_object(restock_obj);
                        end
                     restock_obj := 0;
                     restock_amt := 0;
                  end
               else 
                  begin
                     restock_obj := 0;
                  end
            end
      end
end

and no that ammo you referneced will not always be added if town level is high enough,those functions add randomness to what item is added,beyond what is already randomized

in a script i did not edit,look for the above code and

change item_pid to desired item(these variables will be numbers in a script i did not alter)

change min to minimum num of the item

change max to maximum number of the item

change percent to percent chance of the item appearing

in the case of adding additional items copy all the code in the above function and change what i mentioned above

Nirran
 
FML. Cannot get it to work; I tried what you suggested, Nirran.

The script is yours, the San Fran gun merchant, and has a very complex script compated to vanilla script.

Vanilla:
Check restock_item PID_ITEM_NAME (min, max, percent)

That I could understand a bit better -.-

I can't even decompile the file, not modify, and compile again. What software do you use?

TEMP.I(388): Error! Undefined symbol op_random
FSE info --> Compiler reports unknown command or character.
"Please check whenever you have mistyped function or procedure name or not declared all variables."
 
Bulletti said:
FML. Cannot get it to work; I tried what you suggested, Nirran.

The script is yours, the San Fran gun merchant, and has a very complex script compated to vanilla script.

Vanilla:
Check restock_item PID_ITEM_NAME (min, max, percent)

That I could understand a bit better -.-

I can't even decompile the file, not modify, and compile again. What software do you use?

TEMP.I(388): Error! Undefined symbol op_random
FSE info --> Compiler reports unknown command or character.
"Please check whenever you have mistyped function or procedure name or not declared all variables."

if anything has op_ in the script it was decompiled with ruby,and then you tried to compile it with regular compiler,download the decompiler from my site,then decompile bla bla,or use ruby 1.68 to compile the script(it is the only version of ruby that works with fo)

but yea,vanilla is the code wrapped in that procedure,it is what the macro check_restock_item puts into the script

edit : after downloading the decompiler rename it to decompile.exe and place it in the fse folder,then fse will use it to decompile scripts with the fse interface

Nirran
 
Back
Top