alexcrazy14 Posted March 21, 2015 Share Posted March 21, 2015 I want to write a script on a container that goes along the lines of: begin OnActivate if (players inventory has a certain note) then add a different note to the containers inventory new to scripting help appreciated thx Link to comment Share on other sites More sharing options...
claustromaniac Posted March 21, 2015 Share Posted March 21, 2015 I'd try something like this: scn myscript begin OnActivate if IsActionRef Player && GetHasNote NoteID && GetHasNote Note2ID == 0 ; if the player is the one who activated the container and he has the first note but not the new note... AddItem Note2ID 1 ; add the new note to the container. endif Activate ; activate the container end Link to comment Share on other sites More sharing options...
alexcrazy14 Posted March 21, 2015 Author Share Posted March 21, 2015 thanks :) just to clarify as Im trying to learn though what does the IsActionRef do and why do we need to activate the container at the end Link to comment Share on other sites More sharing options...
claustromaniac Posted March 21, 2015 Share Posted March 21, 2015 thanks :smile: just to clarify as Im trying to learn though what does the IsActionRef do and why do we need to activate the container at the endI used IsActionRef to ensure that the one who activated the container was the player and not something else. That way if any NPC or other reference activates the container the OnActivate block will run, but those lines of the script wont.The Activate function at the end is necessary because the OnActivate block overrides the normal activation behaviour of the container. In other words, if that line wasn't there you'd never be able to open the container normally. Link to comment Share on other sites More sharing options...
alexcrazy14 Posted March 21, 2015 Author Share Posted March 21, 2015 thanks :) helps alot Link to comment Share on other sites More sharing options...
alexcrazy14 Posted March 21, 2015 Author Share Posted March 21, 2015 one last question. What wer those symbols around gethasnote were they 2 &&'s were they actually part of the script Link to comment Share on other sites More sharing options...
claustromaniac Posted March 21, 2015 Share Posted March 21, 2015 (edited) It is a common operator present in most programming languages usally referred to as Logical AND. It is used to make complex evaluations. Example: if This && That That evaluation returns TRUE(1) only if both This and That are TRUE. If you take a look at the script above you'll see that I used it to evaluate the following three things in order:Whether the one activating the container was the player or not.Whether the player had the first note or not.Whether the player didn't have the second note or not.That if statement returns TRUE only if all of those three things are true at the same time. It is practically the same as this: if IsActionRef Player ; if the player is the one who activated the container if GetHasNote NoteID ; and he has the first note if GetHasNote Note2ID == 0 ; but not the new note... AddItem Note2ID 1 ; add the new note to the container. endif endif endifHowever, this last example is more performance friendly than the first one if you call RETURN, which is what I normally do to optimize my scripts. Example: if IsActionRef Player != 1; if the player is NOT the one who activated the container return ;trim CPU usage. (This frame of the script will stop right here) endif if GetHasNote NoteID != 1; or if he does NOT have the first note return endif if GetHasNote Note2ID ; or if he already has the new note... return endif ; if the script made it to this point it means the one who activated the container was the player, and he had the first note but not the second so... AddItem Note2ID 1 So now you are probably wondering why I didn't use this if it is the most performance-friendly option. The reason is simple: your script only has an OnActivate block, which means that it only runs when you activate the container. Optimizing scripts this way is only truly beneficial when they have a GameMode or MenuMode block, because those are always running in the background. I hope that helps :cool: Edited March 22, 2015 by claustromaniac Link to comment Share on other sites More sharing options...
alexcrazy14 Posted March 21, 2015 Author Share Posted March 21, 2015 very helpful thanks, you make a lot more sense of things than any tutorials iv seen lol :p Link to comment Share on other sites More sharing options...
claustromaniac Posted March 21, 2015 Share Posted March 21, 2015 very helpful thanks, you make a lot more sense of things than any tutorials iv seen lol :tongue: Very welcome :) and thanks for the compliment! Link to comment Share on other sites More sharing options...
Recommended Posts