player class in ACS -Solved

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!)

player class in ACS -Solved

Postby Hitscanner » Fri Jun 17, 2022 11:56 am

Hello zdoom forums. I have a question i couldnt find the answer to.

Im trying to get ACS to recognize Differnet classes for events (ex: a crate appears and one character says "whoah!" and the other shouts in fear)
and a few other things i got planned. where im stuck is that i cant get ACS to recognize The actor in question, I've tried using if-else but the compiler always says something is wrong with else.(its not the brackets, ive checked alot)

I cant figure this out, can anyone help?

Code snippet :

if (Checkinventory("IamTheWarrior")<1);
{
Print(s: "Promise?");
Delay(60);
SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
Thing_activate(10);
if(Checkinventory("IAmTheWarrior")>1);
}

oh i had to use if because it was the only thing that didnt cause an error

again if anyone knows how, i would be super, super grateful.
Last edited by Hitscanner on Sun Jun 19, 2022 12:36 pm, edited 1 time in total.
Hitscanner
 
Joined: 17 Jun 2022
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: player class in ACS

Postby Enjay » Fri Jun 17, 2022 12:08 pm

You have ; after your CheckInventory lines. They should not be there.
Code: Select allExpand view
if (Checkinventory("IamTheWarrior")<1)
    {
        Do stuff
    
}
 


That should work (obviously replace "do stuff" with actual code) and should also allow you to use else.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: player class in ACS

Postby Hitscanner » Sat Jun 18, 2022 11:39 am

okay, i THOUGHT i had this solved but. its giving me the same error now....can you help me again? i suspect its because im not sujpposed to use if more than once per script, but i dont know another way to do this....(what i want is for each player class to respond differently to what is happening) ...sorry about this.

if (CheckInventory("IamTheCleric")<1)
{
Delay (30);
Print(s:"Dont try it!");
Delay(60);
SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
Thing_Activate(10);
}
Else ("IamTheCleric")>1)
}



if (Checkinventory("IamTheWarrior")<1)
{
Print(s: "Promise?");
Delay(60);
SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
Thing_activate(10);
Else (Checkinventory("IAmTheWarrior")>1)
}
Hitscanner
 
Joined: 17 Jun 2022
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: player class in ACS

Postby Enjay » Sat Jun 18, 2022 1:16 pm

Yeah, you've got a few misplaced braces and some off layout there.

I take it that you have two classes and each class has its own identifying inventory item?

I'm not a coder, so there may be a better/more accepted way to do this but I *think* what you are trying to do is this:

Code: Select allExpand view
if (CheckInventory("IamTheCleric")<1)
    {
        Delay (30);
        Print(s:"Dont try it!");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_Activate(10);
    }

Else
    {
        Print(s: "Promise?");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_activate(10);
    }


Unless I've made a mistake, that should check for the IamTheCleric item and, if there are less than 1 present in the calling actor's inventory, it will run the bit of code in the first set of braces. (i.e. you would see the "Don't try it." message.)

If, however, IamTheCleric is 1 or greater, then that first bit of code will be ignored and the lines in the braces following the Else will be run instead. (i.e. you will see "Promise?")

BTW, presumably you could replace if (CheckInventory("IamTheCleric")<1) with if (CheckInventory("IamTheCleric")==0) i.e. instead of saying "is there less than 1 present" you are explicitly saying "is the amount present equal to zero".


Another approach might be to do away with the else (not sure if real coders like this approach or not - but it should work) and explicitly check for class specific items for each result that you want from the script. The lines inside the braces will only run if the item is present, so you could perhaps use this approach if you have several classes rather than just two:

Code: Select allExpand view
if (CheckInventory("IamTheWarrior")>0)
    {
        Delay (30);
        Print(s:"Dont try it!");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_Activate(10);
    }

if (CheckInventory("IamTheCleric")>0)
    {
        Print(s: "Promise?");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_activate(10);
    }
    
if 
(CheckInventory("IamTheWizard")>0)
    {
        Print(s: "I'm going to run away and cast magic missile from a distance.");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_activate(10);
    }
    
if 
(CheckInventory("IamTheAssassin")>0)
    {
        Print(s: "Imma kill you");
        Delay(60);
        SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
        Thing_activate(10);
    }


I would also urge you to look into using SetHudSize to set how big your text appears and also HudMessage to give you much more control over how your text looks. The basic print commands are easy to use, but they are not hugely flexible. HUDMessages are a bit arcane in their syntax, but they often give a better result in the long run.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: player class in ACS

Postby Hitscanner » Sat Jun 18, 2022 1:39 pm

so, yes i have three classes(Cleric, Fighter, mage), ive tested them all, and they all work.
it a simple solution at a glance, but maybe ive been doing this script for too long.
anyway! thank you so much, enjay! (big fan, btw) i genuinely could not figure this out. your help means the actual world to me

now.. how do i mark this as solved?
Hitscanner
 
Joined: 17 Jun 2022
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: player class in ACS

Postby wildweasel » Sat Jun 18, 2022 1:43 pm

Hitscanner wrote:now.. how do i mark this as solved?

If you're satisfied with this solution, you only need to go edit the first post of the thread and change its title. You'd be doing a nice favor for future generations that way. ;)
User avatar
wildweasel
from a different perspective.
Moderator Team Lead
 
Joined: 15 Jul 2003

Re: player class in ACS

Postby Enjay » Sat Jun 18, 2022 1:56 pm

Glad you've got it working. I guess that there is one more thing to say: if your script looks much like the example I posted, there is a lot of common ground inside the braces. That's unnecessary repetition. So you could do this:

Code: Select allExpand view

    if 
(CheckInventory("IamTheWarrior")>0)
        {
            Delay (30);
            Print(s:"Dont try it!");
        }

    if (CheckInventory("IamTheCleric")>0)
        {
            Print(s: "Promise?");
        }
        
    if 
(CheckInventory("IamTheWizard")>0)
        {
            Print(s: "I'm going to run away and cast magic missile from a distance.");
        }
        
    if 
(CheckInventory("IamTheAssassin")>0)
        {
            Print(s: "Imma kill you");
        }
        

    Delay
(60);
    SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
    Thing_Activate(10); 


What happens there is that the class-specific stuff inside the braces gets run, then the common lines (the delay of 60, the player property and the thing_Activate) get run.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: player class in ACS

Postby Hitscanner » Sat Jun 18, 2022 3:13 pm

Enjay wrote:Glad you've got it working. I guess that there is one more thing to say: if your script looks much like the example I posted, there is a lot of common ground inside the braces. That's unnecessary repetition. So you could do this:

Code: Select allExpand view

    if 
(CheckInventory("IamTheWarrior")>0)
        {
            Delay (30);
            Print(s:"Dont try it!");
        }

    if (CheckInventory("IamTheCleric")>0)
        {
            Print(s: "Promise?");
        }
        
    if 
(CheckInventory("IamTheWizard")>0)
        {
            Print(s: "I'm going to run away and cast magic missile from a distance.");
        }
        
    if 
(CheckInventory("IamTheAssassin")>0)
        {
            Print(s: "Imma kill you");
        }
        

    Delay
(60);
    SetPlayerProperty(TRUE, OFF, PROP_TOTALLYFROZEN);
    Thing_Activate(10); 


What happens there is that the class-specific stuff inside the braces gets run, then the common lines (the delay of 60, the player property and the thing_Activate) get run.


whoah. dude you're way better at this than i am. i just know the commands from google. Not so much how they flow. Thanks again!
hey uh, since i have the attention of the class, would you also happen to how to make a Diablo 2 style custom character select screen? im kinda lost there, too. And *mods* im willing to create another topic, if you prefer.


[/quote=""wildweasel"] just change the title to solved, that will help future generations[/quote] Thank you!
Hitscanner
 
Joined: 17 Jun 2022
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)

Re: player class in ACS

Postby MFG38 » Sun Jun 19, 2022 1:31 am

Hitscanner wrote:whoah. dude you're way better at this than i am.


Years of experience working with ACS works wonders. ;)
User avatar
MFG38
 
Joined: 14 Apr 2019
Location: Finland
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia (Modern GZDoom)

Re: player class in ACS

Postby Enjay » Sun Jun 19, 2022 4:08 am

Thanks for all the positivity. :D But, yeah, I've been doing it for a while.

However, everything I do is learned as I need it. Other than an introduction to C++ short-course a few years back just to help me understand some of the terminology, I've never been formally instructed in any of this stuff. Which is why I'm sure someone who understands coding properly could look at many of the things I've done and identify a quicker and more efficient way of doing things. Indeed, they often have and I am always grateful for the input.

Much of the time, it doesn't really matter too much with something like ACS in the context of simple game scripts, but I certainly don't have a fundamental or intuitive understanding of many of the things that can be done with it.


As for a Diablo 2-stlye character selection... I've never even played Diablo 2 (too busy playing Doom ;) ). I've looked at a video of it and I'm pretty sure that it would be possible with a character selection map, some cunning ACS, some custom characters for the animations etc but the detail of precisely how to do it is beyond what I know how to do. I know that the various requirements will be more or less in the game engine but I've never done anything like it myself.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: player class in ACS

Postby Hitscanner » Sun Jun 19, 2022 12:36 pm

okay. ive been messing with menudef and im hoping to add acs execute in there somewhere to change the camera and select the class. thank you for your help, ill mark this as solved now.
Hitscanner
 
Joined: 17 Jun 2022
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: Intel (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: ABDO and 0 guests