Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
STOOPMAN

Newbie to coding

Recommended Posts

For some time ive been thinking of making a mod for doom that adds various weapons, enemies, powerups, and even some weapon customization. But since I barely know anything of coding and the only way im coding now is by using a guide, I need some help with it. Im trying to make a mac 10 that can be reloaded, but I am not sure if Im doing it correctly. I may not respond immediatly (I may be doing something else) but any coding help is greatly appreciated (also heres the code I have so far)unknown.png

Share this post


Link to post

Ive also ran the wad a few time to see if ti worked and ironed out some errors, but Im having problems with line 45 saying Quote "Script error, "Mac10.wad:DECORATE" line 45: Expected '(', got 'MA10'

Share this post


Link to post

Taking a quick look: Because you don't close the MAC10FIRE state, the code doesn't know it's done with line 44.  It winds up jumping to some other state and reads the name of the frame that's being called.  You should end all your states with a Loop or a Goto (or Stop for stuff other than weapons), even if it won't get read while the script is running.

 

Another thing I notice is that your firing cycle uses "A_Fire", which shoots the gun again.  That means the first time you fire it it will shoot forever until you're out of ammo.  If you want to give it autofire, use A_ReFire - that will check to see if the player is still pressing the button, and restart the Fire state if they are, or go to Ready if they aren't. (It's the same command the vanilla Chaingun uses)

Once you've got a working gun, you start learning a lot by playing with values and seeing what happens, and that's, like, the very best part of modding.  Have fun dude!

Share this post


Link to post

Hey Burg, while I was waiting for a reply I was tweaking the code and managed to get it working, only problem is that when I switch to a different weapon, I can't switch back to the Mac 10, help is appericiated (also heres the tweaked code)
image.png.56b5dab7b55d77f59a64d7c8d9e1ca2a.png

Share this post


Link to post

You may be having some trouble with both replacing the chaingun and including the chaingun. That's my best guess anyhow.  Usually when I make weapons if I call "Replaces", I don't need to give it an actor number (your 20002) because it should be getting that from the thing it's replacing.

 

...that is, if you haven't fixed it already ;)  Hope this helps!

Share this post


Link to post

Yea I made the weapons seperate, still need help with fixing the weapon switching, because when I switch to a different weapon I cant switch back to the mac 10

Share this post


Link to post

Well, you could always try assigning the weapon slot on the weapon instead of the on the Garfield player...

 

I've taken a couple whacks at it now tho, so I might not be the guy with the answer.  All I can think of is to post a weapon of mine I know works:
(It's melee, not bullets, but all my weapons use projectiles, so this is probably closer to your weapon. I included some frames so you can get it working it you want)
 

Spoiler

ACTOR EvilWizPlayer : DoomPlayer
{

    Player.StartItem "DarkBlade"
    Player.WeaponSlot 1, "DarkBlade"
}

 

ACTOR DarkBlade : Weapon replaces "Chainsaw"
{
    Weapon.Kickback 300
    Inventory.PickupMessage "DAAAAAARK BLAAAAAADE"
    Weapon.AmmoType1 "Clip"
    Weapon.AmmoType2 "Clip"
    Weapon.AmmoUse1 0
    Weapon.AmmoUse2 0
    Weapon.SlotNumber 1
    +WEAPON.MELEEWEAPON
    +WEAPON.NOAUTOFIRE
    +WEAPON.AMMO_OPTIONAL
    
    States
    {
        Spawn:
        DBPU A -1
        Loop
        Ready:
        DBLD ABC 4 A_WeaponReady
        DBLD C 0 A_GiveInventory("clip",1)
        Loop
        Select:
        DBLD ABC 1 A_Raise
        Loop
        Deselect:
        DBLD ABC 1 A_Lower
        Loop
        Fire:
        DBLD B 3
        DBLD E 2 A_Recoil(-7)
        DBLD F 1 A_CustomPunch(20,TRUE,CPF_PULLIN,0,90,1,0,FALSE,"Punch1","Fwoosh")
        DBLD F 1 Offset(-30,0)
        DBLD F 1 Offset(-60,0)
        DBLD F 1 Offset(-90,0)
        DBLD G 1 Offset(-90,0)
        DBLD G 1 Offset(-120,0)
        DBLD G 2 Offset(-140,0)
        DBLD G 0 A_GiveInventory("clip",1)
        DBLD G 0 A_Refire("Backswing")
        Goto Ready
        Backswing:
        DBLD K 2 A_Recoil(-5)
        DBLD K 1 A_CustomPunch(20,TRUE,CPF_PULLIN,0,90,1,0,0,"Punch1","Fwoosh")
        DBLD K 1 Offset(30,0)
        DBLD K 1 Offset(60,0)
        DBLD L 1 Offset(90,0)
        DBLD L 1 Offset(90,0)
        DBLD M 1 Offset(120,0)
        DBLD M 1 Offset(140,0)
        DBLD M 2 Offset(140,0)
        DBLD M 0 A_GiveInventory("clip",1)
        DBLD M 0 A_Refire("AltFire")
        Goto Ready
        AltFire:
        DBLD A 4
        DBLD A 0 A_CustomPunch(20,TRUE,CPF_PULLIN,0,90,1,0,0,"Punch1","Fwoosh")
        DBLD A 1 A_SetSpeed(0)
        DBLD A 0 A_Recoil(-30)
        DBLD J 4
        DBLD J 0 A_CustomPunch(20,TRUE,CPF_PULLIN,0,90,1,0,0,"Punch1")
        DBLD J 4 Offset(-17,-5)
        DBLD J 0 A_CustomPunch(20,TRUE,CPF_PULLIN,0,90,1,0,0,"Punch1")
        DBLD J 0 A_SetSpeed(1)
        DBLD J 4 A_ChangeVelocity(0,0,0,CVF_REPLACE)
        DBLD J 0 A_CustomPunch(20,TRUE,CPF_PULLIN,0,92,1,0,0,"Punch2")
        DBLD J 3
        DBLD I 3
        Goto Ready
    }
}

 

DarkBlade.zip

Share this post


Link to post

I'm a bit unskilled at Decorate coding myself, so take my advice with a grain of salt.

So, the first thing we need to do is "flag" the weapons READY state as re-loadable. So, on the sprite underneath Ready: (The sprite is MA10 F 1, in this case.) you need to put (WRF_ALLOWRELOAD). This will make it where, upon the "reload" key being pressed, the weapon will go to the RELOAD state.

The next thing you'll have to do is make a RELOAD state. It's exactly the same thing as making a FIRE state, except instead of shooting, you reload. However, to actually make the game count magazines, you'll need to create a Custom Inventory item. I stole this from the ZDoom CustomInventory page, and adapted it to work for you:

actor Mac10Mag : CustomInventory
{
  Inventory.MaxAmount <Magazine Size in an integer>
}

It should be pretty self explanatory. Now, what you next need to do is create two frames in your FIRE state. One will use A_JumpIfInventory before you fire the bullets, so if it tries to fire and the magazine is "empty", it'll switch to reload. For your use, it would be A_JumpIfInventory("Mac10Mag", <Magazine Size>, "RELOAD"). This would make it jump to the RELOAD state when a certain amount of bullets are fired. The second frame will be after you fire the bullets, which would be A_GiveInventory("Mac10Mag", 1), which works as essentially ticking one spent round from your magazine.

Then, in your RELOAD state, have a frame use A_TakeInventory("Mac10Mag", <Mag Size>). This will "reload" the in-game counter for spent bullets.

Share this post


Link to post
9 hours ago, STOOPMAN said:

while I was waiting for a reply I was tweaking the code and managed to get it working, only problem is that when I switch to a different weapon, I can't switch back to the Mac 10

You're defining a new player class, did you actually tell the game to use that class? https://zdoom.org/wiki/Creating_new_player_classes

Share this post


Link to post
4 hours ago, boris said:

You're defining a new player class, did you actually tell the game to use that class? https://zdoom.org/wiki/Creating_new_player_classes

I did set a player class but apparently I missed an s in classes for my map info, once I added the s I could switch between weapons. now I just gotta figure out the reloading, which is what im doing now :p

(btw thanks for the help)

 

Share this post


Link to post
10 hours ago, act said:

I'm a bit unskilled at Decorate coding myself, so take my advice with a grain of salt.

So, the first thing we need to do is "flag" the weapons READY state as re-loadable. So, on the sprite underneath Ready: (The sprite is MA10 F 1, in this case.) you need to put (WRF_ALLOWRELOAD). This will make it where, upon the "reload" key being pressed, the weapon will go to the RELOAD state.

The next thing you'll have to do is make a RELOAD state. It's exactly the same thing as making a FIRE state, except instead of shooting, you reload. However, to actually make the game count magazines, you'll need to create a Custom Inventory item. I stole this from the ZDoom CustomInventory page, and adapted it to work for you:


actor Mac10Mag : CustomInventory
{
  Inventory.MaxAmount <Magazine Size in an integer>
}

It should be pretty self explanatory. Now, what you next need to do is create two frames in your FIRE state. One will use A_JumpIfInventory before you fire the bullets, so if it tries to fire and the magazine is "empty", it'll switch to reload. For your use, it would be A_JumpIfInventory("Mac10Mag", <Magazine Size>, "RELOAD"). This would make it jump to the RELOAD state when a certain amount of bullets are fired. The second frame will be after you fire the bullets, which would be A_GiveInventory("Mac10Mag", 1), which works as essentially ticking one spent round from your magazine.

Then, in your RELOAD state, have a frame use A_TakeInventory("Mac10Mag", <Mag Size>). This will "reload" the in-game counter for spent bullets.

still pretty confused on what to do with this code, ive added it in and im able to do something with the reload button, only problem is that it still takes ammo directly from the inventory and it only makes a sound when I press R

help is appreciated

image.png

Share this post


Link to post

Well firstly, the A_JumpIfInventory in the FIRE state should be before everything else. You can use the sprite TNT1 A 0 which acts as a "null" sprite which instantaneously performs any actions relating to it. Secondly, in the A_JumpIfInventory action, you should put the magazine size - which I assume to be 30 - where the "0" is. This will "jump" to the RELOAD state after 30 shots have been fired.

Share this post


Link to post
1 hour ago, act said:

Well firstly, the A_JumpIfInventory in the FIRE state should be before everything else. You can use the sprite TNT1 A 0 which acts as a "null" sprite which instantaneously performs any actions relating to it. Secondly, in the A_JumpIfInventory action, you should put the magazine size - which I assume to be 30 - where the "0" is. This will "jump" to the RELOAD state after 30 shots have been fired.

Alright I changed the code a bit, but the problem is that whenever I press the reload key all it does is change the frame (keep in mind that I also added and entirely different ammo group for the mac10, which I may convert back)

btw heres my current code, help is always appreciated
image.png.b4dc54a4ebe0f477f8bb28a82f92bcd7.png

Share this post


Link to post
15 hours ago, STOOPMAN said:

Alright I changed the code a bit, but the problem is that whenever I press the reload key all it does is change the frame (keep in mind that I also added and entirely different ammo group for the mac10, which I may convert back)

btw heres my current code, help is always appreciated
image.png.b4dc54a4ebe0f477f8bb28a82f92bcd7.png

Well just as a by the way, I should tell you that this whole reloading thing has nothing to do with the actual ammunition or firing lmao, we're just creating a jerryrigged counter to make the game count how many bullets are fired.

Now in your code, the RELOAD state - which is what is executed when you press your reload key - has MA10 A 1 as its only frame. So what that means is that it uses the sprite MA10A0 in your .WAD/.PK3/Whatever for 1 tic. That's what the number means at the end; it's the amount of tics the sprite MA10A0 is rendered for. A tic is 1/35th of a second, so you're telling the game to do the entire reloading thing for 1/35th of a second. If you want to create an animation, use the Offset feature in Decorate.

And once again, you need to create one of these frames after you fire a bullet in order to tell the game you "expended one round from your magazine". That means put MA10 A 0 A_GiveInventory("Mac10Loaded", 1) after you fire the bullet. This tells the game to give the player 1 item that counts as an expended round in your magazine.

Share this post


Link to post
18 minutes ago, act said:

Well just as a by the way, I should tell you that this whole reloading thing has nothing to do with the actual ammunition or firing lmao, we're just creating a jerryrigged counter to make the game count how many bullets are fired.

Now in your code, the RELOAD state - which is what is executed when you press your reload key - has MA10 A 1 as its only frame. So what that means is that it uses the sprite MA10A0 in your .WAD/.PK3/Whatever for 1 tic. That's what the number means at the end; it's the amount of tics the sprite MA10A0 is rendered for. A tic is 1/35th of a second, so you're telling the game to do the entire reloading thing for 1/35th of a second. If you want to create an animation, use the Offset feature in Decorate.

And once again, you need to create one of these frames after you fire a bullet in order to tell the game you "expended one round from your magazine". That means put MA10 A 0 A_GiveInventory("Mac10Loaded", 1) after you fire the bullet. This tells the game to give the player 1 item that counts as an expended round in your magazine.

While I was waiting for a response, I tinkered the code around a bit and managed to make the mac10 preform the animation after it fires 30 bullets, all I need to do now is to jerryrig the counter, but im having problems with that too. whenever I pick up ammo (in this case clips) it goes both to the ammo counter and the backpack counter, so instead of the ammo counter staying at a maximum of 30, it will go beyond that.
help is appreciated (P.S. sorry for my lack of knowledge, but I thank you for teaching me and helping me get this far, thanks! :} ) image.png.586db9472bc982f110739f3bd7696daf.png also heres my code

Share this post


Link to post
55 minutes ago, STOOPMAN said:
Spoiler

While I was waiting for a response, I tinkered the code around a bit and managed to make the mac10 preform the animation after it fires 30 bullets, all I need to do now is to jerryrig the counter, but im having problems with that too. whenever I pick up ammo (in this case clips) it goes both to the ammo counter and the backpack counter, so instead of the ammo counter staying at a maximum of 30, it will go beyond that.
help is appreciated (P.S. sorry for my lack of knowledge, but I thank you for teaching me and helping me get this far, thanks! :} ) image.png.586db9472bc982f110739f3bd7696daf.png also heres my code

 

I genuinely don't understand what you're trying to say. It makes no sense how the clips would increase the magazine counting item, especially when it's hard capped to 30. Not to mention how you'd measure it.

Share this post


Link to post
1 minute ago, act said:

I genuinely don't understand what you're trying to say. It makes no sense how the clips would increase the magazine counting item, especially when it's hard capped to 30. Not to mention how you'd measure it.

can I send you a recording on the weapon in use to give you a better Idea

Share this post


Link to post
35 minutes ago, STOOPMAN said:

can I send you a recording on the weapon in use to give you a better Idea

sure, why not. Use YouTube or something instead of uploading it here because of the 50MB limit.

Share this post


Link to post

you should give weapon.ammotype which A_FireBullets hitscan attack uses, right. but it's only taking in your reload state.

Share this post


Link to post
40 minutes ago, act said:

sure, why not. Use YouTube or something instead of uploading it here because of the 50MB limit.

press 5 on your keyboard, thats where I fire the mac10 and you should see the problem with the ammo count

Share this post


Link to post
33 minutes ago, STOOPMAN said:

press 5 on your keyboard, thats where I fire the mac10 and you should see the problem with the ammo count

I don't really see anything wrong with that? It's working as it should. It fires 30 shots, reloads, and fires 30 more before reloading again.

Anyways, the big fat watermark on your vid tells me you haven't heard of FOSS alternatives. You should look into using OBS and Shotcut for recording gameplay and editing respectively.

Share this post


Link to post
7 minutes ago, act said:

I don't really see anything wrong with that? It's working as it should. It fires 30 shots, reloads, and fires 30 more before reloading again.

Anyways, the big fat watermark on your vid tells me you haven't heard of FOSS alternatives. You should look into using OBS and Shotcut for recording gameplay and editing respectively.

I want the ammo counter to stay at 30, and once it reaches zero, it plays the reload anim/sound and takes 30 ammo. so it creates the illusion of reloading kinda how brutal doom does it

Share this post


Link to post
36 minutes ago, act said:

No clue how to do that, sorry.

Hope this explains it better, I basically want the ammo system to work as it would in a modern shooter like call of duty or battlefield

Demonstration.png

Share this post


Link to post
2 hours ago, STOOPMAN said:

Hope this explains it better, I basically want the ammo system to work as it would in a modern shooter like call of duty or battlefield

Demonstration.png

Well thanks for the MSPaint diagram, but I still don't know how to do that.

I'd recommend rummaging through Brutal Doom in Slade, see what they do to do that. It probably has something to do with the SBARINFO stuff. But I wouldn't sweat it if you can't find a way to make that happen. It's a common thing where reloading weapons don't have any indicator on how much is left in the mag.

Share this post


Link to post

so take what I'm suggesting with a grain of salt; this is how I would do it, not necessarily the only (or even the best) way to handle it.

 

With what you're describing up there, you probably need to have a separate ammo from bullets that your weapon actually fires (which will be the number shown on the left side in the default status bar). Using some form of number-checking code, when reloading the gun would check how much ammo is left in the magazine (if any), then take however many "Bullets" are needed in order to put the magazine back up to 30 ammo. E.g., if the magazine is empty, it will take away 30 bullets and give you 30 mac-10 ammo; if the magazine has 8 rounds left, it will take away 22 bullets and give you 22 more mac-10 ammo for the magazine. I would offer an actual example of this, but I'm not that good at writing DECORATE code without referencing other stuff.

 

Which leads into my next point - like Act mentioned, it's a good idea to check out how others do similar stuff. Either go through the Brutal doom package, or maybe find a weapon on Realm667 that already functions like this and see how it handles reloading.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×