[ZScript] Port of DaZombieKiller's footsteps

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by Hidden Hands »

ramon.dexter wrote:HiddenHands: Without seeing your whole wad, we cannot decide anything. Do you have the eventhandler also? Is the eventhandler registered in gameinfo block in mapinfo?
I have no event handler. I'm nit sure how they work or what to do with it. Footsteps is a single example of one thing I have no idea whatsoever where to start.
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by ramon.dexter »

Make a zscript file, put the footsteps code into it. Second, make a new zscript file and put the eventhandler code that I've quoted into it. Then include these files into tour main zscript file in pk3 root.

Then also, you need to have the steps sounds in your pk3 along with the language entried definig the steps sounds.

If you have any concers, download this: https://drive.google.com/file/d/1kaoNNf ... sp=sharing
Open it in slade and take a time to study how it's made. How I used the steps, how the eventhandlers are being registered in mapinfo and more. Sorry, but if you want to make games, you need to understand the internals. Learning any programming language is just the same as learning any foreign language. You have to understand it to actually use it. And zscript (or ACS, or any other programming language) is just the same as any foreign language.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by Hidden Hands »

I've been looking into all the stuff you showed me... far more confusing than I expected! Let me show you what I have so far.

Image

Image

Image

Am I on the right path? Looking into your WOSBETA it seems you have many event handlers and they are all stores in a zmapinfo. Does this make a difference?
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by ramon.dexter »

Again, open wos and look where are the eventhandlers placed EXACTLY! They are in gameinfo block! Why did you put it outside gameinfo block? The eventhandler parameter fits only into the gameinfo block and nowhere else. Stop rushing forward! And stop with the blind copy-pasting of things! You really have to understand things.
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by Hidden Hands »

Sorry I'm trying to follow your PK3, but I am unable to actually locate your EventHandler. I did check GAMEINFO but it only contains the games title and bootup colours. ZMAPInfo does contain information pertaining to the EventHandler, but I don't believe that's the same thing. I am trying to understand, but there is so much to these footsteps and for whatever reason, I'm not grasping it at all. I cannot believe how complex this is.
User avatar
ramon.dexter
Posts: 1529
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by ramon.dexter »

I didn't said anything about gameinfo lump...all the time I'm speaking about gameinfo BLOCK in mapinfo/zmapinfo. Do you know what is a 'block" called in programming languages? The 'block" is a part of text marked by brackets. It this case, the block looks like this:

Code: Select all

gameinfo {
    -->!when told to put inside gameinfo (block), you put it HERE! <--
}
--> !!!NOT HERE!!!! <--
So, for your case here, here is everything you need to make the zscript footsteps work:
file footsteps.zs

Code: Select all

class Footsteps : Actor
{
    //the player footsteps are attached to.
    PlayerPawn toFollow;

    array<string> fstep_sounds;
    array<int> fstep_textures;
    string fstep_default_sound;
    
    //VSO: only needed for debug.
    array<string> fstep_textures_names_debug;
    
    int next_update_tics_countdown;

    //attach PlayerPawn, load the texture/sound associated tables.
    void Init( PlayerPawn attached_player)
	{
        next_update_tics_countdown = -1;
        self.toFollow = attached_player;
        
        //Read SOUNDINFO and LANGUAGE to map textures on sounds.
        //only add to (fstep_sounds;fstep_textures) if the texture exist.
        array<String> sSTEP_FLATS_List; 
        
        StringTable.Localize("$STEP_FLATS").Split(sSTEP_FLATS_List, ":");
        //iterate over the list of flat names, and retreive  
        for (int i = 0; i < sSTEP_FLATS_List.Size(); i++) {
            
            String singleFLAT_Sound = StringTable.Localize(String.Format("$STEP_%s", sSTEP_FLATS_List[i]));
            
            if (singleFLAT_Sound.Length() != 0) {
                //check if the texture exists.
                textureid  tx_id = TexMan.CheckForTexture( sSTEP_FLATS_List[i],TexMan.TYPE_ANY);
                
                if (tx_id.Exists()) {
                    //texture exists, add both in the lists:
                    fstep_sounds.Push(singleFLAT_Sound);
                    fstep_textures.Push(int(tx_id));
                    
                    //also keep tx names, but it is only used for debugging.
                    fstep_textures_names_debug.Push(sSTEP_FLATS_List[i]);
                }
            }
        }
        // add fstep_default:
        fstep_default_sound = StringTable.Localize("$STEP_DEFAULT");
    }

    override void Tick()
	{  
        next_update_tics_countdown--;
        
        //0) do nothing until next_update_tics_countdown is below 0
        if (next_update_tics_countdown > 0) {
            Super.Tick();
            return;
        }
        
        //1) Update the Footstep actor to follow Player.
        SetOrigin(self.toFollow.pos, true);
        self.floorz = self.toFollow.floorz;
           
        double player_speed2d = sqrt(self.toFollow.vel.x * self.toFollow.vel.x + self.toFollow.vel.y * self.toFollow.vel.y);
        
        //2) Only play footsteps when on ground, and if the player is moving fast enough.
        if ((CVar.GetCvar("fs_enabled").GetInt() > 0) && (player_speed2d > 0.1) && (self.toFollow.pos.z - self.toFollow.floorz <= 0)) {
            
             //trace
             //Console.PrintF("Speed2d = %f",player_speed2d);
             
            //current floopic id for player:
            int player_floor_tx_id = int(self.toFollow.floorpic);
           
            //sound volume is amplified by speed.
            double soundLevel = CVar.GetCvar("fs_volume_mul").GetFloat() * player_speed2d;
                  
            //3) Find the matching index of player_floor_tx_id in fstep_textures and retreive the sound to play matching the texture we are in.
            int foundIndex  = fstep_textures.Find(player_floor_tx_id);
            
            if (foundIndex != fstep_textures.Size()) {
    
                //3-1) play the sound
                S_Sound(fstep_sounds[foundIndex], CHAN_AUTO, soundLevel);
                //Console.PrintF("Found tx = %s, play snd = %s",fstep_textures_names_debug[foundIndex], fstep_sounds[foundIndex]); 
            }
            else {
            
                //3-2) Play default sound if no match was found
                S_Sound(fstep_default_sound,  CHAN_AUTO, soundLevel);
                //Console.PrintF("Not found Tx ! , play default snd = %s",fstep_default_sound); 
            }
                          
            //4) Compute the next date at which playing a sound step again.
            //clamp the apparent maximum speed, to limit sound repetition interval.         
            if (player_speed2d > 5.0) {
                player_speed2d = 5.0;
            }
            //fastest sound playing speed is set to roughly 0.3s => 10 ticks ( * fs_delay_mul)
            next_update_tics_countdown = (35.0 - ((25.0 / 5.0) * player_speed2d)) * CVar.GetCvar("fs_delay_mul").GetFloat();
           
        } else {
            // no need to poll for change too often
            next_update_tics_countdown = 2;
        }
        
        Super.Tick();
    }  
}
class footStepEventHandler : EventHandler
{
        override void PlayerEntered(PlayerEvent e)
   {
      let player = PlayerPawn(players[e.PlayerNumber].mo);
      //BEGIN VSO : Some Wads crash here with VM Abort because player can be NULL
      if (player == NULL) {
         return;
      }
      //END VSO

              //VSO: Attach footsteps to player:
               Footsteps fsteps = Footsteps(Actor.Spawn("Footsteps",player.pos));
          fsteps.Init(player);
     }
}
and inside mapinfo/zmapinfo gameinfo block

Code: Select all

Gameinfo {
    AddEventHandlers = "footStepEventHandler"
}
But keep in mind if you already have a gameinfo block somewhere in you mapinfo, just put it INSIDE THE BRACKETS. Aand, as I've seen you files, please, look carefully for all occurences of gameinfo in the mapinfo and make it one block, okay? This way you can avoid many errors and bugs.
SanyaWaffles
Posts: 805
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: [ZScript] Port of DaZombieKiller's footsteps

Post by SanyaWaffles »

Judging by what I've seen in the project, your project is very disorganized, Hidden Hands. It could benefit from having a better structure.

I usually store everything Zscript in designated folders (enemies, players, props, effects, etc) and files within, and I split up the MAPINFO into it's own files, and included them in the main file, for the sake of readability - not just for myself, but for others who are helping. Like having an included mapinfo file located in the mapinfo folder called 'gi.txt' for gameinfo. I put all stuff related to the gameinfo data there.

Also, sometimes other people's code can't work by just dropping it into an existing project or copy/pasting it, sometimes it requires a bit the old elbow grease and some changes to be made.

Any code I've used in the past usually requires me doing anything from changing a few variable names and types to integrate with my project better, to completely rewriting it and/or gutting it to only use the parts I need. An example was an old version of Mikk's headshots, which I repurposed to make custom hitboxes for things like corpses or non-standard shaped objects. That wouldn't have worked as a drop in solution as his code was not meant to be used as I used it - I don't even use that version of his project for actual headshots.

Long of the short of it: I seriously recommend cleaning up your project a bit going forward, or at least organizing it, if you want people to be able to help you.
Post Reply

Return to “Script Library”