Jump to content

Script to check players inventory fro a note?


alexcrazy14

Recommended Posts

​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

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 end

I 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

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
endif

However, 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 by claustromaniac
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...