[REQWIP] ModFood: Snippets & Tips

Post » Mon May 07, 2012 5:52 pm

I'm not sure if any of these are what you're looking for, but:


Objective: Debug Messages for Mod Testing (With OBSE and Without OBSE)
The purpose of this is to find out variables stated in the script, so you know it is running and to see what the outcome is. In the example script, I can figure out what the variables equal easily, but if you replace Variable01 with something that can be dynamic in-game, than this becomes helpful to know the outcome of the script variables. This can also be used to see if the script is even running. [Note: The two version are no different, except one message to the console and the other messages in-game.]

Options:

A. Without OBSE

B. With OBSE

Steps

Without OBSE:
A. 1. Edit a script:
Click on the pencil button, click on the folder button, and choose the script you want to edit.
Copy/type this code in the editor.

Scriptname DebugExampleScriptWithoutOBSEShort Variable01Short Variable02Short Variable03Begin GameModeSet Variable01 to 20Set Variable02 to (Variable01 * 2)Set Variable03 to ((Variable02 * 5) + Variable01)Message "Variable 1 is %.2f.  Variable 2 is %.2f.  Variable 3 is %.2f.", Variable01, Variable02, Variable03End
A. 2. Implement the edited script so it will run during the game.
Close the window and save the mod.


With OBSE:
B. 1. Edit a script:
Click on the pencil button, click on the folder button, and choose the script you want to edit.
Copy/type this code in the editor.

Scriptname DebugExampleScriptWithOBSEShort Variable01Short Variable02Short Variable03Begin GameModeSet Variable01 to 20Set Variable02 to (Variable01 * 2)Set Variable03 to ((Variable02 * 5) + Variable01)PrintToConsole "Variable 1 is %.2f.  Variable 2 is %.2f.  Variable 3 is %.2f.", Variable01, Variable02, Variable03End
B. 2. Implement the edited script so it will run during the game.
Close the window and save the mod.


With either version next time you play, you'll get a message (in the console or on screen) telling you the variables you specified in the script.
User avatar
Queen
 
Posts: 3480
Joined: Fri Dec 29, 2006 1:00 pm

Post » Mon May 07, 2012 6:07 pm

Objective: Avoiding Message Spam (With OBSE)

To avoid message spam with OBSE, you can use these functions:

AddItemNSRemoveItemNSEquipItemNSUnequipItemNSAddSpellNSRemoveSpellNS
All the no spam functions have the same syntax as their opposite message producing functions.

Here's an example script:

Scriptname NoMessageSpamExampleScriptBegin GamemodePlayer.AddItemNS DwarvenGauntlets, 1Player.RemoveItemNS DwarvenGauntlets, 1Player.EquipItemNS DwarvenGauntletsPlayer.UnequipItemNS DwarvenGauntletsPlayer.AddSpellNS StandardShield1NovicePlayer.RemoveSpellNS StandardShield1NoviceEnd

Next time you play the game, you won't realize an item/spell has been added/removed or equipped/unequipped.
User avatar
Jessica Lloyd
 
Posts: 3481
Joined: Fri Aug 25, 2006 2:11 pm

Post » Mon May 07, 2012 8:10 am

Great! Thanks con-tur-eh! Now we have to wait Felic or moderator and ask them to put it in the first post.
User avatar
Nathan Risch
 
Posts: 3313
Joined: Sun Aug 05, 2007 10:15 pm

Post » Mon May 07, 2012 2:17 pm

Good to know that this topic is available. Many of these subjects are asked over and over.
So, here is my contribution (from http://cs.elderscrolls.com/constwiki/index.php/User:QQuix)

Objective: Working with distances and angles

1. Three angle systems
The game uses three angle 'systems':

1a. World Angle
Range ? 0-360 - 0 degrees is up, increasing clockwise up to 360. (e.g: 90 = Right, 180 = Down, 270 = Left).
This is the most common. It is the angle you find in the CS for Reference Rotation.
This type of angle is returned by: GetAngle Z, GetStartingAngle
This type of angle must be provided for: SetAngle Z

1b Heading Angle
Range ? -180 to +180 - 0 degrees is up, increasing clockwise up to 180 and decreasing counterclockwise down to -180. (e.g: 90 = Right, 180 = Down, -90 = Left, -180 = Down).
This is used to tell how a second object is positioned in relation to a first object heading
This type of angle is returned by: GetHeadingAngle

1c.Trigonometric Angle

Range ? 0 to 360 - 0 degrees is right, increasing counterclockwise up to 360. (e.g: 90 = Up, 180 = Left, 270 = Down). This is the standard trigonometric angle system.
This type of angle must be provided for OBSE trigonometric functions: Sin, Cos, Tan, etc

2.Sample code
This code uses OBSE trig functions. Non-OBSE trig code can be found in the http://cs.elderscrolls.com/constwiki/index.php/ESM_Math_Library.

2a. DeltaX & DeltaY from Angle and distance
Useful when positioning an object at a given distance and angle from another object

;=================================; Get:  DeltaX and DeltaY; From:	Angle and distance;=================================set xAngle to xxxset xDistance to xxxif  xAngle <= 90	set xxTrigAngle  to 90 - xAngleelse	set xxTrigAngle to 450 - xAngleendif set xDeltaX to xDistance * cos xxTrigAngle set xDeltaY to xDistance * sin xxTrigAngle

2b. Angle and distance from DeltaX & DeltaY
Useful to calculate the horizontal (2D) distance between two objects or in situations where GetDistance is not reliable.
Useful to calculate the heading angle in situations where GetHeadingAngle is not reliable (non-actors).

;=================================; Get:  Angle and distance; From: DeltaX and DeltaY;=================================set xAngle to atan2 xDeltaX xDeltaY   ;	returns -180 to +180if xAngle  < 0  set xAngle to xAngle + 360   	;	convert to 0-360endifset xDistance to ( xDeltaX * xDeltaX ) + ( xDeltaY * xDeltaY )set xDistance to sqrt xDistance

2c. Adding two angles
Self explanatory

;=================================; Get:  Angle ; From: Adding two angles;=================================set xAngle to xAngleA + xAngleBif xAngle > 360  set xAngle to xAngle - 360endifif xAngle < 0  set xAngle to xAngle + 360endif
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Mon May 07, 2012 4:21 am

Excellent idea! I have already benefited from this thread thanks. :goodjob:
User avatar
Sammi Jones
 
Posts: 3407
Joined: Thu Nov 23, 2006 7:59 am

Post » Mon May 07, 2012 12:41 pm

Objective: Slide an object up and down

This script should be attached to an activator to move the object up or down each time the activator is activated.
The activator may be the object itself.
Change the numbers for speed and max displacement to fit your needs.
Can be easily adapted to sliding sideways.

scn SlidingObjectSCRIPTref xObjectshort xStdSpeedshort xSpeedshort xMaxDisplacementfloat xPosZfloat xPosMinfloat xPosMaxbegin onactivate	if xObject == 0		; First time only: set vars		;======================		; xStdSpeed positive: Object will initially go up 		; xStdSpeed negative: Object will initially go down		;======================		set xObject to aaqqActivator;  aaqqPlatform ; aaqqPaint		set xStdSpeed to -5 ; <<< Change to your liking  (units per second)		set xMaxDisplacement to 100   ; <<< Displacement limit		set xPosZ to xObject.getstartingpos z		if xStdSpeed > 0			set xPosMin to xPosZ			set xPosMax to xPosZ + xMaxDisplacement 		else			set xPosMax to xPosZ			set xPosMin to xPosZ - xMaxDisplacement 			set xStdSpeed to -xStdSpeed 		endif	endif	if xPosZ <= xPosMin 		set xSpeed to xStdSpeed 	else		set xSpeed to -xStdSpeed 	endifendbegin gamemode	if xSpeed == 0		return	endif	set xPosZ to xObject.getpos Z + xSpeed * getsecondspassed	if xPosZ > xPosMax		set xPosZ to xPosMax		set xSpeed to 0	endif	if xPosZ < xPosMin		set xPosZ to xPosMin		set xSpeed to 0	endif	xObject.setpos Z xPosZ	xObject.reset3Dstateend
User avatar
Queen Bitch
 
Posts: 3312
Joined: Fri Dec 15, 2006 2:43 pm

Post » Mon May 07, 2012 7:51 am

Bringing this up to the front with a thanks for this thread Felic!
User avatar
carrie roche
 
Posts: 3527
Joined: Mon Jul 17, 2006 7:18 pm

Post » Mon May 07, 2012 1:47 pm

Detecting collision of items (objects which can be held in containers)

The construction set defines collision sounds of havoked items explicitly, which can be detected to approximate an item's collision. Though this method has a high success rate and good accuracy, it's not completely fool proof. Inherently, the game engine doesn't play the collision sounds at times. From my testing, this has something to do with the mesh of the item. It seems that the bhkCollisionObject's bhkXYZShape needs to be triggered by the collision to cause the sound; ergo the material defined by the bhkXYZShape determines the sound being played. More about that aspect in this http://www.gamesas.com/bgsforums/index.php?showtopic=990278&hl=. This method requires OBSE.

Another method to detect collisions would be to check if the distance of the item from a fixed point reduces in an subsequent frame. More clearly, if the distance in the last frame was greater the distance in the current frame, it could possibly imply a collision. The obvious flaw in this method would be that this method detects collisions only if the item bounces off a surface, causing the distance to reduce. This method does not require OBSE.

Method 1 : Using collision sounds
OBSE's http://obse.silverlock.org/obse_command_doc.html#GetSoundPlaying function can determine if the collision sounds are being played during a frame, in the vicinity of a reference or otherwise.
 if ( rItem.getSoundPlaying "C*" 100 ); collision handling endIf
The numeric parameter can be modified to increase the sound detection radius. Currently, the code checks for any collision sound being played within 100 units of the item, which seems to be a radius good enough to gauge the item's collision. The material of the item/surface can be determined by checking for the particular collision sound associated with it. The sounds are defined in the Sound tab of the Object Window.

Method 2 : Using distance checks
 float fCurrentDistance float fLastDistance   ref rItem  begin gameMode	set fCurrentDistance to rItem.getDistance rMarker; where rMaker is a persistent reference and is in the same cell as the item 	if ( fCurrentDistance != fLastDistance )	   if ( fCurrentDistance < fLastDistance ); collision handling	   endIf 	   set fLastDistance to fCurrentDistance	endIf end
This method is not reliable for items being dropped down vertically. The item has to be moving horizontal to some extent to get the system to trigger the detection.
User avatar
Oyuki Manson Lavey
 
Posts: 3438
Joined: Mon Aug 28, 2006 2:47 am

Post » Mon May 07, 2012 2:17 pm

Bumping . . . for the benefit of those that may have missed this thread . . . very useful.
User avatar
Greg Cavaliere
 
Posts: 3514
Joined: Thu Nov 01, 2007 6:31 am

Post » Mon May 07, 2012 9:58 am

A small snippet of code that is extremely useful. It allows you to check when an actor value changes.

Here is it for level

If Level != Player.GetLevel		*Do Stuffs*	Set Level to Player.GetLevelEndif

Another example showing another way it can be used
Set cHealth to Player.GetAV HealthIf Health != cHealth  Set HealthDifference to Health - cHealth  Set Health to Player.GetAV HealthEndif
User avatar
Alada Vaginah
 
Posts: 3368
Joined: Sun Jun 25, 2006 8:31 pm

Post » Mon May 07, 2012 5:01 pm

Can some1 explain that last piece of code to us noobs? How it works and why it is, the way it is?
User avatar
Shelby Huffman
 
Posts: 3454
Joined: Wed Aug 08, 2007 11:06 am

Post » Mon May 07, 2012 3:53 am

Bump to prevent the thread from entering Oblivion.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Mon May 07, 2012 4:56 pm

Another bump, as I've just referenced some code here on another thread.
User avatar
Star Dunkels Macmillan
 
Posts: 3421
Joined: Thu Aug 31, 2006 4:00 pm

Previous

Return to IV - Oblivion