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...


2 posters

    [solved]How to - Player throws something

    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty [solved]How to - Player throws something

    Post by Josip_2P2 Wed Sep 16, 2020 3:54 am

    So, hello, I dont see that anyone is creating some beginners HowTo topics here like me. Surely cause this is an old game and mostly all that kind of topics goes to year 2007 idk, and ofc I started with this kind of modding since last year (and my english is not very well lol). I dont care if that all is wierd, stupid or something, all that is matters to me that it's ok to post topics like this here and that you can understand enough my bad english. XD bla bla bla

    Finally, just let me understand some pieces of wolf3d code here, ok.

    Now, I searched ofc for this topic on other forums which are related to w3d. With no success.I also tried to do my own code, but with no success.

    Ok, I know about adding new weapons, but only I need here is code snippet(s) in which player is throwing flame, rockets or something else, just like Schabbs or Otto, Fat, Fake Hitler etc...

    I think it is clear what I am looking for.

    Thank you for understanding me.


    Last edited by Josip_2P2 on Fri Sep 18, 2020 5:49 am; edited 1 time in total
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Wed Sep 16, 2020 9:17 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:50 pm; edited 1 time in total
    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Thu Sep 17, 2020 5:39 am

    Wolf3DGuy wrote:http://dhw.wolfenstein3d.com/viewtopic.php?t=2904

    This might be helpful!
    I didn't try this one, but yeah, this is what I was looking for, it might be very helpful. Thanks!
    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Thu Sep 17, 2020 9:45 am

    This is for anyone who needs help with that, cause in that link above, there was some errors, so I made some changes that this code works exactly it should...

    WL_DEF.H

    Add new projectile object for player below rocketobj in classtype structure:
    Code:
    bjfireobj,




    WL_AGENT.CPP:

    Put this at the top of the file with other definitions:
    Code:
    extern statetype s_fire1;

    Change weapon behavior in attackinfo (a 2nd line, in this case wp_pistol will be used for throwing projectiles):
    Code:
    { {6,0,1},{6,5,2},{6,0,3},{6,-1,2} },

    Add this above KnifeAttack function:
    Code:
    void ProjectileAttack (objtype *ob)
    {
       if (!gamestate.ammo)
       {
          return;
       }

      madenoise = true;

       SD_PlaySound (FLAMETHROWERSND);

       GetNewActor ();

       newobj->state = &s_fire1;
       newobj->ticcount = 1;

       newobj->x = ob->x ;
       newobj->y = ob->y ;
       newobj->tilex = newobj->x >> TILESHIFT;
       newobj->tiley = newobj->y >> TILESHIFT;

       newobj->obclass = bjfireobj;
       newobj->dir = nodir;
       newobj->angle = ob->angle;
       newobj->speed = 0x4200l;
       newobj->flags = FL_NEVERMARK;
       newobj->active = ac_yes;
    }

    In T_Attack in the switch statement add case 5 like this:
    Code:
    case 5:
                    ProjectileAttack (ob);
                    if (!ammocheat)
                        gamestate.ammo--;
                    DrawAmmo ();
                    break;

    WL_ACT2.CPP:

    Put this at the top of the file with other BJ.. definitions:
    Code:
    #define BJROCKETSIZE    0x6000l

    Replace T_Projectile function with this:
    Code:
    void T_Projectile (objtype *ob)
    {
       long   deltax,deltay;
       int      damage;
       long   speed;
       objtype *check, *extracheck;

       speed = (long)ob->speed*tics;

       deltax = FixedMul(speed,costable[ob->angle]);
       deltay = -FixedMul(speed,sintable[ob->angle]);

       if (deltax>0x10000l)
          deltax = 0x10000l;
       if (deltay>0x10000l)
          deltay = 0x10000l;

       ob->x += deltax;
       ob->y += deltay;

       if (!ProjectileTryMove (ob))
       {
          if (ob->obclass == rocketobj)
          {
             PlaySoundLocActor(MISSILEHITSND,ob);
             ob->state = &s_boom1;
          }
    #ifdef SPEAR
          else if (ob->obclass == hrocketobj)
          {
             PlaySoundLocActor(MISSILEHITSND,ob);
             ob->state = &s_hboom1;
          }
    #endif
          else
             ob->state = NULL;      // mark for removal

          return;
       }

        if (ob->obclass == bjfireobj)
        {
            check = objlist ;
            while (check)
            {
                if (check->flags & FL_SHOOTABLE)
                {
                    deltax = LABS(ob->x - check->x);
                    deltay = LABS(ob->y - check->y);

                    if (deltax < BJROCKETSIZE && deltay < BJROCKETSIZE)
                    {
                        /*if (ob->obclass == bjrocketobj)
                      {
                         PlaySoundLocActor(MISSILEHITSND,ob);
                         ob->state = &s_boom1;
                      }
                #ifdef SPEAR
                      else if (ob->obclass == bjhrocketobj)
                      {
                         PlaySoundLocActor(MISSILEHITSND,ob);
                         ob->state = &s_hboom1;
                      }
                #endif
                      else*/
                         ob->state = NULL;      // mark for removal


                        DamageActor (check, 25);
                    }
                }
                check = check->next ;
            }
        }
        else
        {
            {
                // Check if player hit by anything
                deltax = LABS(ob->x - player->x);
                deltay = LABS(ob->y - player->y);

                if (deltax < PROJECTILESIZE && deltay < PROJECTILESIZE)
                {   // hit the player
                    switch (ob->obclass)
                    {
                        case needleobj:
                            damage = (US_RndT() >>3) + 20;
                            break;
                        case rocketobj:
                        case hrocketobj:
                        //   case sparkobj:
                            damage = (US_RndT() >>3) + 30;
                            break;
                        #ifdef SPEAR
                        case sparkobj:
                            damage = (US_RndT() >> 3) + 30;
                            break;
                        #endif
                        case fireobj:
                            damage = (US_RndT() >>3);
                            break;
                    }

                    TakeDamage (damage,ob);
                    ob->state = NULL;      // mark for removal
                    return;
                }
            }

        ob->tilex = ob->x >> TILESHIFT;
        ob->tiley = ob->y >> TILESHIFT;
        }
    }


    Of course, this could be easily changed with some new weapons, projectiles, but that is some another topic.

    I hope this should help (for anyone who is interested).

    Bye.


    Last edited by Josip_2P2 on Fri Sep 18, 2020 1:16 pm; edited 9 times in total
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


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

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Mega Luigi Thu Sep 17, 2020 3:35 pm

    Btw, just thought I should mention, there's barely any difference at all regarding how player projectiles are treated when compared to enemies', so pretty much everything you do for one will also work for the other. And if you need any help trying to understand any specific part of the code you posted, let me know. 

    For example, I noticed you used the s_boom state for the fire, which I assume is a fake-hitler-kind-of-fire, right? Anyway, if that's what you wanted to do, don't mind me too much, but feel free to ask if you have any more questions Razz

    Josip_2P2 likes this post

    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Fri Sep 18, 2020 5:42 am

    I appreciate any help, thanks!

    If I understood you well, you are trying to say that in this code above, player projectile's behavior is not as it should be (compared to same projectiles from specified enemy - fakehitler) and that in the code the specific projectile's behavior(needle, spark, rocket, fire...) is not specified.

    Btw, I saw some more code holes yesterday, and I edited that and tried the code for different projectiles from the game (needle, fire, (h)rocket, spark - including different speed, sound, enemy damage value etc. depending on specific projectile) and everything works fine.
    There was also a glitch with doors which can't be closed when their adjacent walls are hitted by player's projectiles, because in T_Projectile "ob->state = NULL;" was missed. I think that this is the cause of that glitch.

    I edited the code from the previous post today. If there is something more strange in the code, let me know.

    [EDIT]

    I was wrong about that doors glitch. It is not about adjacent walls, that glitch appears when projectile hits the doors which are in opening/closing process was thrown/created on the door gates. And the doors can be closed again when player throws another projectile. Probably, there are projectile remains in doors - similar case is with guards corpses in the doors gate where doors can't be closed. Maybe something needs to be changed in WL_ACT2.cpp  T_Projectile function, I thought that "ob->state = NULL;" will solve this but that is not the solution.
    Or is there a way to destroy that invisible projectile object or remove his references. Shocked Sweating Laughing


    Last edited by Josip_2P2 on Fri Sep 18, 2020 9:16 am; edited 2 times in total
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Fri Sep 18, 2020 9:02 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:50 pm; edited 1 time in total
    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Fri Sep 18, 2020 9:15 am

    Wolf3DGuy wrote:To solve this problem, in your ProjectileAttack function
    Code:
    newobj->flags = FL_NONMARK | FL_BONUS;

    should be

    Code:
    newobj->flags = FL_NEVERMARK;

    Do the same in WL_ACT2 also in the T_SchabbThrow, T_FakeFire, T_GiftThrow and probably T_FatThrow functions, but I am not sure if the latter actually exist, it is declared, but fatface is using the T_GiftThrow function as well, if I know that right. If you're working with the SPEAR code then do not forget to do the same in T_Launch as well.

    Nope. With FL_NEVERMARK, projectile damages the player.
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Fri Sep 18, 2020 9:30 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:50 pm; edited 1 time in total
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Fri Sep 18, 2020 9:57 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:49 pm; edited 1 time in total
    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Fri Sep 18, 2020 10:12 am

    Wolf3DGuy wrote:Try this in WL_ACT2's T_Projectile function and change this line

    Code:
    if (ob->obclass == fireobj && ob->flags & FL_NONMARK && ob->flags & FL_BONUS)

    to this

    Code:
    if (ob->obclass == fireobj)
    Yeah maybe that solve the first problem, but obviously there comes another one - the enemy is not throwing his projectile cause with that the ELSE condition goes "If it is not a fireobj". That ELSE block is for enemies.

    This below is that ELSE block (in WL_ACT2 T_Projectile function):
    Code:
    else
    {
            {
                // Check if player hit by anything
                deltax = LABS(ob->x - player->x);
                deltay = LABS(ob->y - player->y);

                if (deltax < PROJECTILESIZE && deltay < PROJECTILESIZE)
                {   // hit the player
                    switch (ob->obclass)
                    {
                        case needleobj:
                            damage = (US_RndT() >>3) + 20;
                            break;
                        case rocketobj:
                        case hrocketobj:
                        case sparkobj:
                            damage = (US_RndT() >>3) + 30;
                            break;
                        case fireobj:
                            damage = (US_RndT() >>3);
                            break;
                    }

                    TakeDamage (damage,ob);
                    ob->state = NULL;      // mark for removal
                    return;
                }
            }

        ob->tilex = ob->x >> TILESHIFT;
        ob->tiley = ob->y >> TILESHIFT;
    }

    I knew it that there will be complications with this stupid problem. I'm too bit confused now. Feel is like - too little problem, but too many posts(and my post edits).
    I also tried to change some door behavior, but I only found this with whom idk what to do:

    Code:
    if (actorat[tilex][tiley])
            return;"

    Btw, I found some interesting mods on some youtube channel:
    https://www.youtube.com/watch?v=sc9gOevAI-w

    This is what I am looking for (if that weapons works with doors properly XD).

    Is this your channel (cause it is the same name)?
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Fri Sep 18, 2020 10:14 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:49 pm; edited 1 time in total
    avatar
    Josip_2P2
    Freshmen
    Freshmen


    Number of posts : 17
    Age : 29
    Location : Croatia
    Hobbie : Modding
    Registration date : 2019-02-04

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Josip_2P2 Fri Sep 18, 2020 10:16 am

    Wolf3DGuy wrote:I would say you probably should add new objects for the player, like bjfireobj and add that for the objclass in WL_AGENT and in WL_ACT2 you probably should use this

    Code:
        if (ob->obclass == bjfireobj)
        {
            for (check = player->next; check; check = check->next)
            {
                if (check->flags & FL_SHOOTABLE)
                {
                    deltax = LABS(ob->x - check->x);
                    deltay = LABS(ob->y - check->y);

                    if (deltax < BJFIRESIZE && deltay < BJFIRESIZE)
                    {
                        ob->state = NULL;
                        DamageActor (check, 5);
                        return;
                    }
                }
            }
        }

    EDIT: You can use BJROCKETSIZE instead of BJFIRESIZE and change the number in DamageActor from 5 to 25.
    Yeah, that is some another way which will probably bypass all of that complication. I was too bit focused on this old way. Thanks.

    [EDIT]

    I tried with new projectile objects and finally, I think that everything is fine now. Of course, my post with the tutorial code is updated now.
    avatar
    Guest
    Guest


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Guest Fri Sep 18, 2020 10:52 am

    .


    Last edited by Wolf3DGuy on Wed Feb 16, 2022 1:49 pm; edited 1 time in total
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


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

    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Mega Luigi Fri Sep 18, 2020 2:37 pm

    Josip_2P2 wrote:I appreciate any help, thanks!

    If I understood you well, you are trying to say that in this code above, player projectile's behavior is not as it should be (compared to same projectiles from specified enemy - fakehitler) and that in the code the specific projectile's behavior(needle, spark, rocket, fire...) is not specified.

    Btw, I saw some more code holes yesterday, and I edited that and tried the code for different projectiles from the game (needle, fire, (h)rocket, spark - including different speed, sound, enemy damage value etc. depending on specific projectile) and everything works fine.
    There was also a glitch with doors which can't be closed when their adjacent walls are hitted by player's projectiles, because in T_Projectile "ob->state = NULL;" was missed. I think that this is the cause of that glitch.

    I edited the code from the previous post today. If there is something more strange in the code, let me know.

    [EDIT]

    I was wrong about that doors glitch. It is not about adjacent walls, that glitch appears when projectile hits the doors which are in opening/closing process was thrown/created on the door gates. And the doors can be closed again when player throws another projectile. Probably, there are projectile remains in doors - similar case is with guards corpses in the doors gate where doors can't be closed. Maybe something needs to be changed in WL_ACT2.cpp  T_Projectile function, I thought that "ob->state = NULL;" will solve this but that is not the solution.
    Or is there a way to destroy that invisible projectile object or remove his references. Shocked Sweating Laughing

    No no, I just meant that I was not sure you actually wanted to have the s_boom state for your fire (which is the "boom" statements used for rockets). There's nothing that's inherently wrong so you're free to do as you please! Smile

    Just as a general comment, it's nice to see that you're actually making an effort to try to understand what's going on. While just following tutorials can get you quite far, it's nothing compared to what you can do when you truly get what's happening. So, again, if you need any specific help as to why something is the way it is, or to understand some specific part of the code, I'm here to help

    Josip_2P2 likes this post


    Sponsored content


    [solved]How to - Player throws something Empty Re: [solved]How to - Player throws something

    Post by Sponsored content


      Current date/time is Wed Oct 30, 2024 7:06 am