Duke4.net Forums: Double Ammo Issue - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Double Ammo Issue  "An actor that adds BOTH types of ammo at the same time."

User is offline   HELLMOUSE 

#1

Remember in Hexen how some of the power-ups would give you both mana's. I'm trying to do the same thing. The only problem is if one is at full already, I can't pick up the item even if the other ammo type is less than full.

I've made an ammo type that adds ammo for both the Shrinker and Expander at the same time. Only problem is, lets say the Shrinker is at full, I can't gain ammo for the other weapon, which is the Expander in this case. If one ammo type is full, the sprite has no effect on the other ammo type.

Does anyone have a suggestion?

This post has been edited by HELLMOUSE: 17 June 2020 - 07:08 PM

0

User is offline   Danukem 

  • Duke Plus Developer

#2

The addammo command will abort code execution if the weapon being added to is already full, therefore any lines following in that actor/state will not be executed. There are several ways around this. The most straightforward way is to not use that command at all and learn how to check and set the player's ammo_amount members directly. Use the wiki to learn how to do this, it is all there.
3

User is offline   HELLMOUSE 

#3

I've spent enough time on that wiki and need to get back to everything else. I'm sure there is a way to do it, but for now I have lots of other stuff to do. It's not game breaking. Maybe preventing the player from wasting ammo is a good thing, because the actor is for people who like to use the shrinker and expander.
0

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#4

Instead of "addweapon", use this:
  ife player[].gotweapon SHRINKER_WEAPON 1
  ife player[].gotweapon GROW_WEAPON 1
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  setplayer[].gotweapon SHRINKER_WEAPON 1
  setplayer[].gotweapon GROW_WEAPON 1
  addammo SHRINKER_WEAPON 10
  addammo GROW_WEAPON 10


Instead of "addammo", use this:
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
  addammo GROW_WEAPON GROWCRYSTALAMMOAMOUNT

1

User is offline   HELLMOUSE 

#5

Thanks, I'll try this out.
0

User is offline   HELLMOUSE 

#6

View PostFox, on 22 June 2020 - 07:03 PM, said:

Instead of "addweapon", use this:
  ife player[].gotweapon SHRINKER_WEAPON 1
  ife player[].gotweapon GROW_WEAPON 1
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  setplayer[].gotweapon SHRINKER_WEAPON 1
  setplayer[].gotweapon GROW_WEAPON 1
  addammo SHRINKER_WEAPON 10
  addammo GROW_WEAPON 10

Hmm, I'm not sure if I need this part.



View PostFox, on 22 June 2020 - 07:03 PM, said:

Instead of "addammo", use this:
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
  addammo GROW_WEAPON GROWCRYSTALAMMOAMOUNT

This part looks like what I'm talking about. I've tested it, but I still have the same problem. If one is maxed, then Duke doesn't pick up the sprite. You're still using "addammo" which seems to be preventing him from using the object. Even without "addammo" it doesn't work, because there is no way to add anything.

I'm wondering if there is a way to load Duke's ammo amount and the amounts of the power-ups into "vars" and add them together. I did notice some math operations and ways to access the player's structs. Again, I'm not sure of the syntax and some of the commands don't have anything.

Thanks for the advice though.
0

User is offline   Danukem 

  • Duke Plus Developer

#7

I don't think Fox intended to use "addammo" since the whole point was to avoid the problem caused by that command.
2

User is offline   HELLMOUSE 

#8

Game Vars

// MY THING - the Doulbe Ammo (BOOTHER)

gamevar SHRINK_STAT 0 1		// used to report what the player has
gamevar SHRINK_AMMO_ADDIT 0 2	// used to add player number and ammo in the sprite
gamevar SHRINK_SUBIT 0 2 	// used for unused shrinker to transfer to dark exp 
gamevar SHRINK_AMMO_TRANS 0 2	// used for unused shrinker to transfer to dark exp

gamevar DARKEXP_STAT 0 1
gamevar DARKEXP_AMMO_ADDIT 0 2
gamevar DARKEXP_SUBIT 0 2	// used for unused dark exp to transfer to shrinker
gamevar DARKEXP_AMMO_TRANS 0 2	// used for unused dark exp to transfer to shrinker

gamevar BOOTHER_AMOUNT 0 2 	// this is set by each type of BOOTHER actor and is only declared here.




State, BOOTHER_MATH, that is called for the Double Ammo actor (BOOTHER).
This state handles:
1) adding to both ammo types
2) adding to either of the ammo types if the other is full
3) preventing either of the ammo types from exceeding the maximum
4) and allows the transfer of either ammo to the other if one of them is or becomes full.

// MY THING
state BOOTHER_MATH
	getplayer[THISACTOR].ammo_amount 6 SHRINK_AMMO_ADDIT 		 // load what player has
	addvarvar SHRINK_AMMO_ADDIT BOOTHER_AMOUNT 			 // add ammo amount to what player has (SHRINK.. + ..AMOUNT)
	getplayer[THISACTOR].ammo_amount 11 DARKEXP_AMMO_ADDIT
	addvarvar DARKEXP_AMMO_ADDIT BOOTHER_AMOUNT
   
	setplayer[THISACTOR].ammo_amount 6 SHRINK_AMMO_ADDIT 		 // actual update ammo for player with new value	      
	setplayer[THISACTOR].ammo_amount 11 DARKEXP_AMMO_ADDIT
	
	getplayer[THISACTOR].ammo_amount 6 SHRINK_STAT 			 // what does the player have now?
	ifvarg SHRINK_STAT MAXSHRINKERAMMO 				 // if ammo over the max then...            
                { 
		  setvarvar SHRINK_SUBIT SHRINK_STAT			 // puts what the player has into mem
                  subvar SHRINK_SUBIT MAXSHRINKERAMMO			 // figures out what the remaining ammo is 
		  addvarvar DARKEXP_AMMO_TRANS SHRINK_SUBIT		 // puts the ramaining ammo into mem 
		  getplayer[THISACTOR].ammo_amount 11 DARKEXP_STAT	 // get what the player has
	          addvarvar DARKEXP_AMMO_TRANS DARKEXP_STAT		 // adds what remaining ammo is to what player has 
		  setplayer[THISACTOR].ammo_amount 6 MAXSHRINKERAMMO 	 // set to max - no over
	          setplayer[THISACTOR].ammo_amount 11 DARKEXP_AMMO_TRANS // give player the remaining ammo 
                  getplayer[THISACTOR].ammo_amount 11 DARKEXP_STAT	 // get what the player has now
		  ifvarg DARKEXP_STAT MAXGROWAMMO			 // What happens if the other ammo type is full from the transfer?
		    setplayer[THISACTOR].ammo_amount 11 MAXGROWAMMO	 // This stops the program from repeating another transfer with the  
                }							 // code below. 

	getplayer[THISACTOR].ammo_amount 11 DARKEXP_STAT
	ifvarg DARKEXP_STAT MAXGROWAMMO
		{
		  setvarvar DARKEXP_SUBIT DARKEXP_STAT
                  subvar DARKEXP_SUBIT MAXGROWAMMO
		  addvarvar SHRINK_AMMO_TRANS DARKEXP_SUBIT
		  getplayer[THISACTOR].ammo_amount 6 SHRINK_STAT
	          addvarvar SHRINK_AMMO_TRANS SHRINK_STAT
		  setplayer[THISACTOR].ammo_amount 6 SHRINK_AMMO_TRANS
	          setplayer[THISACTOR].ammo_amount 11 MAXGROWAMMO
		  getplayer[THISACTOR].ammo_amount 6 SHRINK_STAT
		  ifvarg SHRINK_STAT MAXSHRINKERAMMO
		    setplayer[THISACTOR].ammo_amount 6 MAXSHRINKERAMMO
                }		
ends




The code for the Double Ammo actor (BOOTHER: BOOTHER5).

// code from Trooper Dan
appendevent EVENT_SPAWN
ifactor BOOTHER5
  sizeat 32 32
endevent
// code from Trooper Dan

// MY THING
actor BOOTHER5
  fall
  cstat 2048
  setvar BOOTHER_AMOUNT 5

  ifmove RESPAWN_ACTOR_FLAG
    state respawnit
  else
    ifp pshrunk nullop
    else ifp palive
      ifpdistl RETRIEVEDISTANCE
        ifcount 6
          ifcanseetarget
          {
            getplayer[THISACTOR].ammo_amount 6 SHRINK_STAT // load player ammo into mem
	    getplayer[THISACTOR].ammo_amount 11 DARKEXP_STAT	    

	    ifvarl SHRINK_STAT MAXSHRINKERAMMO // if player has less than max
            {       	   
              state BOOTHER_MATH
              quote 125
              ifspawnedby BOOTHER5
                state getcode
              else
                state quikget
            }
	    else
             ifvarl DARKEXP_STAT MAXGROWAMMO
             {     
	       state BOOTHER_MATH
               quote 125
               ifspawnedby BOOTHER5
                 state getcode
               else
                 state quikget
             }
	    
          }
enda


This post has been edited by HELLMOUSE: 11 July 2020 - 10:09 PM

0

User is offline   HELLMOUSE 

#9

View PostTrooper Dan, on 17 June 2020 - 08:55 PM, said:

The addammo command will abort code execution if the weapon being added to is already full, therefore any lines following in that actor/state will not be executed. There are several ways around this. The most straightforward way is to not use that command at all and learn how to check and set the player's ammo_amount members directly. Use the wiki to learn how to do this, it is all there.

Thanks for the direction. Accessing the ammo_amount array inside the player struct seems to be the best way to do it. The only problem is an ammo type can go over the max limit. I did fix this and gave the actors the ability to transfer the ammo into the other type if one fills-up. I kind of made the Shrinker and Dark Expander ammo types arguably obsolete since my Double Ammo actors take care of both and will automatically add ammo to the other if one is full.

I'm not sure if there is a more efficient way to do this but this mess works. That's why I made a state, so I wouldn't have to code it for each BOOTHER actor. There's also a gamevar that I used to set the amount of ammo, for both types, to be added from each variation of the actor.

Maybe I could make a "hyper ammo" actor that goes beyond the max limits using these:
gamevars
gamevar commands
get<struct>[THISACTOR].<struct member / array> <member in array> <gamevar>
set<struct>[THISACTOR].<struct member / array> <member in array> <gamevar>

...just a thought since accessing the player structure bypasses certain rules.

This post has been edited by HELLMOUSE: 12 July 2020 - 09:38 AM

0

User is offline   Striker 

  • Auramancer

#10

View PostFox, on 22 June 2020 - 07:03 PM, said:

Instead of "addweapon", use this:
  ife player[].gotweapon SHRINKER_WEAPON 1
  ife player[].gotweapon GROW_WEAPON 1
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  setplayer[].gotweapon SHRINKER_WEAPON 1
  setplayer[].gotweapon GROW_WEAPON 1
  addammo SHRINKER_WEAPON 10
  addammo GROW_WEAPON 10


Instead of "addammo", use this:
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  addammo SHRINKER_WEAPON CRYSTALAMMOAMOUNT
  addammo GROW_WEAPON GROWCRYSTALAMMOAMOUNT



This won't work because the problem is addammo.


This should work. (Untested though, I'm unable to verify if it compiles at this time, but the answer should at least be extremely close to this)

For addweapon:
  // Check if we have the weapons and we're full on ammo for both, if so, break.
  ife player[].gotweapon SHRINKER_WEAPON 1
  ife player[].gotweapon GROW_WEAPON 1
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  
  // Grant the weapon
  setplayer[].gotweapon SHRINKER_WEAPON 1
  setplayer[].gotweapon GROW_WEAPON 1
  
  // Add ammo directly to structs
  addvar player[].ammo_amount SHRINKER_WEAPON 10
  addvar player[].ammo_amount GROW_WEAPON 10
  
  // If ammo exceeds maximum after adding, clamp.
  ifg player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
    setvarvar player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  
  ifg player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    setvarvar player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON


Addammo:
  // Check if we have full ammo for both, if so, break.
  ifge player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  ifge player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    break
  
  // Add ammo directly to structs
  addvar player[].ammo_amount SHRINKER_WEAPON 10
  addvar player[].ammo_amount GROW_WEAPON 10
  
  // If ammo exceeds maximum after adding, clamp.
  ifg player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
    setvarvar player[].ammo_amount SHRINKER_WEAPON player[].max_ammo_amount SHRINKER_WEAPON
  
  ifg player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON
    setvarvar player[].ammo_amount GROW_WEAPON player[].max_ammo_amount GROW_WEAPON


This post has been edited by Striker: 13 July 2020 - 11:34 AM

1

User is offline   HELLMOUSE 

#11

I cleaned my code up a bit. Took out one line in each type because the ...SUBIT gamevars were not needed. I also cleaned up the gamevars and made them perplayer. The BOOTHER_AMOUNT is the same 0 and 2. It pretty much is the same exact code that I posted.

So if you are looking for a double ammo actor then here it is. Remember, it also transfers ammo to the other type when one fills up. I think that my solution may be useful for anyone who has this idea. I've tested it in every possible situation and it does work perfectly.
0

User is offline   HELLMOUSE 

#12

Here is my Double Ammo Actor's code
Attached File  Double Ammo.TXT (7.34K)
Number of downloads: 139
I only have declaration, tile declaration, and actor code for the BOOTHER5 in the Double Ammo attachment.

Here are the pictures I made in EditArt
Attached File  Double_Ammo_Pics.zip (7.14K)
Number of downloads: 146

What do these actors do again?
1) Give ammo for the Shrinker and Expander at the same time
2) Transfer the ammo to the other type if one is full
3) Saves the remaining ammo Duke does not need by storing it in a gamevar
---- The actor will not disappear until all the ammo for both are gone. No waste of ammo.
4) Outputs exactly what Duke is receiving in a HUD message

Thanks Trooper Dan, Fox, and Striker for the help! :)


By the way, the word Boother is Hellmouse for double functional charge and multi-compatible battery unit. It's a rough translation but that's what it does. Mono-compatible would only charge one weapon at a time and not save any energy for the other. Multi-compatible can do both at the same time. Double functional charge just means it holds two types of energy.

This post has been edited by HELLMOUSE: 25 July 2020 - 05:46 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options