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
(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
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:
(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
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:
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.
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!
(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
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:
Yep (Only for another idea...)! Use Local Variables
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).
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
(This post was last modified: 07-13-2014, 01:57 AM by Romulator.)
(07-13-2014, 01:56 AM)Romulator Wrote: Yep (Only for another idea...)! Use Local Variables
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).
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); } }
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.
// "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.
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.
// "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.
//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.
void CheckIfHasNotes(string &in asParent, string &in asChild, int alState) { if (GetLocalVarInt("note1var") == 1 && GetLocalVarInt("note2var") == 1 && 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.
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.
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 asEntity, int Type) //If you move the code to CallbackFunc, you need to add the second parameter. { if(GetLocalVarInt("monster_appear") < 3) AddLocalVarInt("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.
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? and thanks for your help guys you're awesome ^^