Frictional Games Forum (read-only)
Trigger script when using any laudanum - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Trigger script when using any laudanum (/thread-15894.html)

Pages: 1 2


Trigger script when using any laudanum - Damascus - 06-06-2012

As the title says, how can i trigger a script any time the player uses a laudanum to recover health?


RE: Trigger script when using any laudanum - Adny - 06-06-2012

AddUseItemCallback using the exact name of the laudanum in the level editor?


RE: Trigger script when using any laudanum - Datguy5 - 06-06-2012

I was wondering this too..But i didnt bother making a thread :/


RE: Trigger script when using any laudanum - Damascus - 06-06-2012

(06-06-2012, 10:11 AM)andyrockin123 Wrote: AddUseItemCallback using the exact name of the laudanum in the level editor?
I want it to be able to work with any laudanum, not just one. Especially since they stack and you're not sure which one you're using.


RE: Trigger script when using any laudanum - Adny - 06-06-2012

Okay, I just so happen to be an expert in this subject. (Not really, but I did recently learn the "for" loop)

From my very basic understanding of the for loop, I came up with this for your script:

for(int i=1;i<=7;i++)
AddUseItemCallback(string& asName, string& asItem, string& asEntity, string& asFunction, bool abAutoDestroy);


replace the 7 in "for" part with the total amount of laudanums in your script, +1 (for example, if you had 20 laudanums in your map, the number would be 21).

To place this in your script, you will have to modify the item name slightly. The standard name for the laudanum is :

"potion_health_1"

Now, what you need to do is replace the "1" with "+i", but make sure it is out of the quotations. it should now look like:

"potion_health_"+i

This makes the game recognize all of these same items within the for loop as compatible for the adduseitemcallback.


here's an example of a chair puzzle I am using in my current mod, allowing the player to throw any of the 6 chairs in the room through the window and triggering the script (do not copy this script for your own uses or I will sacrifice you to the Sun God, Ra.)



for(int i=1;i<=7;i++)
AddEntityCollideCallback("chair_"+i, "AreaBreakWindow", "CollideAreaBreakWindow", true, 1);


Hope that helped!


RE: Trigger script when using any laudanum - palistov - 06-06-2012

Nah AddUseItemCallback triggers when an object is used on another object. You can create a loop which checks the player health...and if it jumps up by 15 HP instantly or so, you'll know they used a potion. Just know this won't work if the player uses a potion while at max health. Just an example of how you might go about it. Also notice the GetPlayerHealth() - 15.0f. This is to check if the player's health has changed by a value more than ~15 points. It depends on the heal amount of the potion. But realistically it could be something like 1.0f, because the player's health regenerates very slowly anyways.

PHP Code:
void OnStart()
{
    
SetLocalVarFloat("PlayerLastHP"GetPlayerHealth());
    
HPCheck("HPCheckLoopTimer");
}

void HPCheck(string &in t)
{
    if(
GetPlayerHealth()-15.0f GetLocalVarFloat("PlayerLastHP"))
    {
        
PlayerUsedPotion();
    }
    
SetLocalVarFloat("PlayerLastHP"GetPlayerHealth());
    
AddTimer(t0.0166f"HPCheck");




RE: Trigger script when using any laudanum - Damascus - 06-07-2012

Hmm I'm very inexperienced with custom functions, but if I follow this guide, do I then have to follow it up with this?

void PlayerUsedPotion()
{
(the [buy some apples] i want to happen)
}


RE: Trigger script when using any laudanum - FragdaddyXXL - 06-07-2012

(06-07-2012, 05:16 AM)Damascus Wrote: Hmm I'm very inexperienced with custom functions, but if I follow this guide, do I then have to follow it up with this?

void PlayerUsedPotion()
{
(the [buy some apples] i want to happen)
}
Yes, that should work.

Also, I recommend you start it in OnEnter() and stop the timer in OnLeave() if you are planning to have multiple levels. Do not have it start in OnEnter() AND OnStart() tho. I did a similar thing to make sanity more sensitive to things, and it didn't work as intended because I had the timer start in OnEnter() and OnStart().


RE: Trigger script when using any laudanum - Damascus - 06-07-2012

Works like a damn charm! Thanks a billion, mate!

Last question, if the player doesn't think to use a laudanum and ends up actually regenerating to full health, I'd like to trigger the script as well. I'm using an interval of 5 health to activate the function, so I'd also like it to auto-activate above 95 health.

if([PLAYER GAINS 5 LIFE] or [PLAYER REACHES 95 HEALTH OR HIGHER])

I have a vague sense of how i would script it, but don't know the symbol for "or"


RE: Trigger script when using any laudanum - SilentStriker - 06-07-2012

Else if is the code you are looking for, works the same as if but you need to but else before it Smile