Set Powerup.Colormap in ZScript

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Set Powerup.Colormap in ZScript

Post by etbasch »

I want to change the colormap for Invulnerability sphere in Zscript, but without replacing the actor. If I were to use replacement, I would simply write:

Code: Select all

Inv : InvulnerabilitySphere replaces InvulnerabilitySphere {
    Default {
        Powerup.Colormap  0.0, 0.0, 0.0, 1.0, 1.0, 1.0;
        }
}
Now I want to attach that property after the object has spawned onto the map, like this:

Code: Select all

class SomeEventHandler : EventHandler {
    override void WorldThingSpawned(WorldEvent e) {
		if (e.thing is "Powerup") {
                    let pow = Powerup(e.thing);
                    if (pow.GetClassName() = 'InvulnerabilitySphere')
                        pow.colormap  0.0, 0.0, 0.0, 1.0, 1.0, 1.0;
                }
    }
}
It doesn't work. I get an error "Expression must be a modifiable value". When I rewrite the command as

Code: Select all

pow.colormap = "0.0, 0.0, 0.0, 1.0, 1.0, 1.0";
It cannot read that expression. What am I missing here? Can this be done in Zscript?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Set Powerup.Colormap in ZScript

Post by Player701 »

It looks from the source code that the Powerup.Colormap property is handled in a very special way - it builds and adds a colormap to an internal engine table at compile time. It doesn't seem to be possible to change it from the script side.

However, it is possible to change the value of BlendColor for a PowerupGiver to set a normal color instead. Use the following ZScript for that (replace A, R, G, B with the corresponding values of your color's components):

Code: Select all

class SomeEventHandler : EventHandler 
{
    override void WorldThingSpawned(WorldEvent e) 
    {
        let a = e.Thing;

        if (a is 'InvulnerabilitySphere')
        {
            InvulnerabilitySphere(a).BlendColor = Color(A, R, G, B);
        }
    }
}
Do note that your original code contains the following errors:
  • You are confusing Powerup and PowerupGiver. Powerup is what actually does the effect. It doesn't spawn initially on the map, and while you can probably modify it too, you instead do another check to ensure it's an InvulnerabilitySphere. However, an InvulnerabilitySphere is a PowerupGiver, not a Powerup. PowerupGiver is a type of item that spawns in the map and gives the powerup upon pickup/activation. PowerupGiver and Powerup are not interchangeable; your code wouldn't work properly even if it compiled.
  • You are confusing actor properties and fields. A property is set only once in the default block, and while its value(s) may be overridden in derived classes, it cannot be changed anywhere in the code by addressing the property directly. A property definition relies on one or more backing fields that usually can be accessed and/or modified. However, some properties function differently, and Powerup.Colormap is one such example. For more details, see ZScript custom properties.
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Thanks Player701! You are the only one who could give me a good understandable answer.
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Player701 wrote: However, it is possible to change the value of BlendColor for a PowerupGiver to set a normal color instead. Use the following ZScript for that (replace A, R, G, B with the corresponding values of your color's components):
I still can't convert the DECORATE value "0.0, 0.0, 0.0, 1.0, 1.0, 1.0" into an RGB color, assuming Alpha has a default value. When i put

Code: Select all

Color(00, 01, 11)
it simply takes away any kind of color effect for the Invul. sphere. But the color should be light-grayish. Can you help me with the converting?

I've read thse articles but still is missing something:
https://zdoom.org/wiki/A_SetBlend
https://zdoom.org/wiki/Actor_properties#Powerup
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Set Powerup.Colormap in ZScript

Post by Player701 »

I don't think there are any default values in the color expression. Values go from 0 to 255. An alpha of 0 means fully transparent, while 255 means fully opaque. From your code, I'm not quite sure of the exact color you're trying to get. Here's how it would look like for light gray, 50% transparent:

Code: Select all

Color(128, 211, 211, 211)
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Player701 wrote:I don't think there are any default values in the color expression. Values go from 0 to 255. An alpha of 0 means fully transparent, while 255 means fully opaque. From your code, I'm not quite sure of the exact color you're trying to get. Here's how it would look like for light gray, 50% transparent:

Code: Select all

Color(128, 211, 211, 211)
Yes, now I know how it works and it actually works here. But the effect is like a mist in the air, more or less opaque. Seems like it can't neither inverse colors (like by default) nor decolorize them (make everything in gray-scale). That way it does not adding any mist in the air, it simply changes the colors of everything in the world. Can this be done using the example above?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Set Powerup.Colormap in ZScript

Post by Player701 »

Now I just thought of an interesting way to do what you want.

Like I said before, colormaps are created at compile time, and you can't create a new one at runtime. However, there is nothing to prevent you from defining it at compile time by creating your own class:

Code: Select all

class MyColormap : PowerupGiver
{
    Default
    {
        Powerup.Colormap 0.0, 0.0, 0.0, 1.0, 1.0, 1.0;
    }
}
We won't actually be using instances of this class in-game. What we need is the index into the colormap table, which was created during compilation. It is stored in our class as a specially masked value of the BlendColor field, the same one we've been using before. We don't need to know its exact value (it may also change with each run depending on the WAD files used and other things). What we need to do is to retrieve it from MyColormap and put it into the invulnerability powerup:

Code: Select all

class SomeEventHandler : EventHandler
{
    override void WorldThingSpawned(WorldEvent e)
    {
        let a = e.Thing;

        if (a is 'InvulnerabilitySphere')
        {
            InvulnerabilitySphere(a).BlendColor = GetDefaultByType('MyColormap').BlendColor;
        }
    }
}
I have just tested this myself, and it actually works! Don't know why I didn't think of it before. But now you know how to change both the blend color and the colormap. You are still limited to colormaps that you can create at compile time, however - you cannot dynamically alter it during gameplay.
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Player701 wrote: I have just tested this myself, and it actually works! Don't know why I didn't think of it before. But now you know how to change both the blend color and the colormap. You are still limited to colormaps that you can create at compile time, however - you cannot dynamically alter it during gameplay.
Great! Thanks, now I know how to do it. However, the change does not work for me for some reason. It still uses default inverse-colored colormap. Did it work for you?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Set Powerup.Colormap in ZScript

Post by Player701 »

This WAD works for me in GZDoom 4.4.2.
Attachments
colormap_change.wad
(534 Bytes) Downloaded 26 times
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Player701 wrote:This WAD works for me in GZDoom 4.4.2.
I was using older versions of GZDoom and ZScript. I'll try the latest versions on this. Anyway, thanks for the help.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Set Powerup.Colormap in ZScript

Post by Player701 »

Yeah, I recommend to always use the latest version of GZDoom. Older versions may not support the features I'm suggesting to use, and/or may contain bugs that prevent said features from working properly.
Last edited by Player701 on Tue Oct 06, 2020 9:09 am, edited 1 time in total.
User avatar
etbasch
Posts: 25
Joined: Wed Apr 10, 2019 5:42 pm
Graphics Processor: nVidia (Modern GZDoom)
Location: Ukraine

Re: Set Powerup.Colormap in ZScript

Post by etbasch »

Player701 wrote:Yeah, I recommend to always use the latest version of GZDoom. Older versions may not support the features I'm suggesting to use, and/or may contains bugs that prevent said features from working properly.
The reason it didn't work back then because I forgot to add my EventHandler to the MAPINFO file, that's why it didn't work. Now the colormap works fine with Invulnerability Sphere without replacing the actual actor. Great.
Post Reply

Return to “Scripting”