Jump to content

Home

Handy include for Module Building


Recommended Posts

Reference this thread for questions

 

Since I've still got my tutorial forum privileges I figured it would be worth referring this thing here too

 

A while back (2008 to be precise) I wrote this script for module building, a debugging function in addition to several useful functions which I figure will be more useful to you guys than myself now - It's been a while but IIRC it compiles fine - you just need to use the line:

[color="DarkOrchid"]#include "gm_include"[/color]

 

Luckily I documented it, I'm pretty good at forgetting what I write these for so feel free to pick it apart

/*
:: Written by Glovemaster - 26/12/08 ::
Quanon and Glovemaster's Scrapyard Games Modification

[color="DarkOrchid"]gm_include.nss[/color]
*/

// Declaring functions... So I can use each function in each
[color="Lime"]void debug(string Message, int Time = FALSE);
vector getRandomVector(float fDistance);
void applyEffectNearObject(int DURATION_TYPE, effect eEffect, object oTarget, float fDistance = 1.0, float fDur = 0.0);
void createVisualEffectsArc(float fDuration, object oStart, location lTarget, int iEffect, int isBeam = TRUE);
int calculateDamage(int nDice, int nDiceSize);
float locationToObject(location lPoint, object oTo);
void checkWeaponSlotsForItem(object oCheck, string itemTag, int requiredCert);[/color]

[color="Cyan"]/*
-[ debug ]---------------------------------------------------
Sends a message to the Party Leader for debugging purposes,
generally to see if some "if" statement has triggered or not.
-------------------------------------------------------------
*/[/color]
void debug(string Message, int Time = FALSE) {
string TimeNote = "";
if (Time) {
	int Hour = GetTimeHour();
	int Minute  = GetTimeMinute();
	int Second  = GetTimeSecond();
	TimeNote = (Hour < 10 ? "0" : "") + IntToString(Hour) + ":" +
				(Minute  < 10 ? "0" : "") + IntToString(Minute) + ":" +
				(Second  < 10 ? "0" : "") + IntToString(Second) + " ";
}
SendMessageToPC(GetFirstPC(), "[ DEBUG " + TimeNote + "]" + Message);
AurPostString("[ DEBUG " + TimeNote + "]" + Message, 0, 0, 5.0); // Removed I assume, since AFAIK it does nothing.
}

[color="Cyan"]/*
-[ getRandomVector ]-----------------------------------------
Get a random vector within fDistance. This is because
GetRandomDestination actually only generates 5 random
destinations and looks crappy in the effect I was going for.
-------------------------------------------------------------
*/[/color]
vector getRandomVector(float fDistance) {
float fAngle = IntToFloat((Random(361) + (Random(100) / 100))); // Pretty damn random.
vector vRandom = AngleToVector(fAngle);
	// Annoyingly, vectors can't be multiplyed in KotOR ¬.¬ well I get a compile error so we'll just play it this way:
		vRandom.x = vRandom.x * fDistance;
		vRandom.y = vRandom.y * fDistance;
return vRandom;
}

[color="Cyan"]/*
-[ applyEffectNearObject ]-----------------------------------
EffectBeam() when set to miss, doesn't actually miss. Or do
anything at all for that matter, Therefore we need to create
a function that does. Also, apparently you can't apply
EffectBeam() to a location? Well we'll use nodes anyway.
-------------------------------------------------------------
*/[/color]
void applyEffectNearObject(int DURATION_TYPE, effect eEffect, object oTarget, float fDistance = 1.0, float fDur = 0.0) {
vector vAdd = AngleToVector(GetFacing(oTarget) - 180.0);
		vAdd.x = (vAdd.x * fDistance);
		vAdd.y = (vAdd.y * fDistance);
vector vNear = getRandomVector(1.0) + vAdd;
object oNode = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_invisible", Location(vNear, 0.0));
	AssignCommand(oNode, DestroyObject(oNode, (fDur + 1.0)));
ApplyEffectToObject(DURATION_TYPE, eEffect, oNode, fDur);
}

[color="Cyan"]/*
-[ createVisualEffectsArc ]----------------------------------
Creates an arc of nodes, works better as a beam but over a 
short distance then its fine to use visual effects.
Lightning is advised for this as it does not "bend" in an
ugly way. I initially used this for fire but it was rather
crude.
-------------------------------------------------------------
*/[/color]
void createVisualEffectsArc(float fDuration, object oStart, location lTarget, int iEffect, int isBeam = TRUE) {
// Right then, we'll have 10 nodes making up the arc.
object oNode, oNode1, oNode2, oNode3, oNode4, oNode5, oNode6, oNode7, oNode8, oNode9, oNode10;
float fDistanceOver = locationToObject(lTarget, oStart);
float fGap = fDistanceOver / 10;
// Get the direction to create the arc and change magnitude of the vector to fGap.
vector vDir = GetPosition(oStart) - GetPositionFromLocation(lTarget);
		vDir = AngleToVector(VectorToAngle(vDir)); // Seems wierd, I know
			vDir.x = vDir.x * fGap;
			vDir.y = vDir.y * fGap;

// Lets get those nodes made then.
vector vPos;
float fHeight = 1.8;
int i;
for(i = 1; i <= 10; i++) {
	// Set the node's height.
	if(i <= 4) { // Going up.
		fHeight += 1.0; // Up 1m each time.
	}
	else if(i >= 6) { // Going down.
		fHeight -= 1.45; // Down 65cm each time. By my maths: 20cm * 4 is 80cm + our 1.8m is 2.6m
						 // divided by 4 more steps and we get 65cm? BTW unto the Americans:
						 // its MATHS not MATH you illiterate f*$@ers. -.-
	}
	vPos = vDir;
		vPos.x = vPos.x * i;
		vPos.y = vPos.y * i;
		vPos.z = fHeight;
	oNode = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_invisible", Location(vPos, 0.0));
	AssignCommand(oNode, DestroyObject(oNode, fDuration + 1.0));
	// If only KotOR had arrays. ¬.¬
	if(i == 1) oNode1 = oNode;
	else if(i == 2) oNode2 = oNode;
	else if(i == 3) oNode3 = oNode;
	else if(i == 4) oNode4 = oNode;
	else if(i == 5) oNode5 = oNode;
	else if(i == 6) oNode6 = oNode;
	else if(i == 7) oNode7 = oNode;
	else if(i == 8) oNode8 = oNode;
	else if(i == 9) oNode9 = oNode;
	else if(i == 10) oNode10 = oNode;
}

if(isBeam) {
	effect eBeam = EffectBeam(iEffect, oNode1, BODY_NODE_CHEST);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode2, fDuration);
	eBeam = EffectBeam(iEffect, oNode2, BODY_NODE_CHEST);
	DelayCommand(0.2, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode3, fDuration));
	eBeam = EffectBeam(iEffect, oNode3, BODY_NODE_CHEST);
	DelayCommand(0.4, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode4, fDuration));
	eBeam = EffectBeam(iEffect, oNode4, BODY_NODE_CHEST);
	DelayCommand(0.6, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode5, fDuration));
	eBeam = EffectBeam(iEffect, oNode5, BODY_NODE_CHEST);
	DelayCommand(0.8, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode6, fDuration));
	eBeam = EffectBeam(iEffect, oNode6, BODY_NODE_CHEST);
	DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode7, fDuration));
	eBeam = EffectBeam(iEffect, oNode7, BODY_NODE_CHEST);
	DelayCommand(1.2, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode8, fDuration));
	eBeam = EffectBeam(iEffect, oNode8, BODY_NODE_CHEST);
	DelayCommand(1.4, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode9, fDuration));
	eBeam = EffectBeam(iEffect, oNode9, BODY_NODE_CHEST);
	DelayCommand(1.6, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oNode10, fDuration));
}
else {
	effect eVis = EffectVisualEffect(iEffect);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode1, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode2, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode3, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode4, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode5, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode6, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode7, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode8, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode9, fDuration);
	ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oNode10, fDuration);
}
}

[color="Cyan"]/*
-[ calculateDamage ]-----------------------------------------
Calculates damage to deal using nDice amount of dice with
nDiceSize faces.
-------------------------------------------------------------
*/[/color]
int calculateDamage(int nDice, int nDiceSize) {
// Calculate a reasonable amount of damage to deal.
int iDamage = 0; // Start off, no damage.
switch(nDiceSize) {
	case 2: 	iDamage = d2(nDice); 	break;
	case 3: 	iDamage = d3(nDice); 	break;
	case 4: 	iDamage = d4(nDice); 	break;
	case 6: 	iDamage = d6(nDice); 	break;
	case 8: 	iDamage = d8(nDice); 	break;
	case 10: 	iDamage = d10(nDice); 	break;
	case 12: 	iDamage = d12(nDice); 	break;
	case 20: 	iDamage = d20(nDice); 	break;
	case 100: 	iDamage = d100(nDice); 	break;
	default:
		iDamage = Random(nDice * nDiceSize) + 1; // Otherwise just get a random number.
		if (iDamage < nDice) iDamage = nDice; // Not too low ofc. XD
		break;
}

return iDamage;
}

[color="Cyan"]/*
-[ locationToObject ]----------------------------------------
Just a quick GetDistanceBetweenLocations() only with a
location and an object.
-------------------------------------------------------------
*/[/color]
float locationToObject(location lPoint, object oTo) {
location lTo = GetLocation(oTo);
return GetDistanceBetweenLocations(lPoint, lTo);
}

[color="Red"]/*
-[ checkWeaponSlotsForItem ]---------------------------------
Checks certain weapons slots for an item with itemTag, this
is for Scrapyard Games only.
-------------------------------------------------------------
*/
// Cut this one out since it relied on global vars for SG[/color]

 

I've also included the Notepad++ Syntax User Defined Language I threw together to help with writing your scripts. And also wish you all the best with modding and I'm glad to see this community is still going

Notepad++ Syntax.zip

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...