Adding to the weapon menu
#1
What part of 'Menu_settings' do i need to change to add a custom weapon to the weapons list?

So far I have the menu to list my weapon but wont load menu skin (The spinning display animation) or the weapon itself.

const isprimary [ return (|| (|| (|| (= $arg1 $SNIPER) (= $arg1 $SHOTGUN)) (|| (= $arg1 $AR) (= $arg1 $SMG))) (= $arg1 $CARBINE)) ]

const getcustomprimarydirs [
  customprimarydirs = []
  loop gcp $NUM_WEAPONS [
    if (! (isprimary $gcp)) [ add2list customprimarydirs (addpunct [ ]) ] [
      add2list customprimarydirs (at $ALTERNATIVE_WEAPONS (+ (* $gcp 3) 2))
    ]
  ]
  return $customprimarydirs
]

const loadcustomprimary [
  nargs = $numargs
  if (> $nargs 0) [
    li = $arg1
    if (isprimary $li) [
      tmp = (getalias (at $WEAPONS $li))
      customphud = (format modmdlweap%1 $tmp)
      custompwld = (format modmdlvwep%1 $tmp)
      if (> $nargs 1) [ // revert to default primary HUD model if any 2nd argument is given
        delalias $customphud; delalias $custompwld
      ] [ // else try loading the custom primary models
        cdirlist = (getcustomprimarydirs)
        if (listlen $cdirlist) [
          dirtotry = (at $cdirlist $li)
          if (strlen $dirtotry) [
            $customphud = $dirtotry
            $custompwld = $dirtotry
          ]
        ]
      ]
    ]
  ]
]

const DEFAULT_PRIMARIES ["MTP-57 Assault Rifle" "A-ARD/10 Submachine Gun" "Precision Tech AD-81 Sniper Rifle" "V-19 Combat Shotgun" "TMP-M&A Carbine" "MG-5 Snipe Rifle"]
const DEFAULT_PRALIASES [AR SMG SNIPER SHOTGUN CARBINE MG-5]
const DEFAULT_PRMDLDIRS [assault subgun sniper shotgun carbine MG-5]

const CUSTOM_PRIMARIES ["AR-15 Assault Rifle" "Mac11 Submachine Gun" "Dragunov SVD Sniper Rifle" "Sawed-off Shotgun" "Marlin Guide Carbine 1895"]
const CUSTOM_PRMDLDIRS [assault2 subgun2 sniper2 shotgun2 carbine2 MG-52]

newmenu Weapons

@@@@@menumdl weapons/MG-5/menu mapmodel 75 12@@@@@
menumdl weapons/assault/menu mapmodel 75 12
loop gwm (listlen $DEFAULT_PRIMARIES) [
  execute (format [menuitem [%1] [ nextprimary (getalias %2); loadcustomprimary (getalias %2) 0; echo %1 selected ] [ chmenumdl Weapons weapons/%3/menu mapmodel 75 12 ]] (at $DEFAULT_PRIMARIES $gwm) (at $DEFAULT_PRALIASES $gwm) (at $DEFAULT_PRMDLDIRS $gwm))
]

// menuitem [] -1
// menuitem [Alternative weapons...] [ showmenu [Alternative Weapons] ]

// newmenu [Alternative Weapons]

// menumdl weapons/assault2/menu mapmodel 75 12
// loop cwm (listlen $CUSTOM_PRIMARIES) [
//   execute (format [menuitem [%1] [ nextprimary (getalias %2); loadcustomprimary (getalias %2); echo %1 selected ] [ chmenumdl [Alternative Weapons] weapons/%3/menu mapmodel 75 12 ]] (at $CUSTOM_PRIMARIES $cwm) (at $DEFAULT_PRALIASES $cwm) (at $CUSTOM_PRMDLDIRS $cwm))
// ]
// menuitem [] -1
// menuitem [Other alternative weapons...] [ showmenu [Alternative Weapon Models] ]
EDIT: So the text you see inbetween the "@" symbols have displayed the "spinning weapon" animation when selecting the weapon, but when actually selected does not change the weapon. Although the console quotes "nextprimary= (Random number) Then "MG-5 Sniper Rifle Selected"

The weapon is just a reskin of the snipe but i'd like to add it to the list as a seperate weapon.. Can this be done?
Thanks given by:
#2
You know, this kinda reminds me about the time I asked V-Man about modding the game to have seperate weapons for CLA and RVSF. I like this concept Myke. Though if I'm not mistaken there's a very old script in akimbo's archives that allowed you to do something similar to this. You'd have your skin_weapon.jpg and skin_weaponx.jpg (or something like that). You'd execute a command to switch them in game.

If I get the chance I'll see if I have it lying around somewhere.



I just found it, though idk if it is compatable with 1.2 ... give it a shot! Everything in the code section is a read-me provided by V-Man.

SkinSwitcher by V-Man

This setup will allow you to switch weapon skins (.jpg) in-game via menu. Unfortunately, swapping 3d models does not work unless you quit the game first, which ruins the point of crafting CubeScript for it.
Another shortcoming to this is that it only supports one alternate skin per weapon. If this monstrosity becomes popular, I'll look into extending it.
After the instructions for use, I'll talk about the nerdy details of what this setup does.

To enable SkinSwitch:

1 - Place "skinswitch.bat" and "sleep.exe" in your main AssaultCube folder. It should be the same folder that contains "assaultcube.bat" and the folders "config" and "packages".

2 - Save each alternate skin as "skin_weaponx.jpg" and place it in the same folder as the skin you will replace in-game.

3 - Place skinswitch_menu.cfg in your "config" folder.

4 - Add the following line to your "autoexec.cfg" folder:

    exec config\skinswitch_menu.cfg


5 - If you want, you can keybind "skinwitch" to a particular key, or use it in a script to access the menu. If you want to switch skins without using the menu, reading the menu itself should give you a clue about how to do that.


To use SkinSwitch:

1 - Run "skinswitch.bat". Allow it to run in the background.

2 - In AssaultCube, type "skinswitch" (or activate the alias through a keybind).

3 - Select the weapon you have an alternate skin for. Voila!

"assault" contains a file named "skin_weaponx.jpg" as an example of a replacer-skin. It should go in the "packages\models\weapons\assault" folder if you do not already have an assault rifle alternate skin.

WARNING: Nerdy explanations ahead.

Thanks to DES|GeneralDisarray for showing me the "sleep.exe" file. This causes the batch file to use fewer system resources. "sleep.exe" is used in the batch file to pause for a second while assessing the files it is searching.

"skinswitch.bat" looks in the "packages\maps" folder for a map named one of four keywords: "switchout_AR.cgz", "switchout_SMG.cgz", "switchout_SR.cgz", or "switchout_SG.cgz". If any of those exist, it performs actions in the folder correspinding to the map name.
It goes to the designated weapon folder and checks if there is a file there called "skin_weaponx.jpg". If there is, it swaps its name with "skin_weapon.jpg". Then it deletes the indicator map file and goes back to monitoring the maps folder.

"skinswitch_menu.cfg" creates a new menu. It then gives four options, one for each weapon, to swap out the skin in question. I've added "menumdl" and "chmenumdl" as nifty whirligigs, but they don't actually portray the skin in question.
When a weapon is selected, the menu executes a "savemap" command, calling the current map "switchout_" followed by a code representing the weapon in question. It then executes the "resetgl" command, reloading all textures and skins.
The cfg file then defines alias "skinswitch" to open the menu and remind you of the most important parts of this setup.

If the "resetgl" part of this takes less than 1 second for you, you may experience a lack of skin-change. Simply enter "resetgl" yourself and it should be fine.

Download Skin Switcher by V-Man
Thanks given by:
#3
Thats pretty cool.
Could that also allow for a "Knife-gets-blood-on-it-after-slashing-somebody" kind of mod? Anyway, thats a whole different thread.

I was sort of wanting to just ADD it as another weapon not replace the skins.. :/
Thanks given by:
#4
(29 May 14, 09:29PM)MykeGregory Wrote: Thats pretty cool.
Could that also allow for a "Knife-gets-blood-on-it-after-slashing-somebody" kind of mod? Anyway, thats a whole different thread.

I was sort of wanting to just ADD it as another weapon not replace the skins.. :/

I know but you might be able to modify it for your needs. But that's just a thought.
Thanks given by:
#5
Bump?
Thanks given by:
#6
iirc someone already came up with a sort of 'Armory Menu' that was posted on the Ol' AKIMBO wasn't it? not too sure if it's still compatible with v1.2 tho
Thanks given by:
#7
Do you mean this? http://forum.cubers.net/thread-4207.html...ght=armory

I would have thought there was just an extra line of code to add or edit to get this to work..
Thanks given by: