Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trigger script when using any laudanum
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#1
Trigger script when using any laudanum

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

06-06-2012, 10:08 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Trigger script when using any laudanum

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

I rate it 3 memes.
06-06-2012, 10:11 AM
Find
Datguy5 Offline
Senior Member

Posts: 629
Threads: 25
Joined: Dec 2011
Reputation: 12
#3
RE: Trigger script when using any laudanum

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

06-06-2012, 10:38 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#4
RE: Trigger script when using any laudanum

(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.

06-06-2012, 06:38 PM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#5
RE: Trigger script when using any laudanum

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!

I rate it 3 memes.
06-06-2012, 09:10 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: Trigger script when using any laudanum

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: (Select All)
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");


(This post was last modified: 06-06-2012, 09:56 PM by palistov.)
06-06-2012, 09:54 PM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#7
RE: Trigger script when using any laudanum

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)
}

06-07-2012, 05:16 AM
Find
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#8
RE: Trigger script when using any laudanum

(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().

Dark Seclusion Here
(This post was last modified: 06-07-2012, 07:52 AM by FragdaddyXXL.)
06-07-2012, 06:00 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#9
RE: Trigger script when using any laudanum

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"

(This post was last modified: 06-07-2012, 08:12 AM by Damascus.)
06-07-2012, 08:07 AM
Find
SilentStriker Offline
Posting Freak

Posts: 950
Threads: 26
Joined: Jul 2011
Reputation: 43
#10
RE: Trigger script when using any laudanum

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

06-07-2012, 08:31 AM
Find




Users browsing this thread: 3 Guest(s)