PDA

View Full Version : Little help with a script [K1]


sekan
01-06-2008, 07:05 AM
Hi ,

I'm trying to make a script that spawns two npcs and start a conversation when i open a door. But i get a failure in my script that says: Error Unexpected end of file.

This is the script I'm trying to make.


void main()
{
object oEntering = GetEnteringObject();
object oPC=GetFirstPC();
if (GetIsPC(oEntering))
{


vector vPos;
float fAngle;

vPos.x = 84.76;
vPos.y = 68.72;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_tareelok", Location(vPos, fAngle));



vector vPos;
float fAngle;

vPos.x = 79.67;
vPos.y = 68.86;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_garrum", Location(vPos, fAngle));


ActionStartConversation(GetFirstPC(),"dan13_cort");


DestroyObject(OBJECT_SELF);


}


Can anybody tell me where the error is or give me a script that is working?

Stream
01-06-2008, 07:32 AM
I'm not sure if this is the problem but something doesn't look right with the conditional part of the script, try this and see if it works
void main()
{
object oPC = GetFirstPC();

if (GetEnteringObject() == oPC)
return;


vector vPos;
float fAngle;

vPos.x = 84.76;
vPos.y = 68.72;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_tareelok", Location(vPos, fAngle));



vector vPos;
float fAngle;

vPos.x = 79.67;
vPos.y = 68.86;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_garrum", Location(vPos, fAngle));


ActionStartConversation(GetFirstPC(),"dan13_cort");


}

I'm not sure what object you were wanting to destroy but it's probably best if you write a new script to fire at the end of the conversation, something like this should work;
void main() {


DestroyObject(GetObjectByTag("INSERT_TAG_HERE", 0), 0.0, 0, 0.0, 0);

}

I hope this helps.

Kind Regards
--Stream

sekan
01-06-2008, 08:29 AM
void main()
{
object oPC = GetFirstPC();

if (GetEnteringObject() == oPC)
return;


vector vPos;
float fAngle;

vPos.x = 84.76;
vPos.y = 68.72;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_tareelok", Location(vPos, fAngle));



vector vPos;
float fAngle;

vPos.x = 79.67;
vPos.y = 68.86;
vPos.z = 5.03;
fAngle = 0.0;

CreateObject(OBJECT_TYPE_CREATURE, "dan13_garrum", Location(vPos, fAngle));


ActionStartConversation(GetFirstPC(),"dan13_cort");


}

When i compile this it says: Error varible "vpos" defined multiple times in same scope and Error varible "fAngle" defined multiple times in same scope

Then when i add a { between them i get: Error Unexpected end of file
Hmm what if i... Yes i manged to fix it thanks for the help.

Darth333
01-06-2008, 09:05 AM
You are declaring vpos and fangle more than once in your script. Check lines 9 and 21. You do the same thing with fAngle.

In any event, it can be simplified to: (also, you stop the execution of the script by doing a return when the pc enters the area: you will not spawn anything if this is an onenter script). Just make sure to insert the proper npc tags where indicated


void main()
{


object oEntering = GetEnteringObject();
object oPC=GetFirstPC();
if (GetIsPC(oEntering))
{
// prevent clones to be created each time the pc enters the area - ( edit: this
// version checks if the npc already exists or use a local boolean as in stoffe's
// example below. Mine is good only if you don't destroy the npc afterwards.)
//You can use the tag of any of the two npcs...you do not need both

if (!GetIsObjectValid(GetObjectByTag("my_npc_tag")))
{
CreateObject(OBJECT_TYPE_CREATURE, "dan13_tareelok", Location(Vector(84.76,68.72,5.03), 0.0));
CreateObject(OBJECT_TYPE_CREATURE, "dan13_garrum", Location(Vector(79.67,68.86,5.03), 0.0));
AssignCommand ((GetObjectByTag("npcwhoshouldspeak_tag")), ActionDoCommand(ActionStartConversation(oPC,"dan13_cort")));
}
}

}

stoffe
01-06-2008, 09:11 AM
Hi ,

I'm trying to make a script that spawns two npcs and start a conversation when i open a door. But i get a failure in my script that says: Error Unexpected end of file.


There are three problems with your script as I can see:
The first one, causing the Unexpected End of File error, is caused by not having a closing } at the end of your If-statement checking if the entering object is is a player.

The second is caused by re-declaring the vPos and fAngle variables multiple times in the script. You should only declare them once, then you can change their values as needed in the script.

The third problem is that you are trying to make the door start a conversation with the player and then immediately destroy the door from the game world. Presumably you want to start conversation with one of the NPCs you just spawned instead of the door.

You likely also want a blocker condition to ensure this is only done once. In the case of a door it might not be that necessary since players can't close or interact with a door they've opened in KotOR, but just in case. :)

void main() {
object oEntering = GetEnteringObject();
object oPC=GetFirstPC();

if ((oEntering == oPC) && !GetLocalBoolean(OBJECT_SELF, 40)) {
vector vPos;
float fAngle = 0.0;

vPos.x = 84.76;
vPos.y = 68.72;
vPos.z = 5.03;
object oNPC = CreateObject(OBJECT_TYPE_CREATURE, "dan13_tareelok", Location(vPos, fAngle));


vPos.x = 79.67;
vPos.y = 68.86;
vPos.z = 5.03;
CreateObject(OBJECT_TYPE_CREATURE, "dan13_garrum", Location(vPos, fAngle));

SetLocalBoolean(OBJECT_SELF, 40, TRUE);
DelayCommand(0.5, AssignCommand(oNPC, ActionStartConversation(oPC, "dan13_cort", FALSE, 0, TRUE)));
}
}

sekan
01-06-2008, 01:38 PM
Thank you both you have helped a lot :D

Can just somebody explain how to make a npc start a dialog when your just walking towards the npc?

Marius Fett
01-06-2008, 03:16 PM
Can just somebody explain how to make a npc start a dialog when your just walking towards the npc?

You want an NPC to start talking to you when he sees you I think?

This should work:

void main()
{
ActionStartConverstaion(GetFirstPC(), "dlghere", 0, 0, 0, "", "", "", "", "", "", 0);
}

Replace the dlghere with the name of the conversation and set it as thw NPC's on notice script.

Hope this helped :)

sekan
01-06-2008, 03:39 PM
You want an NPC to start talking to you when he sees you I think?

Yes that right

void main()
{
ActionStartConverstaion(GetFirstPC(), "dlghere", 0, 0, 0, "", "", "", "", "", "", 0);
}

I get an error: Undeclered identifer "ActionstartConversation"

Darth Xander
01-06-2008, 03:42 PM
Don't forget to put the name of your script in the OnOpen box of your utc (door) file.

Marius Fett
01-06-2008, 03:51 PM
Yes that right

void main()
{
ActionStartConverstaion(GetFirstPC(), "dlghere", 0, 0, 0, "", "", "", "", "", "", 0);
}

I get an error: Undeclered identifer "ActionstartConversation"

Well that's odd...

It compiled for me...

Try this one instead:

void main()
{

object oPC = GetLastPerceived();

if (!GetIsPC(oPC)) return;

if (!GetLastPerceptionSeen()) return;
object oTarget;
oTarget = GetObjectByTag("NPC_TAG");

AssignCommand(oTarget, ActionStartConversation(oPC, "DLG_NAME"));

}

Ferc Kast
01-06-2008, 03:58 PM
I get an error: Undeclered identifer "ActionstartConversation"

Try using the following script:

void main()
{
ActionStartConversation(GetFirstPC(),"dlghere");
}

I dunno why the other won't work for you, however this should compile very nicely.

EDIT: Unless DDD posted as I made this post.

sekan
01-06-2008, 04:13 PM
Try using the following script:

void main()
{
ActionStartConversation(GetFirstPC(),"dlghere");
}

I dunno why the other won't work for you, however this should compile very nicely.

EDIT: Unless DDD posted as I made this post.

Thanks it works now