Page 1 of 1

Using an item on the floor using the use key.

PostPosted: Fri Mar 02, 2018 7:17 am
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".

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

PostPosted: Fri Mar 02, 2018 8:20 am
by Mikk-
Is this for ZScript or DECORATE? Because with ZScript you can create a base inventory class like so:
Code: Select allExpand view

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.

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

PostPosted: Fri Mar 02, 2018 10:25 am
by insightguy
Mikk- wrote:Is this for ZScript or DECORATE?

Zscript at the moment. Thanks for the code!

Mikk- wrote:
Code: Select allExpand view

class UseInventory 
: Inventory
    
{
    override bool used(Actor user)
            {
            Super.touch(user);
            return true;
            }
            
        override void touch
(Actor toucher) 
            
{
            }
    }
 


May I ask how this works?

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

PostPosted: Fri Mar 02, 2018 11:36 am
by ramon.dexter
Inheritance.

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

Basically, your items need to inherit from the class provided by Mikk-.

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

PostPosted: Fri Mar 02, 2018 12:44 pm
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.

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

PostPosted: Fri Mar 02, 2018 6:01 pm
by insightguy
I get the override part. Now I understand what it's overriding. Thanks!