Page 1 of 1

player class in ACS -Solved

Posted: Fri Jun 17, 2022 11:56 am
by Hitscanner
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.

Re: player class in ACS

Posted: Fri Jun 17, 2022 12:08 pm
by Enjay
You have ; after your CheckInventory lines. They should not be there.

Code: Select all

if (Checkinventory("IamTheWarrior")<1)
    {
        Do stuff
    
}
 


That should work (obviously replace "do stuff" with actual code) and should also allow you to use else.

Re: player class in ACS

Posted: Sat Jun 18, 2022 11:39 am
by Hitscanner
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)
}

Re: player class in ACS

Posted: Sat Jun 18, 2022 1:16 pm
by Enjay
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 all

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 all

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.

Re: player class in ACS

Posted: Sat Jun 18, 2022 1:39 pm
by Hitscanner
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?

Re: player class in ACS

Posted: Sat Jun 18, 2022 1:43 pm
by wildweasel
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. ;)

Re: player class in ACS

Posted: Sat Jun 18, 2022 1:56 pm
by Enjay
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 all


    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.

Re: player class in ACS

Posted: Sat Jun 18, 2022 3:13 pm
by Hitscanner
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 all


    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!

Re: player class in ACS

Posted: Sun Jun 19, 2022 1:31 am
by MFG38
Hitscanner wrote:whoah. dude you're way better at this than i am.


Years of experience working with ACS works wonders. ;)

Re: player class in ACS

Posted: Sun Jun 19, 2022 4:08 am
by Enjay
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.

Re: player class in ACS

Posted: Sun Jun 19, 2022 12:36 pm
by Hitscanner
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.