PDA

View Full Version : Help with Scripting!


Darth_HaHa
12-09-2007, 12:37 PM
Okay, I'm pretty much a complete noob at modding. Scripting is the hardest part for me, and I'm trying to figure it out! :fist:

So I wrote this script for K1 and each time I try to compile it, I get a "Syntax Error at 'string constant' " on lines 15 and 17

Here's my script using a recruited Darth Bandon as an example:

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

GiveXPToCreature(GetFirstPC(), 2500);

AddMultiClass(3, GetObjectByTag("p_bandon"));
object me = GetFirstPC();
CreateItemOnObject("g_a_mstrrobe01", me);
CreateItemOnObject("g_w_lghtsbr03", me);
CreateItemOnObject("g_w_dblsbr003", me);

AssignCommand (GetFirstPC(), ActionEquipItem (o"g_a_mstrrobe01", nINVENTORY_SLOT_BODY=1);

AssignCommand (GetFirstPC(), ActionEquipItem (o"g_w_dblsbr003",

nINVENTORY_SLOT_LEFTWEAPON=5);

}


Can anyone help me fix this?
:giveup:

Darth InSidious
12-10-2007, 05:42 AM
Try this:


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

GiveXPToCreature(GetFirstPC(), 2500);

AddMultiClass(3, GetObjectByTag("p_bandon"));
object me = GetFirstPC();
CreateItemOnObject("g_a_mstrrobe01", me);
CreateItemOnObject("g_w_lghtsbr03", me);
CreateItemOnObject("g_w_dblsbr003", me);

AssignCommand(GetFirstPC(), ActionEquipItem("g_a_mstrrobe01", nINVENTORY_SLOT_BODY=1);

AssignCommand(GetFirstPC(), ActionEquipItem("g_w_dblsbr003", nINVENTORY_SLOT_LEFTWEAPON=5);

}

Hope that helps. :)

DarthJebus05
12-10-2007, 06:23 AM
Will that script work for the Janitor on Taris?

Darth InSidious
12-10-2007, 09:04 AM
Provided you changed the tag in the GetObjectByTag() function call, it should do.

DarthJebus05
12-10-2007, 09:18 AM
Cool. Every time I tried to make the Janitor recruitable, he just wont join my party. Would I be able to use your script, Darth_HaHa? And of course if I use it for my mod, you will get full credit for it.

stoffe
12-10-2007, 12:12 PM
So I wrote this script for K1 and each time I try to compile it, I get a "Syntax Error at 'string constant' " on lines 15 and 17


The problem on those lines are that you are providing an undeclared variable followed by a string constant where the script expects an object reference, and are assigning a value to an undeclared variable where it expects an integer value to be provided. You are also missing closing parenthesises for your AssignCommand() function calls.

Further, the if (GetIsPC(oEntering)) line only affects the next statement directly following it (the one giving XP), making the rest of the script run regardless whether the object triggering the OnEnter event (which I assume you run yoru script from) is the player or someone else since you have no block delimiters.

Finally, it seems like you're trying to equip a two-handed weapon in the off-hand weapon slot, whereas twohanded weapons only can be wielded in the right hand weapon slot.

Here is an example variant of your script with those problems fixed. :)

void main() {
object oPC = GetFirstPC();
if (oPC == GetEnteringObject()) {
GiveXPToCreature(oPC, 2500);

AddMultiClass(CLASS_TYPE_JEDIGUARDIAN, GetObjectByTag("p_bandon"));

CreateItemOnObject("g_w_lghtsbr03", oPC);

AssignCommand(oPC, ActionEquipItem( CreateItemOnObject("g_a_mstrrobe01", oPC), INVENTORY_SLOT_BODY));
AssignCommand(oPC, ActionEquipItem( CreateItemOnObject("g_w_dblsbr003", oPC), INVENTORY_SLOT_RIGHTWEAPON));
}
}


Depending on where the script is run from you may also need to add some cutoff condition to ensure it is only run once, otherwise the XP and items will be given any time the player triggers the OnEnter event of the object this script is assigned to.

Darth Xander
12-10-2007, 01:12 PM
Could someone explain to me what GetEnteringObject does?
Oh and welcome to LucasForums Darth_HaHa.

stoffe
12-10-2007, 02:08 PM
Could someone explain to me what GetEnteringObject does?

When used in a script triggered from an OnEnter event (belonging to an object such as an area, persistent AoE or a trigger), it returns an object reference to the player or NPC who was responsible for triggering the event.

In the case of an area's OnEnter event, it triggers every time the player transitions into an area, loads a savegame into an area or an NPC or party member is spawned into the area.

So for example if you transition into an area with Bastila and Carth in the party, that area's OnEnter event script is triggered three times, where the GetEnteringObject() function returns an object reference to the player character, Carth and Bastila respectively. This is why you often check if the entering object is the player in Area OnEnter scripts when you only want something done once when the player enters.

(If, for example, you spawn an NPC into the area in the Area OnEnter script and have no checks for who is entering the area would be flooded with copies of that NPC. This is since spawning the NPC triggers the area's OnEnter script for that NPC, which in turn would spawn another NPC, triggering the script again etc.)

In the case of a persistent AoE or a trigger the script runs whenever an player or NPC moves into the "hot zone" of the trigger/AoE and the function returns an object reference to the player/npc in question.

It shouldn't be used in scripts which aren't run by an OnEnter event, since the return value will be unreliable/invalid.

Darth_HaHa
12-10-2007, 04:16 PM
Thanks!
I'll try it out and see if it works!

Darth_HaHa
12-10-2007, 04:22 PM
And go right ahead DarthJebus05.
Of course, you might not want to use mine....

:)

Give the other guys credit for the script. They wrote it!
Thanks again everyone!

Qui-Gon Glenn
12-12-2007, 12:37 AM
:)

Give the other guys credit for the script. They wrote it!
Thanks again everyone!

You gave it a real good shot though. You deserve a mention at least :)

Back to studying the Lexicon....