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
Help on entity activation
TShapeShifter Offline
Junior Member

Posts: 17
Threads: 5
Joined: Jul 2014
Reputation: 0
#1
Help on entity activation

hey guys, this is probably a dumb question and much likely the answer is no but I recently have been wondering, is it possible to activate an entity upon the possession of a certain number of notes? Like for example is it possible for an entity to only activate itself if the player picks up all the notes in a story?
Sorry if this is a dumb question, any help is very much appreciated, thank you Smile
07-12-2014, 10:26 PM
Find
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#2
RE: Help on entity activation

(07-12-2014, 10:26 PM)TShapeShifter Wrote: hey guys, this is probably a dumb question and much likely the answer is no but I recently have been wondering, is it possible to activate an entity upon the possession of a certain number of notes? Like for example is it possible for an entity to only activate itself if the player picks up all the notes in a story?
Sorry if this is a dumb question, any help is very much appreciated, thank you Smile

It's not a dumb question! xD

If it is possible, I would think you can use an if statement. Note's are considered items, and are technically stored in the inventory. You could set up a script box that calls a check function that looks for the if statement and whether or not you have all notes. The if statement would look something like this:

PHP Code: (Select All)
if(HasItem("nameofnote1") == true && HasItem("nameofnote2") == true && HasItem("nameofnote3") == true)
{
Script called yadda yadda


If the player is missing any of those notes, the script won't call. Big Grin

I've never tried it myself, so I'm not completely sure, however if you can attach script to the interaction with notes, then I'm sure this would work.

07-12-2014, 10:48 PM
Find
TShapeShifter Offline
Junior Member

Posts: 17
Threads: 5
Joined: Jul 2014
Reputation: 0
#3
RE: Help on entity activation

(07-12-2014, 10:48 PM)MsHannerBananer Wrote:
(07-12-2014, 10:26 PM)TShapeShifter Wrote: hey guys, this is probably a dumb question and much likely the answer is no but I recently have been wondering, is it possible to activate an entity upon the possession of a certain number of notes? Like for example is it possible for an entity to only activate itself if the player picks up all the notes in a story?
Sorry if this is a dumb question, any help is very much appreciated, thank you Smile

It's not a dumb question! xD

If it is possible, I would think you can use an if statement. Note's are considered items, and are technically stored in the inventory. You could set up a script box that calls a check function that looks for the if statement and whether or not you have all notes. The if statement would look something like this:

PHP Code: (Select All)
if(HasItem("nameofnote1") == true && HasItem("nameofnote2") == true && HasItem("nameofnote3") == true)
{
Script called yadda yadda


If the player is missing any of those notes, the script won't call. Big Grin

I've never tried it myself, so I'm not completely sure, however if you can attach script to the interaction with notes, then I'm sure this would work.

That's actually a great idead! Thanks I'll give it a try! Smile

(07-12-2014, 10:54 PM)TShapeShifter Wrote:
(07-12-2014, 10:48 PM)MsHannerBananer Wrote:
(07-12-2014, 10:26 PM)TShapeShifter Wrote: hey guys, this is probably a dumb question and much likely the answer is no but I recently have been wondering, is it possible to activate an entity upon the possession of a certain number of notes? Like for example is it possible for an entity to only activate itself if the player picks up all the notes in a story?
Sorry if this is a dumb question, any help is very much appreciated, thank you Smile

It's not a dumb question! xD

If it is possible, I would think you can use an if statement. Note's are considered items, and are technically stored in the inventory. You could set up a script box that calls a check function that looks for the if statement and whether or not you have all notes. The if statement would look something like this:

PHP Code: (Select All)
if(HasItem("nameofnote1") == true && HasItem("nameofnote2") == true && HasItem("nameofnote3") == true)
{
Script called yadda yadda


If the player is missing any of those notes, the script won't call. Big Grin

I've never tried it myself, so I'm not completely sure, however if you can attach script to the interaction with notes, then I'm sure this would work.

That's actually a great idead! Thanks I'll give it a try! Smile

Didn't work T-T God I was so sure it was gonna work... :c I dont suppose you have any other ideas? Undecided
(This post was last modified: 07-12-2014, 11:42 PM by TShapeShifter.)
07-12-2014, 10:54 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#4
RE: Help on entity activation

Yep (Only for another idea...)! Use Local Variables Smile

On each note that affects your monster counter, put the code name of your script in PlayerInteractCallback (MsHannerBananer pointed that out, but this is what she meant).
Spoiler below!
[Image: 99ada05fc4.jpg]

This is the code you should use :3
PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("monster_appear"0);
}

void note_pickup(string &in asEntity)
{
    if(
GetLocalVarInt("monster_appear") == 3//Change the three to the number of notes needed.
    
{
         
//script here what to happen
    
}
    else
    {
         
AddLocalVarInt("monster_appear"1);
    }


Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 07-13-2014, 01:57 AM by Romulator.)
07-13-2014, 01:56 AM
Find
TShapeShifter Offline
Junior Member

Posts: 17
Threads: 5
Joined: Jul 2014
Reputation: 0
#5
RE: Help on entity activation

(07-13-2014, 01:56 AM)Romulator Wrote: Yep (Only for another idea...)! Use Local Variables Smile

On each note that affects your monster counter, put the code name of your script in PlayerInteractCallback (MsHannerBananer pointed that out, but this is what she meant).
Spoiler below!
[Image: 99ada05fc4.jpg]

This is the code you should use :3
PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("monster_appear"0);
}

void note_pickup(string &in asEntity)
{
    if(
GetLocalVarInt("monster_appear") == 3//Change the three to the number of notes needed.
    
{
         
//script here what to happen
    
}
    else
    {
         
AddLocalVarInt("monster_appear"1);
    }


Still didn't work Undecided Am I doing anything wrong? o:
PHP Code: (Select All)
void OnStart()
{
     
SetLocalVarInt("monster_appear"0);
}

void note_pickup(string &in asEntity)
{
    if(
GetLocalVarInt("monster_appear") == 2)
    {
         
SetEntityActive("doortest"true);
    }
    else
    {
         
AddLocalVarInt("monster_appear"1);
    }


void OnLeave()
{
 

(This post was last modified: 07-13-2014, 03:08 AM by TShapeShifter.)
07-13-2014, 03:07 AM
Find
MsHannerBananer Offline
Member

Posts: 218
Threads: 34
Joined: Sep 2013
Reputation: 10
#6
RE: Help on entity activation

Okay, let's start from the top. This'll be a long explanation so I'm going to use spoilers.

Step One
Spoiler below!


Say you have 3 notes that you want the player to have in their possession before they can progress.

These notes are called

"note1"
"note2"
and "note3"

So, in order for your character to progress, you need to set up a script box nearby that runs a check function to see whether or not the character has those notes in their possession.

Let's start with adding the collide callback.

PHP Code: (Select All)
void OnStart()

{
AddEntityCollideCallback(stringasParentNamestringasChildNamestringasFunctionbool abDeleteOnCollideint alStates);

// "string& asParentName" is the player, "string& asChildName" is the script box, "string& asFunction" is the function that's called, "bool abDeleteOnCollide" is whether or not this callback is deleted once the player has gone through the script box, "int alStates" is whether the script is called when the player enters (1), leaves (-1), or both (0).

//So this script will be set up to look like this.

AddEntityCollideCallback("Player""CheckScriptBox""CheckIfHasNotes"false1);





Step Two

Spoiler below!

So, going off of some stuff that Romulator suggested and reminded me of, lets give each note a local variable, (or a global variable if your script is being used across multiple maps.)

For each of your notes, you need to set up an interact callback. So lets go do that.

PHP Code: (Select All)
void onStart()
{
SetEntityPlayerInteractCallback(stringasNamestringasCallbackbool abRemoveOnInteraction);

// "string& asName" is the name of the entity, so this would be "note1", "note2", or "note3", "string& asCallback" is the function called and you'll need a separate function for each note you pickup, "bool abRemoveOnInteraction" is whether or not the callback is removed once the entity is interacted with.

//So the script will look like this:

SetEntityPlayerInteractCallback("note1""GiveNote1Var"true);
}


//Then outside of OnStart we give "note1" its variable to be referenced later. This looks like this:

void GiveNote1Var(string &in asEntity)
{
SetLocalVarInt("note1var"1); // "note1var" is a name that's given in order to reference the variable later when we call it in the if statement. "1" is the variable we give.


You need three of them, one for each note.


Step Three
Spoiler below!

Now we need to set up the function that the CollideCallback calls for, which is the check, it looks for the if statement.

PHP Code: (Select All)
void CheckIfHasNotes(string &in asParentstring &in asChildint alState
{
if (
GetLocalVarInt("note1var") == && GetLocalVarInt("note2var") == && GetLocalVarInt("note3var") == 1)
{
//Whatever you want done here.
}



And that's it. I hope this can clear some stuff up for you and that it works for you. If you still have problems and are getting error messages, then post your script and hpl log. Smile

07-13-2014, 05:26 AM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: Help on entity activation

I don't think a collide callback would be very reliable for this type of check. You could just check it every time you actually pick up a note.

I think the issue here is that it's in the PlayerInteractCallback. It probably slipped Rom's mind that the basic CallbackFunc is ran duing OnPickup. Try calling the code Rom provided within the CallbackFunc at the top of each note.

Edit: Actually, let's tweak it a bit. If you have the check to use == 3 before the script that adds the value, then value #3 is actually not recognized until the 4th time this is called. It goes from top to bottom, so even if the value is 3 by the end of it, it won't trigger the if-statement unless it is 3 when it reaches it.

PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("monster_appear"0); //This is not exactly necessary, because an AddLocalVarInt script will create a var that is non-existant, but you might as well have it here.
}

void CheckNote(string &in asEntityint Type//If you move the code to CallbackFunc, you need to add the second parameter.
{
    if(
GetLocalVarInt("monster_appear") < 3AddLocalVarInt("monster_appear"1); 
    else {
        
//Do an action here.
    
}


This script is slightly more compact and it works the other way around. First it checks if the value has not yet reached 3 (the heart <3 means "less than three" :3). If it has not reached it, it adds another value. If it has reached 3 (or more), it will run the script in the else-block instead.

(This post was last modified: 07-13-2014, 07:46 AM by Mudbill.)
07-13-2014, 07:38 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#8
RE: Help on entity activation

Aw sh... forgot... test last... >.>

Either way, we have gone through it a couple of times Smile Whichever solution the OP uses, we can assist with otherwise if there are still problems!

Discord: Romulator#0001
[Image: 3f6f01a904.png]
07-13-2014, 08:42 AM
Find
TShapeShifter Offline
Junior Member

Posts: 17
Threads: 5
Joined: Jul 2014
Reputation: 0
#9
RE: Help on entity activation

Guys thanks alot! Smile I've managed to do it, I tried what Mudbill told me but it didn't work for some reason Undecided I then used this:
PHP Code: (Select All)
void OnStart()
{
    
SetEntityPlayerInteractCallback("note_generic_2""AddOneToFunction"true);
    
SetEntityPlayerInteractCallback("note_generic_1""AddOneToFunction"true);
    
SetLocalVarInt("monster_appear"0);
    
AddEntityCollideCallback("Player""checkfornotesarea""Check"true1);
}

void AddOneToFunction(string &in asEntity)
{
    
AddLocalVarInt("monster_appear"1);
}
void Check(string &in asParentstring &in asChildint alState)
{
    if(
GetLocalVarInt("monster_appear") == 2)
    {
    
SetEntityActive("doortest"true);
    }

but this will work on this specific map only, for it to work on the notes on the other maps aswell I've got to use a Global Variable right? o: How exactly do I do that? Confused and thanks for your help guys you're awesome ^^
07-13-2014, 10:03 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#10
RE: Help on entity activation

If you need to use global variables, just change the AddLocalVarInt to AddGlobalVarInt, as well as the Set and Get versions. That's all.

07-13-2014, 10:15 PM
Find




Users browsing this thread: 2 Guest(s)