Author Topic: Script on module start  (Read 425 times)

Legacy_TheButterflyEffect

  • Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Script on module start
« on: June 30, 2012, 12:15:58 am »


                FFF I'm tearing out my hair trying to get my very first script to work properly and it won't.

I want this script to fire when the module starts. I want it to strip all of the vanilla crap out of the PC's inventory, then give the PC a piece of armor I made myself, then auto-equip it, then start the intro conversation.

However, the latter two things aren't happening and I do not know why. Please help. '<img'>

void main(){    object oItem;
    // Get the creature who triggered this event.    object oPC = GetEnteringObject();
    // Only fire for (real) PCs.    if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )        return;
    // Only fire once.    if ( GetLocalInt(OBJECT_SELF, "DO_ONCE") )        return;    SetLocalInt(OBJECT_SELF, "DO_ONCE", TRUE);
    // Give "worndress" to the PC.    CreateItemOnObject("worndress", oPC);
    // Have the PC perform a sequence of actions.    AssignCommand(oPC, ClearAllActions());    AssignCommand(oPC, ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "worndress"), INVENTORY_SLOT_CHEST));
    // Relieve the PC of its possessions.    oItem = GetFirstItemInInventory(oPC);    while ( oItem != OBJECT_INVALID )    {        DestroyObject(oItem);        oItem = GetNextItemInInventory(oPC);    }
    // Relieve the PC of its gold.    TakeGoldFromCreature(GetGold(oPC), oPC, TRUE);
    // The PC holds an inner dialog.    AssignCommand(oPC, ActionStartConversation(oPC, "intro", TRUE, FALSE));}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Script on module start
« Reply #1 on: June 30, 2012, 12:28:33 am »


               I haven't really looked at it yet but a script like this should go in the "OnClientEnter" event.
               
               

               
            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Script on module start
« Reply #2 on: June 30, 2012, 01:20:27 am »


               I would suggest giving the worndress after you strip them of the items and add a few delays to give the dress, equip the dress and to start the conversation. Like so.

DelayCommand(0.25, CreateItemOnObject("worndress", oPC));
DelayCommand(0.5, AssignCommand(oPC, ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "worndress"), INVENTORY_SLOT_CHEST));
DelayCommand(1.0, ActionStartConversation(oPC, "intro"));
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Script on module start
« Reply #3 on: June 30, 2012, 01:39:54 am »


               object oPC = GetEnteringObject();
if (!GetIsPC(oPC) || GetIsDM(oPC) || GetLocalInt(oPC, "intro") != 0) return;
SetLocalInt(oPC, "intro", 1);
int i;
object oItem;
for (i = 0; i < 18; i++)
{
oItem = GetItemInSlot(oPC, i);
DestroyObject(oItem);
}
oItem = GetFirstItemInInventory(oPC);
while (oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oPC);
}
TakeGoldFromCreature(GetGold(oPC), oPC, TRUE);
oItem = CreateItemOnObject("worndress", oPC);
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionEquipItem(oItem, INVENTORY_SLOT_CHEST));
AssignCommand(oPC, ActionStartConversation, "intro", TRUE, FALSE));


It should work (i typed this from my phone so there may be some error) i'm almost sure you don't need to delay the command...


Edit: you can place this script in the OnEnter of the starting area of your module
               
               

               


                     Modifié par Krevett, 30 juin 2012 - 12:48 .
                     
                  


            

Legacy_TheButterflyEffect

  • Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Script on module start
« Reply #4 on: June 30, 2012, 04:26:09 am »


               Sigh.... still not working. I'm using TK script generator to do this, but it still doesn't work like it should, the armor does not equip and the conversation does not start. I tried adding delays.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Script on module start
« Reply #5 on: June 30, 2012, 04:49:26 am »


               Did you put it in the OnClientEnter and not in the OnModuleLoad?

Better yet to make sure the player is fully "loaded", put a trigger around your starting point and put your script in the trigger's OnEnter event. This way your script won't fire until the player is actually in the module and has landed at the starting point.
               
               

               


                     Modifié par GhostOfGod, 30 juin 2012 - 03:50 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Script on module start
« Reply #6 on: June 30, 2012, 08:12:13 am »


               I put a similar script on the OnEnter into the starting area in my mod, as opposed to the OnClientEnter.  It's the same general theory as the trigger method GoG suggested, ensuring the player is fully loaded in before trying to assign any actions to them.
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Script on module start
« Reply #7 on: July 03, 2012, 03:11:15 pm »


                This script is straight out of my module and does pretty much what you want - stick it OnClientEnter:

void main ()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));
if (DoOnce==TRUE) return;
SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);
object oItem;oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem))   {   if (GetPlotFlag(oItem))      SetPlotFlag(oItem, FALSE);
   DestroyObject(oItem);
   oItem = GetNextItemInInventory(oPC);   }
int nInt;for (nInt=0; nInt<NUM_INVENTORY_SLOTS; nInt++)   {   oItem = GetItemInSlot(nInt, oPC);
   if (GetPlotFlag(oItem))         SetPlotFlag(oItem, FALSE);
DestroyObject(oItem);   }
AssignCommand(oPC, TakeGoldFromCreature(GetGold(oPC), oPC, TRUE));
//Give PC Properties item and dressing gown
CreateItemOnObject("renaarisignetrin", oPC);
CreateItemOnObject("dressinggown", oPC);
AssignCommand(oPC, ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "dressinggown"), INVENTORY_SLOT_CHEST));
AssignCommand(oPC, ActionEquipItem(GetItemPossessedBy(OBJECT_SELF, "renaarisignetrin"), INVENTORY_SLOT_RIGHTRING));
}


Of course, you'll need to change some of the tags to fit your module, but that works just perfectly for me. Start the conversation through a generic trigger, that way you can be sure that the loading screen has gone away and that the player is in control of their character.
               
               

               


                     Modifié par Mr. Versipellis, 03 juillet 2012 - 02:11 .