Advanced Search

Author Topic: [Suggestion for modding] Add a user variable  (Read 1659 times)

0 Members and 1 Guest are viewing this topic.

September 30, 2016, 12:32:17 PM
Read 1659 times

Offline Xhatahx

  • Standard Member

  • *sregnif sevaelretni* stenet wef a evah I
  • Date Registered: September 03, 2016, 07:21:47 AM

    • View Profile
[Suggestion for modding] Add a user variable
« on: September 30, 2016, 12:32:17 PM »
Say someone wants to make a weapon that does something special, like firing projectiles in a sine wave. There are two ways of doing this: the honestly wasteful Wave Burner implementation, or using a user variable and use sin(user_var) as the angle.

However, user variables can only be defined for weapons in the player class, so you have to add the variable to the player itself.

Maybe user variables can be used in some old weapons(e.g. Wave Burner).

September 30, 2016, 12:57:41 PM
Reply #1

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: [Suggestion for modding] Add a user variable
« Reply #1 on: September 30, 2016, 12:57:41 PM »
I've been tinkering with user variables and they seem to work fine online so all seems good. I'm not sure if defining them in the player class for weapon specific things is correct though. What if a custom made inventory item also wants to access these variables? Or an ACS script? I know they don't work in weapons (I tried it) but I can't help but feel there's a more elegant way to do this.

Edit: Wait, how would you access and set these said variables in a weapon?

September 30, 2016, 01:45:48 PM
Reply #2

Offline Xhatahx

  • Standard Member

  • *sregnif sevaelretni* stenet wef a evah I
  • Date Registered: September 03, 2016, 07:21:47 AM

    • View Profile
Re: [Suggestion for modding] Add a user variable
« Reply #2 on: September 30, 2016, 01:45:48 PM »
Like this:

Code: [Select]
Ready:
FLSB T 0 ACS_ExecuteAlways(998,0,86)
FLSB T 0 A_SetUserVar("user_var",0)
FLSB T 1 A_WeaponReady
Goto Ready+2
Fire:
FLSB T 0 A_JumpIfNoAmmo("NoAmmo")
FLSB T 0 A_PlaySoundEx("misc/fakeshot","Weapon")
FLSB T 0 A_FireCustomMissile("BassShot",0,1,8,0)
FLSB T 0 A_FireCustomMissile("BassShot",10+ACS_ExecuteWithResult(112)*2,0,8,0)
FLSB T 0 A_FireCustomMissile("BassShot",-(10+ACS_ExecuteWithResult(112)*2),0,8,0)
FLSB UV 2
FLSB T 0 A_JumpIf(user_var>=14,"EndFire")
FLSB T 0 A_SetUserVar("user_var",ACS_ExecuteWithResult(112)+1)
FLSB T 0 A_Refire
Goto Ready+1
EndFire:
FLSB UV 6
FLSB T 20
Goto Ready+1

<Meanwhile, in ACS...>
script 112 (void)
{
SetResultValue(GetUserVariable(0,user_var));
}

September 30, 2016, 02:20:29 PM
Reply #3

Offline CutmanMike

  • Administrator

  • Is it hot in here or is it just zscript?
  • *******
  • Date Registered: December 17, 2008, 12:24:34 PM

    • View Profile
    • https://cutstuff.net
Re: [Suggestion for modding] Add a user variable
« Reply #3 on: September 30, 2016, 02:20:29 PM »
I'll have to talk this over with Lego. I'm worried that if we assign a bunch of random generic user variables to the player class, all sorts of things could end up wanting to use them and cause issues if more than one thing wants to access them. I am all for doing away with inventory jumps and all that garbage, but want to make sure it is done correctly.

For now though, for something as simple as this, you could use Args and A_SetArg. You don't even need ACS this way. These are still bound to the playerclass and not the weapon, though.

September 30, 2016, 04:07:46 PM
Reply #4

Offline Xhatahx

  • Standard Member

  • *sregnif sevaelretni* stenet wef a evah I
  • Date Registered: September 03, 2016, 07:21:47 AM

    • View Profile
Re: [Suggestion for modding] Add a user variable
« Reply #4 on: September 30, 2016, 04:07:46 PM »
For now though, for something as simple as this, you could use Args and A_SetArg.
Oh, right. Derp. You can lock this topic now.