New weapon code trouble

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

New weapon code trouble

Post by Sergeant Hoppy »

I'm new to modding Doom, only mod I ever made was a skin. Anyway, I am having a hard time with coding a new weapon, I get an error message when loading the mod saying:
Tried to register class 'FlameThrower' more than once.

Execution could not continue.

Script error, "Flamethrower.pk3:decorate.txt" line 8:
Unexpected ',' in definition of 'FlameThrower'



This is my DECORATE:

Code: Select all

//*** Created with EZDec ***//
//***     aurasite.net   ***//
ACTOR Flamethrower : Weapon
{
	Weapon.AmmoType "Cell"
	Weapon.AmmoGive 50
	Weapon.AmmoUse 10
	Weapon.SlotNumber 5, RocketLauncher, Flamethrower
	AttackSound "weapons/pistol"
	States
	{
		Ready:
		HSKL A 1 A_WeaponReady
		Loop
		Select:
		HSKL A 1 A_Raise
		Loop
		Deselect:
		HSKL A 1 A_Lower
		Loop
		Spawn:
		SKLL A  1
		Loop
		Fire:
		MISG B 3 A_FireCustomMissile("FatShot", 0.0, true, 0.0, -2.0, 0, 0.0)
		Goto Ready
	}
}
Here is the pk3 if anyone is interested in looking at my horrible atempt:
Flamethrower.pk3
None-loading-custom-weapon
(50.96 KiB) Downloaded 16 times
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: New weapon code trouble

Post by Graf Zahl »

There's two errors as pointed out by the console output:

Error 1: A class named 'Flamethrower' already exists. Rename your weapon.
Error 2: Weapon.SlotNumber only takes a single argument - you specified 3.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: New weapon code trouble

Post by Sergeant Hoppy »

Ahhh, thank you, that was very helpful! Now I don't get any error messages, but I can't seem to access the weapon, I use the cheatcode IDFA to get all weapons in order to test things quickly.

Any thoughts?

Code: Select all

ACTOR Burninator: Weapon
{
 Inventory.PickupMessage "You got the Burninator, Time for a barbeque!"
	Weapon.Slotnumber 5
	Weapon.AmmoType "Cell"
	Weapon.AmmoGive 50
	Weapon.AmmoUse 10
	AttackSound "weapons/pistol"
	States
	{
		Ready:
		HSKL A 1 A_WeaponReady
		Loop
		Select:
		HSKL A 1 A_Raise
		Loop
		Deselect:
		HSKL A 1 A_Lower
		Loop
		Spawn:
		SKLL A -1
		Stop
		Fire:
		HSKL A 3 A_FireCustomMissile("FatShot", 0.0, true, 0.0, -2.0, 0, 0.0)
		Goto Ready
	}
}
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: New weapon code trouble

Post by Jarewill »

Check if your sprites are correct.
A weapon won't be selected (or given even) if it lacks ready sprites.

Check if the sprites are either in the sprites folder in a .pk3 format or between S_START and S_END markers in a .wad format.
Also check if they filenames are alright.

You can also temporarily switch all sprites in the weapon to existing ones (SHTG for example) to check if it gets selected then.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: New weapon code trouble

Post by Sergeant Hoppy »

Oh wow, so that was what I was doing wrong! I did not have the sprites in a sprite folder! Now it works great!

Thank you so much for your patience, you're a modsaver!
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: New weapon code trouble

Post by Sergeant Hoppy »

Okay, It's working properly now, did some testing and I'm quite happy with it, now I have an additional question: How do I go about having it spawn ingame? Do I give it a unique spawn ID or do I pick a spawn ID already used by an existing weapon, or can I do a 50/50% chance of spawning the new weapon instead of another weapon?
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: New weapon code trouble

Post by Jarewill »

You can give it a unique editor number and place it on the map manually.
In DECORATE, the editor number is defined in the actor's definition like so:

Code: Select all

ACTOR Burninator: Weapon 11001 //This is the number  
If you want to make it randomized, you can use a RandomSpawner to do so:

Code: Select all

Actor LauncherReplacer : RandomSpawner 2003 //2003 is the editor number of the rocket launcher, as to not replace it completely
{
    DropItem "RocketLauncher"
    DropItem "Burninator"
}
If you use the "replaces" keyword, the weapon itself will be replaced and you will have to redefine it.
Just replacing it's editor number helps with that.
Guest

Re: New weapon code trouble

Post by Guest »

Thank you, I am learning a lot! And i've begun to learn what to search for on zdoom wiki now too! Thank you for the help!
Guest

Re: New weapon code trouble

Post by Guest »

I tried expanding my mod by including 1 more new weapon, figured what I learned would suffice, I was wrong, after floating around Zdoom wiki without figuring this thing out, I ask for help with this headscratcher:

I made a folder called Actors and put my weapons in there in the form of .txt's called Burninator.txt and Pipe_Bomb.txt, they include the ACTOR information for the weapons.

In the root I have the DECORATE.txt with some includes:
#include "Actors/Burninator.txt"
#include "Actors/Pipe_Bomb.txt"



When loading the pk3 I get an error saying:
Could not find script lump 'Actors/Burninator.txt'

I can't figure out how the structure for #include should be.
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: New weapon code trouble

Post by Jarewill »

Could you post your file?
Not sure what could be the issue here and seeing the file itself might help.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: New weapon code trouble

Post by Sergeant Hoppy »

Sure:
Multi_Weapons.pk3
(82.09 KiB) Downloaded 20 times
Jarewill
 
 
Posts: 1855
Joined: Sun Jul 21, 2019 8:54 am

Re: New weapon code trouble

Post by Jarewill »

The problem is that you are #including files named "Burninator.txt" and "Pipe_Bomb.txt"
Meanwhile your file names lack the extensions and are just named "Burninator" and "Pipe_Bomb"

Either add the extension to the filenames or change the #includes to not have them.
Sergeant Hoppy
Posts: 42
Joined: Mon Jun 21, 2021 11:24 am

Re: New weapon code trouble

Post by Sergeant Hoppy »

Ahhh, I thought I had to include .txt at all times, now I know, thank you! Now it works as intended.
Post Reply

Return to “Scripting”