Page 1 of 2

Time and pushing the keys

Posted: Sun Jul 27, 2008 5:39 pm
by Danimita92
Hello everybody. I've opened this topic because I'm creating a simple "melee combo system" tutorial for the people in the spanish forum, but I've reached a point where things that shouldn't be happening are happening. What this combo system is, is that you hit the action key (left mouse) once, and the scripted player will attack. If you hit it again, it does a different attack, and so on. But, I want it that if you do a "two-attacks" combo, that if a few seconds pass and you haven't hit the attack button, that the combo goes back to attack number one, instead of doing the third attack half an hour after doing the second one.

Code: Select all

Combo[()
{
    if(self.key_pressed = K_FIRE)
    {
        if(COMBO=0)
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Walk", 1, true, "");
            COMBO=1;
        }
    }
    if(self.key_pressed=K_FIRE)
    {
        if(COMBO=1)
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Run", 1, true, "");
            COMBO=2;
            
        }
    }
    if(self.key_pressed = K_FIRE)
    {
        if(COMBO=2)
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Jump", 1, true, "");
            COMBO=0;
        }
    }
    if(not self.key_pressed = K_FIRE)
    {
        if(self.animate_at_end = true)
        {
            COMBO=0;
            LowLevel("RunPlayer");
            return 0;
        }
    }
}]
But what happens here is that if I hit the key once, it'll directly do the first, second and third attack, and stop there, even if I'm not hitting that key anymore. (COMBO always starts at 0 BTW)

Re: Time and pushing the keys

Posted: Sun Jul 27, 2008 5:51 pm
by Kiji8989
Thats a good tut! I'll keep that in mind whne I make my videogame!

Re: Time and pushing the keys

Posted: Sun Jul 27, 2008 6:37 pm
by Juutis
To me it seems like all the if-statements are true during one frame. First it checks if the key is pressed and COMBO = 0, then sets COMBO = 1. And moves on to the next part, and because COMBO = 1 now it sets COMBO = 2 and so on. You could add 'return 0;' to each of the if-statements to start executing the order from the beginning again. Or you could use 'switch':

Code: Select all

if(self.key_pressed = K_FIRE)
{
   switch(COMBO)
   {
        case 0
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Walk", 1, true, "");
            COMBO=1;
        }
        case 1
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Run", 1, true, "");
            COMBO=2;
        }
        case 2
        {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Jump", 1, true, "");
            COMBO=0;
        }
    }
}

Re: Time and pushing the keys

Posted: Sun Jul 27, 2008 8:03 pm
by Jay
You should use the 'return' keyword, which makes the game skip the rest of the function.

so after you set

COMBO=1;

you must use something like

return 1;

then the rest of the function is not executed and you have no problem anymore.

Re: Time and pushing the keys

Posted: Mon Jul 28, 2008 12:50 am
by Danimita92
Thanks for the help. Okay, I tried putting 'return 0;' after every COMBO = number; but it kept playing over and over the first animation, instead of finishing it and leaving that order. Then I tried putting return 1; after 'COMBO=1;' and return 2; after 'COMBO = 2' instead of the previous return 0; but it didn't help, same problem.
Then I tried with the switches. This sort of helped, actually. Now it plays the first animation, then the pawn freezes at the end of the animation and nothing happens (console says the name of the pawn, the order "Combo" and then it says BlendToAnimation.) I then tried using the switch AND the return 0; but it stayed the same. So I left it like this:

Code: Select all

Combo[()
{
    if(self.key_pressed = K_FIRE)
    {
        switch(COMBO)
        {
            case 0
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Walk", 1, false, "");
            COMBO=1;
            }
            case 1
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Run", 1, true, "");
            COMBO=2;
            }
            case 2
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Jump", 1, true, "");
            COMBO=0;
            }
        }
    }
    else
    {
        if(self.animate_at_end = true)
        {
            COMBO=0;
            LowLevel("RunPlayer");
            return 0;
        }
    }
}]

Re: Time and pushing the keys

Posted: Mon Jul 28, 2008 9:13 pm
by Graywolf
This is low-level and being executed every frame, correct? Try adding ThinkTime = 0.2; to the beginning. I'm willing to bet good money that it rolls through all three cases in three frames, faster than the eye can see.

Edit: You can test this by adding debug(COMBO) to each case. If it dumps 1, 2, 3 when you hit the button, then there's your problem.

Re: Time and pushing the keys

Posted: Mon Jul 28, 2008 10:36 pm
by Danimita92
It is High Level. It plays the first animation and then freezes at the end of it. It doesn't get to the second or third animations

Re: Time and pushing the keys

Posted: Tue Jul 29, 2008 2:46 am
by Graywolf
Okay, can you post the script?(Or is it a mod of one of the sample scripts?) I need to see the big picture on this.

Note: Things like this are much easier accomplish in low-level.

Re: Time and pushing the keys

Posted: Tue Jul 29, 2008 12:46 pm
by Danimita92
If you hit the left click, the script goes to high level and to this order:

Code: Select all

Combo[()
{
    if(self.key_pressed = K_FIRE)
    {
        switch(COMBO)
        {
            case 0
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Walk", 1, false, "");
            COMBO=1;
            }
            case 1
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Run", 1, true, "");
            COMBO=2;
            }
            case 2
            {
            FireProjectile("10mm_shell", "Hand_R", 0, 10, 20, "health", "");
            BlendToAnimation("Jump", 1, true, "");
            COMBO=0;
            }
        }
    }
    else
    {
        if(self.animate_at_end = true)
        {
            COMBO=0;
            LowLevel("RunPlayer");
            return 0;
        }
    }
}]

Re: Time and pushing the keys

Posted: Tue Jul 29, 2008 1:16 pm
by Graywolf
Right... I mean, can you post the whole script(attachment would be best, less topic clutter), because the problem may extend beyond just this order.

Re: Time and pushing the keys

Posted: Tue Jul 29, 2008 4:11 pm
by Danimita92
Why would it? Oh, well, here it is:

Code: Select all

Removed to save space
(I couldn't manage to upload it as an attachment)

Re: Time and pushing the keys

Posted: Tue Jul 29, 2008 7:02 pm
by Graywolf
Okay, it's like I thought. When you go to high-level from run-player, it never goes back to low-level to call combo again. So, it does the first combo case, then it's dead in the water. Add RestartOrder() at the end of combo.

PS: To upload as attachment, compress to a .zip first.

EDIT: RestartOrder() won't completely fix the problem. If they hold the key down, the combo will proceed automatically. And if they aren't holding the key right when the animation ends, the combo will end... Also, IsKeyDown(key_number) works better than using the key_pressed variable. The key_pressed value is only one key, when several might be being pushed.

Re: Time and pushing the keys

Posted: Wed Jul 30, 2008 12:07 am
by Danimita92
Lol, and I was about to leave a message thanking you when I read the EDIT. Yes, it's true. I'll try fixing this problem, and maybe start by changing it to a Low Level order (never liked using High Level anyway)

EDIT: Can switches be used in LowLevel?

Re: Time and pushing the keys

Posted: Wed Jul 30, 2008 12:59 am
by Graywolf
Danimita92 wrote:Can switches be used in LowLevel?
Yep. It's a Simkin internal command, so it can be used in any script. Just out of curiosity, have you read the Simkin docs(not the RF docs, the official Simkin docs)? If not, I'd strongly suggest it.

Re: Time and pushing the keys

Posted: Wed Jul 30, 2008 9:27 pm
by Danimita92
And I was about to write to thank you :lol:
Anyway, now when I hit the left click (activates the combo) the screen goes black and the famous "send a report?" message comes up.
This is how I left the combo order (the HighLevel command that leads to this order was replaced with a self.think = "Combo"; )

Code: Select all

Combo[()
{
    if(IsKeyDown(K_FIRE)) 
    {
        switch(COMBO) 
        {
            case 0 
            {
            FireProjectileBlind("10mm_shell", "Hand_R", 0, 10, 20, "health"); 
            AnimateBlend("Walk", 1); 
            COMBO=1; 
            }
            case 1 
            {
            FireProjectileBlind("10mm_shell", "Hand_R", 0, 10, 20, "health"); 
            AnimateBlend("Run", 1);
            COMBO=2;
            }
            case 2 
            {
            FireProjectileBlind("10mm_shell", "Hand_R", 0, 10, 20, "health"); 
            AnimateBlend("Jump", 1);
            COMBO=0;
            }
        }
    }
    else 
    {
        if(self.animate_at_end = true) 
        {
            COMBO=0;
            self.think="RunPlayer";
            return 0;
        }
    }
    self.ThinkTime=1;
}]

}
And the RealityFactory.log =

Code: Select all

Searching for fullscreen driver

Initializing Game Shell...
--------------------------------------
--- Reality Factory 0.75C          ---
--- For more Information, visit:   ---
---    www.realityfactory.info     ---
--------------------------------------

Parsed RealityFactory.ini file

Genesis3D Initialized

*INFO* VFS detected (not encrypted)...

Initializing Camera Manager...
Initializing User Input Subsystem...
Initializing Audio Manager Subsystem...
Initializing CD Audio Manager Subsystem...
Initializing Midi Audio Manager Subsystem...
Initializing RF Menu Manager Subsystem...
Initializing Network...
Loading Menu.ini...
Parsing Menu.ini...
Loading Character.ini...
Initializing Menu
Initializing Collision Manager Subsystem...
Initializing Network Manager Subsystem...
Initializing AVIFile Video Subsystem...
Launching Reality Factory Game Shell...
Launching Preview from Editor, bypassing Genesis3D Logo for DEBUG purposes ONLY...
Previewing Level as SinglePlayer Client...
Entering CRFMenu::ProcessMenu
Entering Windows Message Loop, Rendering Game Menu
Entering CRFMenu::ProcessMenu
Entering Windows Message Loop, Rendering Game Menu
Initializing Level: rfeditpro1.bsp
Configuring Camera Defaults...
Initializing Entity Registry...
Initializing Terrain Manager...
Initializing Effects Manager...
Initializing Actor Manager...
Parsing Environment Setup Entity...
Initializing Model Manager...
Creating Player Avatar...
Loading Player Avatar...
Initializing HUD...
Initializing Damage Subsystem...
Initializing FixedCamera Manager Subsystem...
Loading Player Configuration...
Loading Attributes and Player Configuration from PlayerSetup.ini
Loading Environmental Audio
Parsing PlayerSetup Entity
Initialize Player Data
Parsing EnvironmentSetup Entity
Initializing Automatic Door Manager Subsystem...
Initializing Moving Platform Manager Subsystem...
Initializing Teleport Manager Subsystem...
Initializing MorphingField Effects Manager Subsystem...
Initializing 3d AudioSource Manager Subsystem...
Initializing Particle Effects Manager Subsystem...
Initializing Static Entity Props Subsystem...
Initializing Static Mesh Subsystem...
Initializing Soundtrack Toggle Subsystem...
Initializing Streaming Audio Manager Subsystem...
Initializing Video Texture Manager Subsystem...
Initializing Corona Manager Subsystem...
Initializing Dynamic Light Manager Subsystem...
Initializing ElectricBolt Manager Subsystem...
Initializing Procedural Texture Manager Subsystem...
Initializing Path Database...
Initializing Path Followers...
Initializing Rain Effects Manager...
Initializing Spout Effects Manager...
Initializing ActorSpout Effects Manager...
Initializing Floating Particle Effects Manager...
Initializing eChaos Effects Manager...
Initializing Flame Effects Manager...
Initializing ScriptPoint Manager Subsystem...
Initializing Pawn Manager Subsystem...
Initializing ChangeAttribute Manager Subsystem...
Initializing Countdown Manager Subsystem...
Initializing Trigger Manager Subsystem...
Initializing LogicHandler Subsystem...
Initializing Message Manager Subsystem...
Initializing Effect Manager Subsystem...
Initializing Weapon Manager Subsystem...
Initializing FirePoint Manager Subsystem...
Initializing Flipbook Manager Subsystem...
Initializing AreaCheck Manager Subsystem...
Initializing Foliage Manager Subsystem...
Initializing Tree Manager Subsystem...
Initializing PWXImage Manager Subsystem...
Initializing Shadow Manager Subsystem...
Initializing Decal Manager Subsystem...
Initializing WallDecal Manager Subsystem...
Initializing LevelController Manager Subsystem...
Initializing Attribute Manager Subsystem...
Initializing Explosion Manager Subsystem...
Initializing Explosion Subsystem...
Initializing ChangeLevel Manager Subsystem...
Initializing ScreenShake Subsystem...
Initializing ViewSwitch Subsystem...
Initializing Inventory Subsystem...
Initializing Liquid Subsystem...
Initializing Overlay Subsystem...
Initializing TextureMorph Subsystem...
Initializing CutScene Subsystem...
Initializing ActorMaterial Subsystem...
Initializing Armour Subsystem...
Initializing LiftBelt Manager...
Initializing CDSpotlight Manager...
Initializing CurvedSurfaces Manager...
Initializing Fonts...
Preparing to Launch Game...
CRFMenu::GameLoop() - Setup and Run Level
CRFMenu::GameLevel() - Entering Inner Game Loop