• View unanswered postsView active topics

  • [tutorial] Interact with guards using Spacebar

    Discuss Wolf3D and Wolf3D modding/ports

    Postby Tricob1974 01 Dec 2011, 03:41

    In this tutorial, you'll be able to "identify" any guard in front of you by pressing the Spacebar. This code can possibly be used as a base for the "Informant Interaction" feature in Blake Stone.

    The tutorial assumes you have WSJ's In-game Messages feature working. But the code can easily be changed to accomodate a different feature.

    First, go into WL_AGENT.CPP. Do a search for "elevatorok". You should see this code:

    Code: Select all
    void Cmd_Use (void)
    {
        int     checkx,checky,doornum,dir;
        boolean elevatorok;

    Insert this code just below it:
    Code: Select all
        int32_t  dist=0x7fffffff;
        objtype *closest = NULL;

        for (objtype *check=player->next; check; check=check->next)
        {
            if ( (check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE)
                && abs(check->viewx-centerx) < shootdelta)
            {
                if (check->transx < dist)
                {
                    dist = check->transx;
                    closest = check;
                }
            }
        }

    Now do a search for "leveldone". You should see this code:
    Code: Select all
            SD_PlaySound (LEVELDONESND);
            SD_WaitSoundDone();
        }

    Insert this code just below it:
    Code: Select all
        else if (closest && dist <= 0x18000l && !buttonheld[bt_use])
           {
                 switch (closest->obclass)
                        {
                        case guardobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm a guard.");
                             break;
                        case officerobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm an Officer.");
                             break;
                        case mutantobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm a Mutant.");
                             break;
                        case ssobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm an SS.");
                             break;
                        case dogobj:
                             buttonheld[bt_use] = true;
                             GetMessage("Woof!");
                             break;
                        }
           }

    Note that if you don't have WSJ's In-game Messages feature enabled, just replace each "GetMessage" line with something else. :)

    This routine is actually just a cheap hack of the T_KnifeAttack code, but I optimized it somewhat. Hope it's useful to someone. :)
    Tricob1974

     
    Posts: 1388
    Location: Huntsville, Alabama

        

    Postby WolferCooker 01 Dec 2011, 07:24

    Nice work Tricob!

    I played around with this code and it turns out you can emphasize it by adding some sound to it as well. It's pretty easy to do. Just add an SD_PlaySound (); in each case as all the sounds are already defined in audiowl6.h.

    Here's an example.

    Code: Select all
    else if (closest && dist <= 0x18000l && !buttonheld[bt_use])
           {
                 switch (closest->obclass)
                        {
                        case guardobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm a guard.");
                             SD_PlaySound (HALTSND);
                             break;
                        case officerobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm an Officer.");
                             SD_PlaySound (SPIONSND);
                             break;
                        case mutantobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm a Mutant.");
                             SD_PlaySound (AHHHGSND);
                             break;
                        case ssobj:
                             buttonheld[bt_use] = true;
                             GetMessage("I'm an SS.");
                             SD_PlaySound (SCHUTZADSND);
                             break;
                        case dogobj:
                             buttonheld[bt_use] = true;
                             GetMessage("Woof!");
                             SD_PlaySound (DOGBARKSND);
                             break;
                        }
           }


    So not only the message will pop up, but a sound will play as well.
    WolferCooker
    User avatar

     
    Posts: 164
    Location: Bethlehem, Pennsylvania

        

    Postby Tricob1974 02 Dec 2011, 02:23

    That it will, but since you usually can't "interact" with the guards unless they're standing there attacking you, it's just another sound mixed with lots and lots of enemy gunshots. :)
    Tricob1974

     
    Posts: 1388
    Location: Huntsville, Alabama

        

    Postby WolferCooker 02 Dec 2011, 02:45

    True, but you can at least make them pretend they're talking to you directly (if you don't die first that is). LOL!
    WolferCooker
    User avatar

     
    Posts: 164
    Location: Bethlehem, Pennsylvania

        


    Return to General Wolf3D/modding Discussion and tutorials


    Who is online

    Users browsing this forum: No registered users and 1 guest