TTLG|Thief|Bioshock|System Shock|Deus Ex|Mobile
Results 1 to 5 of 5

Thread: New Squirrel scripts: Set multiple qvars and other scripts

  1. #1
    Member
    Registered: Jan 2001
    Location: Formby, NW England

    New Squirrel scripts: Set multiple qvars and other scripts

    Download:
    http://www.mediafire.com/file/o5cnph...ul_scripts.nut

    This is similar to a normal QuestVarTrap, but you can set multiple qvars/objectives with one object, and display a custom on-screen text message.

    Reasoning:
    Let's say you have a mission in which completing a goal, e.g. read a book, or go to meet someone, causes another goal will be revealed. You have to make the new goal visible before completing the first one, otherwise the mission could become completed prematurely. Solving that problem causes another one: the "Objective Complete" message will be the last thing shown on screen, and the player may not realise there are new goals.

    The purpose of my SetMultQVars script is to allow multiple goals to be set from one object, along with a 'new goal' message to override whatever the game is trying to display.

    Example:
    Mission starts with goal_0 only. Upon completion, goal_1 becomes visible. goal_0 must be completed last to allow the mission to keep going.

    Add the SetMultQVars script to any object.
    Trap > Quest Var:
    =1:goal_visible_0; =1:goal_state_1
    (standard quest var trap syntax, but multiple statments separated by ; )

    There is no known limit to the number of qvars that can be set. Arithmetic is also supported, so you can add, subtract etc.

    The goals will be set in that order. By default it'll get the value of "NewGoal" as found in strings\playhint.str (no need to extract it from the crf) and will display it on screen.

    You can override the message in a number of ways.
    1) Put a custom version of playhint.str in your strings folder, define a new value, e.g.
    NewMessage = "Check your goals you taffer"

    Add a Design Note to your object will the following value:
    GoalString = "NewMessage"
    (this won't interfere with other custom script parameters)

    2) Set up a book with the text in page_0, e.g
    books\english\gText.str:
    page_0: "Check your goals!"

    Book > Text prop on the object:
    gText

    Code:
    Code:
    class QVarArithmetic extends SqRootScript
    {
    	function setNewValue(qvarCommand) //e.g =1:goal_state_3
    	{
    		local parts = split(qvarCommand, ":"); //returns array of =1 and goal_state_3
    		local lhs = strip(parts[0]); //remove spaces, user might write property like this: =1:goal_state_3; =3:goal_state_4
    		local rhs = parts[1];
    		
    		local qValue = Quest.Get(rhs);
    		local userInt = lhs[1].tointeger()-48; //Number entered after the =, + etc
    		
    		switch(lhs[0])
    		{
    			case 61:
    				qValue = userInt; break;
    			case 43:
    				qValue += userInt; break;
    			case 45:
    				qValue -= userInt; break;
    			case 42:
    				qValue *= userInt; break;
    			case 47:
    				qValue /= userInt; break;
    			case 37:
    				qValue %= userInt; break;
    			case 33: //!
    				qValue = qValue | userInt; break;
    			case 124: //|
    				qValue = qValue | userInt; break;
    			case 123: //{
    				qValue = qValue << userInt; break;
    			case 125: //}
    				qValue = qValue >> userInt; break;
    			case 63: //?
    				qValue += Data.RandInt(0, userInt); break;
    			case 100: //d
    				qValue += Data.RandInt(1, userInt); break;
    			default:
    				print("WARNING: Operator not supported: " + lhs[0].tochar()); 
    				DarkUI.TextMessage("Operator not supported: " + lhs[0].tochar(), 0)
    				break;
    		}
    		Quest.Set(rhs, qValue);
    	}
    }
    
    //Sets a load of qvars specified in the QuestVar propery. Appears instant to the player. Goal text can be overwritten.
    class SetMultQVars extends QVarArithmetic
    {
    	function OnTurnOn()
    	{
    		local qvProp = Property.Get(self, "TrapQvar");
    		local qvList = split(qvProp, ";");
    		
    		//qvCommands are like =1:goal_state_3
    		foreach(qvCommand in qvList)
    		{
    			setNewValue(qvCommand);
    		}
    				
    		ShowText();
    	}
    	
    	//Gets the specified entry from playhint.str, or shows the value from the specified book, or shows "New Objectives" by default.
    	function ShowText()
    	{
    		local popup;
    		if(HasProperty("DesignNote") && "GoalString" in userparams())
    		{
    			popup = Data.GetString("PLAYHINT", userparams().GoalString);
    		}
    		else if ( HasProperty("book") )
    		{
    			local bookname = GetProperty("book");
    			popup = Data.GetString(bookname, "Page_0", "", "Books");
    		}
    		else
    		{
    			popup = Data.GetString("PLAYHINT", "NewGoal");
    		}
    
    		DarkUI.TextMessage(popup);
    	}
    }
    Last edited by R Soul; 8th Aug 2017 at 18:53.

  2. #2
    Desperately dodgy geezer
    Registered: Nov 2001
    Location: The Wailing Keep
    Thank you Robin! I've been wanting this for some time now. There were situations in Godbreaker where I triggered 6 or 7 QVarTraps at one time and had to put a tiny delay before the last one to make sure it was last.

  3. #3
    Member
    Registered: Jan 2001
    Location: Formby, NW England
    I had a couple of other ideas, and have decided to keep them all in one thread.

    Here is a file containing three scripts. MultQVars, mentioned above, InvRename and OnOffModels.
    http://www.mediafire.com/file/o5cnph...ul_scripts.nut

    They all support custom turn on/turn off messages, using [script name]On and [script name]Off, though some scripts don't do an 'off' action, in other words they're one-way.

    InvRename
    Changes/sets the Inventory > Object name property when the object is turned on.
    Design Note parameter: InvRenameNewName="name_something"
    "name_something" needs to be an entry in objnames.str, e.g. name_basekey: "Basement Key"

    Example: A key is on a table, and there's nothing to explain its use. It uses its default inventory name ("Key") until the player either finds out where it goes or some other action, such as reading a book, reveals its use.
    The parameter InvRenameOn="Slain" will have the name changed when the key is successfully used on a matching door/footlocker etc. You can also send a Slain message via NVRelayTrap (or a conv etc) for any additional ways the player could be told what the key is for.

    OnOffModels
    Sets the model name to something when turned on, and another thing when turned off.
    Design Note parameters: OnOffModelsSetOn="model1"; OnOffModelsSetOff="model2"

    Example:
    You have two light models, one with bright glowing gas textures, the other with plain dark glass textures. This script makes it easy to switch between the two so the 'off' light uses the model with the dark glass textures.
    Last edited by R Soul; 8th Aug 2017 at 18:52.

  4. #4
    Member
    Registered: Jan 2001
    Location: Formby, NW England
    I've added two more scripts. Replace the file with this:
    http://www.mediafire.com/file/o5cnph...ul_scripts.nut

    EditorOnly
    When the mission starts, any object with this script will be deleted unless the mission is being played through the editor. This makes it easy to set up things like master keys, or buttons that trigger events that normally require time and effort. The old way to do this is to use Difficulty > Destroy: 0,1,2, but that makes it less convenient to test things when a difficulty level has been set in Dromed.

    Most things can be tested just fine in Dromed, but there may be times when you want to have these objects available in the proper game too. For that, create a quest variable called KeepAllObjects and give it a non-zero value. Remove it or set it to zero to have these objects deleted again.

    CopyProp
    Copies a property from one object (or archetype) to another. Essentially it's the same as the Set Property receptron, but with a script.
    Activated by TurnOn by default. Can be overridden by CopyPropOn="something"
    Parameters:
    CopyPropSource="object name"; CopyPropDest="other object name"; CopyProp="property name".

    If the source or dest params don't exist, the value will default to 'this object'.

    For a list of valid property names, see this page:
    http://dromed.whoopdedo.org/dromed/property/index
    (for pages that don't exist you can use the last part of the link)

  5. #5
    Desperately dodgy geezer
    Registered: Nov 2001
    Location: The Wailing Keep
    Just posting a thank you here for SetMultQVar, it's a great timesaver. I'm at a point where I am changing the visibility of 10 QVars all at one go and it saved me 9 objects and a bunch of hassle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •