Jump to content

Button sticking when pressed [SOLVED]


Shkwarkel

Recommended Posts

Problem:

I want to make pressing the Q key restore health by 20 points. But when I press Q, the script starts adding 20 points to health and I don't know how to stop it. Please help

 

Code KEYCONF:

addkeysection "My Keysection" MySampleKeysection

 

   addmenukey "User action 1" my_userbind1
   
   alias my_userbind1 "+user1"

 

   defaultbind q my_userbind1

 

Code SCRIPTS:

script 1 ENTER
{
    int health = GetActorProperty(0, APROP_HEALTH);
    while(true)
    {
        int buttons;
        buttons = GetPlayerInput(-1, INPUT_BUTTONS);
        if (buttons & BT_USER1)
        {
            Print(s:"Hello");
            SetActorProperty(0, APROP_Health, health + 20);
        }

        Delay(1);

   }

}

Edited by Shkwarkel

Share this post


Link to post

You can run a script using KEYCONF definition like this: alias my_userbind1 "pukename ScriptName; +user1" (if you use numbers for scripts, then it's just puke 1 for example)

 

Then you can change the script to just add the health without needing that loop at all:
 

script "ScriptName" (void)
{
    int health = GetActorProperty(0, APROP_HEALTH);
	SetActorProperty(0, APROP_Health, health + 20);
}

 

Edited by Rifleman

Share this post


Link to post
28 minutes ago, Rifleman said:

You can run a script using KEYCONF definition like this: alias my_userbind1 "pukename ScriptName; +user1" (if you use numbers for scripts, then it's just puke 1 for example)

 

Then you can change the script to just add the health without needing that loop at all:
 


script "ScriptName" (void)
{
    int health = GetActorProperty(0, APROP_HEALTH);
	SetActorProperty(0, APROP_Health, health + 20);
}

 

Its working! Thank you

Share this post


Link to post
9 hours ago, Mordeth said:

 

That works for monsters. Never set player's health by SetActorProperty, use HealThing instead. 

Could there be any problems? Everything seems to be working fine after a few tests. But thanks for the message, if something goes wrong I will try to change the code.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...