Using an item on the floor using the use key.

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!)
User avatar
insightguy
Posts: 1730
Joined: Tue Mar 22, 2011 11:54 pm

Using an item on the floor using the use key.

Post by insightguy »

I'm trying to make a weapon system that allows for interchangeable parts and need a way to use items on the ground.

When I mean use, I mean that the player must press or hold the use key to" activate" the Item rather than the conventional "auto pick up" or "store for later use".
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

Re: Using an item on the floor using the use key.

Post by Mikk- »

Is this for ZScript or DECORATE? Because with ZScript you can create a base inventory class like so:

Code: Select all

class UseInventory : Inventory
    {
    override bool used(Actor user)
            {
            Super.touch(user);
            return true;
            }
            
        override void touch(Actor toucher) 
            {
            }
    }
Though, IIRC you can create a base class in ZScript then your DECORATE actors can inherit from it.
User avatar
insightguy
Posts: 1730
Joined: Tue Mar 22, 2011 11:54 pm

Re: Using an item on the floor using the use key.

Post by insightguy »

Mikk- wrote:Is this for ZScript or DECORATE?
Zscript at the moment. Thanks for the code!
Mikk- wrote:

Code: Select all

class UseInventory : Inventory
    {
    override bool used(Actor user)
            {
            Super.touch(user);
            return true;
            }
            
        override void touch(Actor toucher) 
            {
            }
    }
 
May I ask how this works?
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Using an item on the floor using the use key.

Post by ramon.dexter »

Inheritance.

Read this: https://zdoom.org/wiki/Using_inheritance

Basically, your items need to inherit from the class provided by Mikk-.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Using an item on the floor using the use key.

Post by Apeirogon »

insightguy wrote: May I ask how this works?
You override two functions that exist in inventory class.
override void touch(Actor toucher)
{
}
Function "touch" calls every time you "step" on item. But, in this case, you left it empty, which gzdoom read as "dont do anything when player walk on some item"
override bool used(Actor user)
{
Super.touch(user);
return true;
}
Function "used" called when actor been used by "use" key.
Here you call touch functions, which means "call usual touch functions", super.touch functions means "use functions with name 'touch' from its parent class", and reutrn boolean true, because this functions work so.
There are you find more informations.
User avatar
insightguy
Posts: 1730
Joined: Tue Mar 22, 2011 11:54 pm

Re: Using an item on the floor using the use key.

Post by insightguy »

I get the override part. Now I understand what it's overriding. Thanks!

Return to “Scripting”