Skip to content

Creating a Weapon

ShadowMario edited this page Dec 28, 2024 · 13 revisions

This page is a WIP, it's not complete

Requirements

For the model:


Understanding how the weapon model works

There is no model, that's right, you've been fooled all this time, it's just a bunch of sprites stacked on top of each other!

For example, if you open oChunksArm, you will see that there's only around 10 sprites inside it.

image

But if you stack and tilt them, you will see that it looks vaguely similar to how it looks ingame

chunky Screenshot_1

The game loads the sprites and turn them into cubes, then stack them on top of each other, they're not loaded as an actual 3D model, but get turned into one in-game!

Thankfully, you won't need to know much about what I just told you, I just thought it would be cool to explain it, with MagicaVoxel, Vox2Png and my Script, it will do all of the model import job for you!


Importing the Model

Save your MagicaVoxel model project on the same folder as Vox2Png
image

Once saved, you have to keep in mind these numbers up there, as we're gonna use them!
image

Then open a terminal/command prompt inside vox2png folder and run ./vox2png input.vox output.png

Assuming you installed my Scripts, open Scripts > Dead Estate Scripts > Weapon Scripts > PNGtoWeaponSprites.csx and select your output.png file.

image

On the first window opened, set it to the numbers I told you to keep in mind.

After that give you have to insert a Name for the Custom Weapon's Sprite and Game Object, consecutively, and voi-la!! Half-way done.


Creating the Game Object

image

  1. (Optional) The Parent box is the base weapon for your custom weapon, by default it uses gun, which is a generic handgun with no special attributes. If for example, you want to use a sword as base, search for sword and drag & drop it into the Parent box of your custom weapon.
  2. You will most likely want to create atleast PreCreate and Create Codes for your weapon:
    image
    After that implement the Codes to your Game Object by drag-and-dropping:
    image
  3. Open code gml_GlobalScript_scrWeapons and add your weapon to the list, check this page to understand how to use createWeapon, and unless you want to replace an existing weapon, make your custom weapon use 150 or more on value number (1st argument).

I highly suggest you to copy-and-paste code from other weapons and THEN edit it.


In-Game Testing

The easiest way I could find to test a Weapon so far, is to simply change Jules' default weapon with all curses disabled.

Open Code gml_Object_jules_PreCreate_0, and add defaultGun = <your weapon object name here>; at the end of the code.

image

This is how my model looks in-game by the way!

image


FAQ

Q: "My Weapon is weirdly offset!"

A: On your weapon's PreCreate code, add offsetFromPlayer = <number here>;, this will allow you to make the weapon stay closer/farther from your character.

Clone this wiki locally