View Single Post
Old 01-08-2012, 12:07 AM   #36
Senior Member
JCarter426's Avatar
Join Date: Feb 2008
Location: Look to your left.
Posts: 1,641
Yeah, I've only seen SetCommandable used in certain combat scripts, and NPC exit scripts (so you can't talk to them as they're leaving).

EDIT: I managed to resolve my problem, but I guess some of you might be interested in the script anyway, so here you go:
void main() {

string sParam = GetScriptStringParameter();
int iFaction = GetScriptParameter(1);
int iAll = GetScriptParameter(2);
int iP3 = GetScriptParameter(3);

int iNum;
	if( iP3 == 0 ) iNum = 1;
	else iNum = iP3;

object oCreature;
	string sTag;

	if( sParam == "OBJECT_NEAREST" ){
		oCreature = GetNearestObject(1, OBJECT_SELF, iNum);
		sTag = GetTag(oCreature);
	else {
		sTag = sParam;
		oCreature = GetNearestObjectByTag(sTag, OBJECT_SELF iNum);

ChangeToStandardFaction(oCreature, iFaction);
DelayCommand(1.0, AssignCommand(oCreature, ActionAttack(GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oCreature, 1, -1, -1, -1, -1 ), 0)));

if( iAll > 0 ){

	int i = 1;

	for(;;) {
		object oCreature1 = GetNearestObjectByTag(sTag, OBJECT_SELF, i);
		if( GetIsObjectValid(oCreature1) ){
			ChangeToStandardFaction(oCreature1, iFaction);
			DelayCommand(1.0, AssignCommand(oCreature1, ActionAttack(GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oCreature1, 1, -1, -1, -1, -1 ), 0)));
		else break;


This changes an NPC's faction - or, depending on how the parameters are set up, all NPCs with the same tag. And in case you're wondering, the ActionAttack is in there because some factions don't seem to immediately attack their enemies on sight.

My problem was that one NPC seemed to be excluded 95% of the time, which I resolved by using GetNearestObjectByTag rather than GetObjectByTag, which is screwy... clearly why GetNearestObjectByTag exists. However, GetObjectByTag does recognize 0, and inputting 0 doesn't immediately crash the game. So there's that.

Last edited by JCarter426; 01-08-2012 at 07:46 AM.
JCarter426 is offline   you may: quote & reply,