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".
Using an item on the floor using the use key.
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!)
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!)
-
- Posts: 1730
- Joined: Tue Mar 22, 2011 11:54 pm
-
- Posts: 2274
- Joined: Tue Jun 30, 2009 1:31 pm
Re: Using an item on the floor using the use key.
Is this for ZScript or DECORATE? Because with ZScript you can create a base inventory class like so:
Though, IIRC you can create a base class in ZScript then your DECORATE actors can inherit from it.
Code: Select all
class UseInventory : Inventory
{
override bool used(Actor user)
{
Super.touch(user);
return true;
}
override void touch(Actor toucher)
{
}
}
-
- Posts: 1730
- Joined: Tue Mar 22, 2011 11:54 pm
Re: Using an item on the floor using the use key.
Zscript at the moment. Thanks for the code!Mikk- wrote:Is this for ZScript or DECORATE?
May I ask how this works?Mikk- wrote:Code: Select all
class UseInventory : Inventory { override bool used(Actor user) { Super.touch(user); return true; } override void touch(Actor toucher) { } }
-
- 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.
Inheritance.
Read this: https://zdoom.org/wiki/Using_inheritance
Basically, your items need to inherit from the class provided by Mikk-.
Read this: https://zdoom.org/wiki/Using_inheritance
Basically, your items need to inherit from the class provided by Mikk-.
-
- Posts: 1606
- Joined: Mon Jun 12, 2017 12:57 am
Re: Using an item on the floor using the use key.
You override two functions that exist in inventory class.insightguy wrote: May I ask how this works?
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 void touch(Actor toucher)
{
}
Function "used" called when actor been used by "use" key.override bool used(Actor user)
{
Super.touch(user);
return true;
}
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.
-
- Posts: 1730
- Joined: Tue Mar 22, 2011 11:54 pm
Re: Using an item on the floor using the use key.
I get the override part. Now I understand what it's overriding. Thanks!