Scripting using the .NUT format in Tres CE

Discuss the game Trespasser here!

Moderators: TresCom Support Team, TresCom Board Managers

User avatar
TheIdiot
T-Rex
T-Rex
Posts: 4345
Joined: Thu Feb 20, 2014 9:13 pm
Location: Canada, eh?

Scripting using the .NUT format in Tres CE

Post by TheIdiot »

I've been digging around trying to understand CE's .NUT scripting system to see if I can't come up with some simple scripts. Naturally, my utter lack of progamming skill limits me to only the most basic of things, and so far I haven't succeeded in anything other than understanding how the new example Spitter script works - I was able to get the TC~Isle dilos spitting again, all you have to do is add 1 line in the T-scripts for the dilo and the spit. I'm curious if anyone else has dabbled in this and come up with anything? There are example scripts provided for a HUD and a Map function as well, but I haven't figured those out whatsoever. It seems from what I've looked at that this .NUT system is extremely versatile, though - you could probably do some awesome stuff if you knew how, like drawing whatever you want onto the screen or creating new ActionTypes and even new functions that work with custom keybinds. Seems it even goes as far as modifying object behavior, as evidenced by the complicated script that makes the dilo spit.

Been trying to see if it's possible to do the seemingly simple task of making the game detect when you jump and prevent you from doing so again if you jump too much in a certain amount of time (anti-bunnyhopping measures). The long-term objective would be to create a stamina system where you can only run and jump so much before exhausting yourself, just as a test. :P So far my script is like 4 lines and I can't get much further than that. :|
User avatar
machf
T-Rex Killer
T-Rex Killer
Posts: 12368
Joined: Thu Apr 24, 2003 11:20 pm
Location: Lima, Peru
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by machf »

TheIdiot wrote:I've been digging around trying to understand CE's .NUT scripting system to see if I can't come up with some simple scripts. Naturally, my utter lack of progamming skill limits me to only the most basic of things, and so far I haven't succeeded in anything other than understanding how the new example Spitter script works - I was able to get the TC~Isle dilos spitting again, all you have to do is add 1 line in the T-scripts for the dilo and the spit.
You should post that one.
I'm curious if anyone else has dabbled in this and come up with anything? There are example scripts provided for a HUD and a Map function as well, but I haven't figured those out whatsoever. It seems from what I've looked at that this .NUT system is extremely versatile, though - you could probably do some awesome stuff if you knew how, like drawing whatever you want onto the screen or creating new ActionTypes and even new functions that work with custom keybinds. Seems it even goes as far as modifying object behavior, as evidenced by the complicated script that makes the dilo spit.
I haven't had the time to look at the scripting language, really. It's one of the things that's in the back burner right now.
Been trying to see if it's possible to do the seemingly simple task of making the game detect when you jump and prevent you from doing so again if you jump too much in a certain amount of time (anti-bunnyhopping measures). The long-term objective would be to create a stamina system where you can only run and jump so much before exhausting yourself, just as a test. :P So far my script is like 4 lines and I can't get much further than that. :|
Hmmm... what you might do is decrease health by a certain amount (not too much) whenever you jump. That way you wouldn't jump continuously.
And the same for running, too, although a little less than jumping, maybe.
Visit The Carnivores Saga - a forum devoted to modding Action Forms' Carnivores, Carnivores 2 and Carnivores: Ice Age games
Tres WIP: updated T-Script Reference and File Formats documents
Sound name listings for the Demo (build 117), Retail (build 116), Beta 103, Beta 99, Beta 97, Beta 96, Build 55, PC Gamer Alpha (build 32) and E3 1998 Alpha (build 22) TPA files
User avatar
TheIdiot
T-Rex
T-Rex
Posts: 4345
Joined: Thu Feb 20, 2014 9:13 pm
Location: Canada, eh?

Re: Scripting using the .NUT format in Tres CE

Post by TheIdiot »

You should post that one.
Will do so.
Been trying to see if it's possible to do the seemingly simple task of making the game detect when you jump and prevent you from doing so again if you jump too much in a certain amount of time (anti-bunnyhopping measures). The long-term objective would be to create a stamina system where you can only run and jump so much before exhausting yourself, just as a test. :P So far my script is like 4 lines and I can't get much further than that. :|
Hmmm... what you might do is decrease health by a certain amount (not too much) whenever you jump. That way you wouldn't jump continuously.
And the same for running, too, although a little less than jumping, maybe.
That would be an interesting solution, but it would also make the game perhaps excessively hard, especially if you weren't using the auto-regen health. Looking at the NUT scripting, it seems like it *is* possible to make it do what I described, but I'm totally stumped by the whole scripting thing. Ah well.
User avatar
Draconisaurus
T-Rex Killer
T-Rex Killer
Posts: 14046
Joined: Mon Dec 06, 2004 5:21 pm
Antispam: No
Location: Isla Sorna
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by Draconisaurus »

A very important topic you've made, TI, which I suspect will be posted in slowly over time...

You are making all this sound quite potentious. :| I quite like the idea of a stamina system. Custom key binds?! Perhaps a specific mod where pressing "5" or whatever, when standing over a certain spot, reloads your gun. I feel like I've come up with ideas for custom-key-functions over the years, and forgotten them... Eh I know one of the most significant ones: An onscreen keypad entry, a la Jurassic Park SNES, replacing the button-finger method. Or really, any number of things about walking up to a functioning ingame computer and having an interactive 2D display pop up until you exit it (again, a la SNES). IIIII would assist anyone wishing to help realize this one. Might make a good element for Site C, even. Oh and TI, this could be the key to finishing your SNES mod, replacing insanely complex computer system triggers.
User avatar
TheIdiot
T-Rex
T-Rex
Posts: 4345
Joined: Thu Feb 20, 2014 9:13 pm
Location: Canada, eh?

Re: Scripting using the .NUT format in Tres CE

Post by TheIdiot »

A very important topic you've made, TI, which I suspect will be posted in slowly over time...
That's what I'm hoping as well. :)
I quite like the idea of a stamina system.
For me, it's more about making the player less inclined to just run or bunny-hop away. It would also be great if we could increase Anne's overall speed so that her walk is just a tiny bit slower than the vanilla run speed, and the run would be fast enough to outrun a dinosaur. Run would act more as a sprint, which would quickly drain your stamina, and jumping would take around probably 25% of your stamina. Once you run out, perhaps a simple trigger could play the tired sound, and running and jumping would become impossible. Of course this is all just ideas until someone works out how versatile .NUT is. I don't know if Anne's speed can be changed at all without editing the source code.
Custom key binds?! Perhaps a specific mod where pressing "5" or whatever, when standing over a certain spot, reloads your gun.
That's something else likely possible, as CE has support for 8 custom keybinds (which can even be edited into the Controls menu to boot!). There's the obvious R to reload and M for map, but what about, say, pushing a key to teleport somewhere? Or perhaps a dedicated sprint key to increase your speed temporarily for the stamina system I mentioned above?
Eh I know one of the most significant ones: An onscreen keypad entry, a la Jurassic Park SNES, replacing the button-finger method. Or really, any number of things about walking up to a functioning ingame computer and having an interactive 2D display pop up until you exit it (again, a la SNES).
That would also be quite cool, and I know you can definitely do the overlaying part of that, but whether it would be clickable, I can't say.
Oh and TI, this could be the key to finishing your SNES mod, replacing insanely complex computer system triggers.
I'm thinking that even if this did work, I'd still do the complex computer triggers just for the hell of it. :cry: Only reason I haven't had much progress on the SNES mod is that the set of triggers to make the T-rex chase you and then exit once you reach a certain point, and then reset - the only triggers in the level so far, naturally - aren't cooperating.
User avatar
Draconisaurus
T-Rex Killer
T-Rex Killer
Posts: 14046
Joined: Mon Dec 06, 2004 5:21 pm
Antispam: No
Location: Isla Sorna
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by Draconisaurus »

TheIdiot wrote:stamina
All nice ideas. I quite like the tired vocals part... This makes me want to see a CE-script for the idle vocals as well.
Eh I know one of the most significant ones: An onscreen keypad entry, a la Jurassic Park SNES, replacing the button-finger method. Or really, any number of things about walking up to a functioning ingame computer and having an interactive 2D display pop up until you exit it (again, a la SNES).
That would also be quite cool, and I know you can definitely do the overlaying part of that, but whether it would be clickable, I can't say.
Consider it a top priority... :pirate: I've waited a long time for this one lol. I remember asking Big Red about it for ATX.
Oh and TI, this could be the key to finishing your SNES mod, replacing insanely complex computer system triggers.
I'm thinking that even if this did work, I'd still do the complex computer triggers just for the hell of it. :cry: Only reason I haven't had much progress on the SNES mod is that the set of triggers to make the T-rex chase you and then exit once you reach a certain point, and then reset - the only triggers in the level so far, naturally - aren't cooperating.
Heh well alright then...
Slugger
-=TresCom Developer=-
-=TresCom Developer=-
Posts: 4720
Joined: Sat Jun 12, 2004 6:52 pm
Antispam: No
Location: Atlanta

Re: Scripting using the .NUT format in Tres CE

Post by Slugger »

Draco and I had a conversation about this and he pointed me to this thread, and then asked if I could take a look at this squirrel language. I sent him some of my thoughts in FB messenger, but for the sake of have a more public record I'm going to reproduce and expand upon them here. I've only spent about an hour reading over the documentation and examples included with TresCE (haven't looked at the squirrel manual itself), so I reserve my right to revise any of what I post here at a later date as new information becomes available.

Although the squirrel language is pretty abstracted and flexible and can be used to expand the game play of Tres, it's not that flexible. Essentially we can access via squirrel all of Tres's internal functions and variables and can use these as a basis to build new functionalities. It doesn't look like we can, however, develop new functionalities whole cloth. What I mean by this is implementing something like a virtual computer and command line is impossible, because Tres does not natively support keyboard/mouse input control at that fine of a level (such functionality would have to be implemented at the source level).

The spitter is a good example because while it adds new dinosaur behavior, it does so using existing Tres functions to accomplish this. Tres has functions to calculate the distance between two world object, we can get variable such as the head hit box position and orientation, Tres has a list of all game world objects, there's an impulse function, etc, and initially ATX patched itself into the engine in a round about way to be able to access these things (hence the complicated-looking tscripting for the ATX spitter). What's novel about squirrel is that it's an abstracted higher-level way of accessing what Tres is doing behind the scenes, essentially creating a Tres API that we can access through a more mainstream scripting approach (instead of doing wonky things with tscripts). It sorts of liberates us from the more restrictive environment of tscripts. All of these functions and variables exist beneath the surface; while tscripts only allow us to access a subset of these and to set a certain list of variables and conditions, squirrel gives us more direct and flexible access to all of this. The "API-reference.txt" file lists all of the functions, classes, and variables we can access (so whatever we want to do has to be within the context of this list).

I hope this makes sense and isn't too rambling. In terms of implementing some sort of in-game computer or 2D display, you couldn't have a 'working' computer in-game, but you could certainly fake one use the custome keybinds (uCMD_USER1 through uCMD_USER2 in the API-reference) as a sort of slide show controller: either have an overlay with a list of options (1-8) or an old DOS-based navigation system corresponding to advancing/retreating through slides. A GUI with mouse control would not be possible, nor would having some sort of terminal thing where the user could navigate like you would in a terminal, because as I said above Tres has no native capability to handle this sort of thing. There's nothing in the API list referencing mouse input, so I either missed it or Tres doesn't report anything interesting about the mouse other than to use it as Anne's look direction.

@TheIdiot: Do you mind sharing what code you have written for your stamina system? I'm assuming you saw the "static bool bKeyHit(uMCD);" and "static bool bKeyPressed(uCMD);" commands and are using some variant of that to detect when the user presses the jump or run keys? I think an essential question we need to answer is how the squirrel code interacts with the Tres game loop. Can we take command or override what Tres is doing for the game loop? For example, if the user presses 'q' to jump, can we tell Tres via squirrel to ignore that jump command, or will Anne jump regardless and then the engine will execute our squirrel script in conjunction with that? Because if it's the latter, then you'll have to go with a penalty technique like machf suggested.
0066521C: 'Cannot create local swap file - Is Trespasser installed??',0Ah,0
"Cold lino was the driving force behind world power!"
Slugger
-=TresCom Developer=-
-=TresCom Developer=-
Posts: 4720
Joined: Sat Jun 12, 2004 6:52 pm
Antispam: No
Location: Atlanta

Re: Scripting using the .NUT format in Tres CE

Post by Slugger »

I'm in lab, where I don't have Tres installed, but if someone could try this and report back to me its behavior, that'd be convenient. Otherwise I'll try tonight or tomorrow when I get home.

Just a very basic script to identify when the player presses jump and then holds in the run command.

Code: Select all

// ---------------------------------------------------------------------------------------------------------------
// A test script for input detection and handling 
class Stamina extends GameScript
{
	// Maximum 
	fSprintTime = 5.0;
		// make the general purpose key 1 toggle a (hypothetical) map display
	function OnHandleInput()
	{
		// jump key has been pressed
		if ( bKeyHit(uCMD_JUMP) )
		{
			print("Anne has jumped!");
		}
		
		// first instance of it, I think
		//if ( bKeyHit(uBITKEY_RUN) )
		//{
			//local fSprintTime = TP_Engine.GetElapsedSimTime();
		//}
		
		if ( bKeyPressed(uBITKEY_RUN) )
		{
			print(TP_Engine.GetElapsedSimTime())
		}
	}
}
0066521C: 'Cannot create local swap file - Is Trespasser installed??',0Ah,0
"Cold lino was the driving force behind world power!"
User avatar
TheIdiot
T-Rex
T-Rex
Posts: 4345
Joined: Thu Feb 20, 2014 9:13 pm
Location: Canada, eh?

Re: Scripting using the .NUT format in Tres CE

Post by TheIdiot »

Hmm. I'm glad you've summed up the NUT system in simple terms here, as I now have an understanding of its flexibility. Guess I wasn't that far off! In any case, access to Tres' internal values still opens up a lot of possibilities since the engine is so complex with all of those values. I'm excited to see what you can come up with, Slugger. :)
I'm in lab, where I don't have Tres installed, but if someone could try this and report back to me its behavior, that'd be convenient. Otherwise I'll try tonight or tomorrow when I get home.

Just a very basic script to identify when the player presses jump and then holds in the run command.
I'll give it a go and let you know how it goes. I'm really happy you're working on this, an a big "thank you" if you manage to get it to work. :D What exactly should this script do in-game? Or is it just a test to see if it prints to the dev logging console when you jump?
User avatar
machf
T-Rex Killer
T-Rex Killer
Posts: 12368
Joined: Thu Apr 24, 2003 11:20 pm
Location: Lima, Peru
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by machf »

Slugger wrote: Although the squirrel language is pretty abstracted and flexible and can be used to expand the game play of Tres, it's not that flexible. Essentially we can access via squirrel all of Tres's internal functions and variables and can use these as a basis to build new functionalities.
Well, what I'd do is change the zoom factor using scripts... I know that, internally, Trespasser keep track of the zoom and not just the FOV, so that would finally enable us to better make sighting scopes for guns, or binoculars... I'll start reading a bit and give it a try.
Visit The Carnivores Saga - a forum devoted to modding Action Forms' Carnivores, Carnivores 2 and Carnivores: Ice Age games
Tres WIP: updated T-Script Reference and File Formats documents
Sound name listings for the Demo (build 117), Retail (build 116), Beta 103, Beta 99, Beta 97, Beta 96, Build 55, PC Gamer Alpha (build 32) and E3 1998 Alpha (build 22) TPA files
Slugger
-=TresCom Developer=-
-=TresCom Developer=-
Posts: 4720
Joined: Sat Jun 12, 2004 6:52 pm
Antispam: No
Location: Atlanta

Re: Scripting using the .NUT format in Tres CE

Post by Slugger »

I apologize for the various spelling errors and grammar mistakes in my previous post; I didn't proof read it.
TheIdiot wrote:I'll give it a go and let you know how it goes. I'm really happy you're working on this, an a big "thank you" if you manage to get it to work. :D What exactly should this script do in-game? Or is it just a test to see if it prints to the dev logging console when you jump?
Yeah, it should print into the dev log whenever you press the jump key and hold in the sprint key.
machf wrote:Well, what I'd do is change the zoom factor using scripts... I know that, internally, Trespasser keep track of the zoom and not just the FOV, so that would finally enable us to better make sighting scopes for guns, or binoculars... I'll start reading a bit and give it a try.
That should be fairly easy as the object use/pick up/set down conditionals are available. Do you know, off the top of your head, what the internal variable name for zoom is?
0066521C: 'Cannot create local swap file - Is Trespasser installed??',0Ah,0
"Cold lino was the driving force behind world power!"
User avatar
machf
T-Rex Killer
T-Rex Killer
Posts: 12368
Joined: Thu Apr 24, 2003 11:20 pm
Location: Lima, Peru
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by machf »

Slugger wrote: That should be fairly easy as the object use/pick up/set down conditionals are available. Do you know, off the top of your head, what the internal variable name for zoom is?
There's a "camprop.fZoomFactor" in CameraProperties.cpp
But actually, the float fZoomFactor (part of the properties of the CCamera class) is in Camera.cpp/Camera.hpp, I guess that's the one to use...
Visit The Carnivores Saga - a forum devoted to modding Action Forms' Carnivores, Carnivores 2 and Carnivores: Ice Age games
Tres WIP: updated T-Script Reference and File Formats documents
Sound name listings for the Demo (build 117), Retail (build 116), Beta 103, Beta 99, Beta 97, Beta 96, Build 55, PC Gamer Alpha (build 32) and E3 1998 Alpha (build 22) TPA files
User avatar
TheIdiot
T-Rex
T-Rex
Posts: 4345
Joined: Thu Feb 20, 2014 9:13 pm
Location: Canada, eh?

Re: Scripting using the .NUT format in Tres CE

Post by TheIdiot »

machf wrote:
Slugger wrote: Although the squirrel language is pretty abstracted and flexible and can be used to expand the game play of Tres, it's not that flexible. Essentially we can access via squirrel all of Tres's internal functions and variables and can use these as a basis to build new functionalities.
Well, what I'd do is change the zoom factor using scripts... I know that, internally, Trespasser keep track of the zoom and not just the FOV, so that would finally enable us to better make sighting scopes for guns, or binoculars... I'll start reading a bit and give it a try.
What precisely would be the advantage or difference of a dedicated zoom function over just changing the FOV? Other than not having to change something most players probably want to keep at their chosen value.

...unless we could have it work via keybind, now that'd be something. I guess you could do something like this (not a real scripting language, but this should be a good enough representation of what I mean):

Code: Select all

upon pressing "CUSTOM1" //or whatever CE's scripting language uses for custom keybinds
   if Player is holding Binoculars00-00
      if flag "Zoomed" = 0
         zoom to x5
         set flag "Zoomed" to 1
      if flag "Zoomed" = 1
         zoom to x1
         set flag "Zoomed" to 0
   if Player is not holding Binoculars00-00 and flag "Zoomed" = 1
      zoom to x1
      set flag "Zoomed" to 0
end
I'm sure there are more effective ways to do that in a script, but I figured I'd put my horribly basic idea out there. And instead of specifying a specific instance, you could make it so any object with "float Script = "Zoom_X5"" has the ability to do this. 8)
User avatar
machf
T-Rex Killer
T-Rex Killer
Posts: 12368
Joined: Thu Apr 24, 2003 11:20 pm
Location: Lima, Peru
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by machf »

TheIdiot wrote:
machf wrote: Well, what I'd do is change the zoom factor using scripts... I know that, internally, Trespasser keep track of the zoom and not just the FOV, so that would finally enable us to better make sighting scopes for guns, or binoculars... I'll start reading a bit and give it a try.
What precisely would be the advantage or difference of a dedicated zoom function over just changing the FOV? Other than not having to change something most players probably want to keep at their chosen value.
Did you read? When using a scoped weapon or binoculars, it would happen automatically, and get back to the normal zoom (1.0) after putting them down or holstering them...
Why use zoom and not FOV? Because:
  • unlike zoom factor, the FOV isn't the same for all screens, but depends on the aspect ratio
  • scopes, binoculars and other visual enhancement aids USE a zoom factor to indicate their capabilities
Try the scoped guns in the Armory and you'll see... they were scripted back then when there was no provision for widescreen in Tres, and work by changing the FOV (which had to be previously calculated for each one and for the default screen), and now when they change "back", the resulting FOV turns out wrong when the screen aspect isn't 4:3 anymore...
Visit The Carnivores Saga - a forum devoted to modding Action Forms' Carnivores, Carnivores 2 and Carnivores: Ice Age games
Tres WIP: updated T-Script Reference and File Formats documents
Sound name listings for the Demo (build 117), Retail (build 116), Beta 103, Beta 99, Beta 97, Beta 96, Build 55, PC Gamer Alpha (build 32) and E3 1998 Alpha (build 22) TPA files
User avatar
Draconisaurus
T-Rex Killer
T-Rex Killer
Posts: 14046
Joined: Mon Dec 06, 2004 5:21 pm
Antispam: No
Location: Isla Sorna
Contact:

Re: Scripting using the .NUT format in Tres CE

Post by Draconisaurus »

Glad we're getting somewhere with this... Jeez I suppose I might eventually get into this enough to be able to write some code of my own. Been since 2005 since I did programming outside the scope of t-script... I learn best by example, will most likely wait for an amount of functioning code for this language relative to Tres CE to be written and go from there.

Slugger, it might not hurt to post your chicken-scratch code about the computer screen code. Might come in handy.
Post Reply