Wolf3d Haven Forum

Please log in or register. Smile

Join the forum, it's quick and easy

Wolf3d Haven Forum

Please log in or register. Smile

Wolf3d Haven Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


3 posters

    [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL)

    avatar
    TheLoneSurvivor
    Wolf3d n00b
    Wolf3d n00b


    Male
    Number of posts : 5
    Age : 22
    Registration date : 2015-08-11

    [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL) Empty [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL)

    Post by TheLoneSurvivor Mon Aug 17, 2015 9:44 am

    So, for example, you know how in Doom it says "Picked up a Medkit you REALLY need!" when you have lower than 26 health?

    I will show you how to do this, among other things in Wolf4SDL.

    YOU NEED WSJ's INGAME MESSAGES ADDED TO YOUR CODE FOR THIS TO WORK!

    All the changes are in WL_AGENT.CPP, and written by me without me following any tutorials, so report any bugs.

    ("Picked up a Medkit you REALLY need!")


    Code:
            case    bo_firstaid:
                if (gamestate.health == 100)
                    return;

                SD_PlaySound (HEALTH2SND);
                HealSelf (25);
                    if (gamestate.health <= 51)
                    {
                       GetMessage("Picked up a medkit you REALLY need.");
                    }
                    else if (gamestate.health >= 51)
                    {
                       GetMessage("Picked up a medkit.");
                    }
                break;


    The reason it is 51, rather than 26, is because of a logic error that happens in the Doom code, and would be in this code too if not corrected, despite being new code.
    The error is that since it is when your health is below 26, and a medkit gives you 25 health, your health will be at a minimum 26, due to your minimum health to be alive is 1, thus meaning since it uses less than for the medkit you really need string.

    So, why the number 51? Because I am using the logic error to my advantage. 

    Basically, If you look back to the logic error, and make it 51 instead of 26, the minimum health for displaying the string is when your health is under 26. 
    The reason for this involves some basic knowledge, but maybe advanced if you do not know how integers, and less than and more than work.
    Basically, Due to the fact that you gain 25 health from a medkit, and 51-25=26. Due to the fact the message will display as only "picked up a medkit"  rather than "picked up a medkit you REALLY need" if after you gain 25 health, your health is equal to or more than 26 when you have minimum 1 hp, meaning when set to 26, it is impossible to see the message when set to 26. However, since it is set to 51, if you get 25 hp when you are at 26 hp, you will be at 51, meaning you will not see the message. If you are at 1 hp, and get 25 health, you will see the message, due to it being in the range now. Clever, huh?

    If you walk over ammo with your ammo full, it will say ammo full.


    Code:
            case    bo_clip:
                if (gamestate.ammo == 99)
                    {
                        GetMessage("Can't pick up the ammo, your ammo is full!"
                    }
                    return;
                SD_PlaySound (GETAMMOSND);
                GiveAmmo (8);
                GetMessage("Picked up a clip.")
                break;


    Picked up a gold key or silver key.

    Since the block of code for the keys looks like this, when you put a message for the keys, (i put a getmessage in there to demonstrate, if you want to see what I mean)
    it only says one thing for all the keys.
           
    Code:
     case    bo_key1:
            case    bo_key2:
            case    bo_key3:
            case    bo_key4:
                GiveKey (check->itemnumber - bo_key1);
                SD_PlaySound (GETKEYSND);
                GetMessage("Picked up a key.");
                break;

    To make it say picked up a gold key, and picked up a silver key, for the gold and silver key change it to say this.


    Code:
            case    bo_key1:
                GetMessage("Picked up a gold key.");
            case    bo_key2:
                GetMessage("Picked up a silver key.");
            case    bo_key3:
            case    bo_key4:
                GiveKey (check->itemnumber - bo_key1);
                SD_PlaySound (GETKEYSND);
                break;

    This would work too.

     
    Code:
           case    bo_key1:
            case    bo_key2:
            case    bo_key3:
            case    bo_key4:
                GiveKey (check->itemnumber - bo_key1);
                SD_PlaySound (GETKEYSND);
                if(bo_key1)
                {
                      GetMessage("Picked up a gold key.");
                }
                else if(bo_key2)
                {
                      GetMessage("Picked up a silver key.");
                }
                break;

    Leave any of your ideas for things like these and I can do them.
    I will update this with more code as I do more.
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL) Empty Re: [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL)

    Post by Mega Luigi Tue Aug 18, 2015 5:00 pm

    It's good to see someone doing a tutorial that can be easily customized by someone who needs it. Good one there.

    However, hopefully I won't sound too cranky doing this, but there are some things that are most likely to make you run into trouble:


    Code:
    case    bo_clip:
                if (gamestate.ammo == 99)
                    {
                        GetMessage("Can't pick up the ammo, your ammo is full!"
                    }
                    return;            <<<This will return even when you should be able to pick up the ammo.
                SD_PlaySound (GETAMMOSND);
                GiveAmmo (8);
                GetMessage("Picked up a clip.")
                break;



    Code:
    case    bo_key1:
                GetMessage("Picked up a gold key.");  <<This message will be overwritten by the second one, even if it is a gold key.
            case    bo_key2:
                GetMessage("Picked up a silver key.");
            case    bo_key3:
            case    bo_key4:
                GiveKey (check->itemnumber - bo_key1);
                SD_PlaySound (GETKEYSND);
                break;


    Code:
    case    bo_key1:
            case    bo_key2:
            case    bo_key3:
            case    bo_key4:
                GiveKey (check->itemnumber - bo_key1);
                SD_PlaySound (GETKEYSND);
                if(bo_key1) << This should actually be "if (check->itemnumber == bo_key1)". "bo_key1" (and other bos) are of the enumerated
                              wl_stat_t, and enumerated types are mapped to integers by the compiler, meaning the condition you are
                              comparing is actually an integer >= 0. Since bo_key1 is not the first member of the type, this condition will
                              be always true.
                {
                      GetMessage("Picked up a gold key.");
                }
                else if(bo_key2) <<Same here, although this one is never reached due to the "else"
                {
                      GetMessage("Picked up a silver key.");
                }
                break;


    I didn't test it on the game, but those are the problems I've seen. Again, don't take it the wrong way, just trying to spare you (and maybe someone else) of some headaches Cool
    Officer-Michael John
    Officer-Michael John
    Seasoned Wolfer
    Seasoned Wolfer


    Male
    Number of posts : 332
    Age : 26
    Hobbie : Video and Wolf 3D mode making
    Registration date : 2014-08-04

    [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL) Empty Re: [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL)

    Post by Officer-Michael John Thu Aug 20, 2015 11:32 pm

    Wow. Doom in-game message in Wolf 3D SDL? Good idea Doom in-game message routine in Wolf4SDL.

    Sponsored content


    [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL) Empty Re: [Coding Tutorial] Neat things to do with WSJ Ingame Messages and gamestate definitions (Wolf4SDL)

    Post by Sponsored content


      Current date/time is Thu Nov 21, 2024 6:57 am