Jump to content

Home

Help with Scripting!


Darth_HaHa

Recommended Posts

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:

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...