Shkwarkel Posted November 24, 2023 (edited) 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 November 26, 2023 by Shkwarkel 1 Quote Share this post Link to post
Rifleman Posted November 24, 2023 (edited) 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 November 24, 2023 by Rifleman 2 Quote Share this post Link to post
Shkwarkel Posted November 24, 2023 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 1 Quote Share this post Link to post
Mordeth Posted November 24, 2023 1 hour ago, Shkwarkel said: SetActorProperty That works for monsters. Never set player's health by SetActorProperty, use HealThing instead. 2 Quote Share this post Link to post
Shkwarkel Posted November 24, 2023 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. 0 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.