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.

Using an item on the floor using the use key.

Postby insightguy » Fri Mar 02, 2018 7:17 am

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
insightguy
^HEY! My avatar is up there^
Banned User
 
Joined: 23 Mar 2011

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

Postby Mikk- » Fri Mar 02, 2018 8:20 am

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.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

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

Postby insightguy » Fri Mar 02, 2018 10:25 am

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?
User avatar
insightguy
^HEY! My avatar is up there^
Banned User
 
Joined: 23 Mar 2011

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

Postby ramon.dexter » Fri Mar 02, 2018 11:36 am

Inheritance.

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

Basically, your items need to inherit from the class provided by Mikk-.
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

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

Postby Apeirogon » Fri Mar 02, 2018 12:44 pm

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
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

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

Postby insightguy » Fri Mar 02, 2018 6:01 pm

I get the override part. Now I understand what it's overriding. Thanks!
User avatar
insightguy
^HEY! My avatar is up there^
Banned User
 
Joined: 23 Mar 2011


Return to Scripting

Who is online

Users browsing this forum: ramon.dexter and 1 guest