Aller au contenu

Photo

Script on module start


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
TheButterflyEffect

TheButterflyEffect
  • Members
  • 1 407 messages
 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. :(

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));}

#2
GhostOfGod

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

#3
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
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"));

#4
Krevett

Krevett
  • Members
  • 104 messages
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 .


#5
TheButterflyEffect

TheButterflyEffect
  • Members
  • 1 407 messages
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.

#6
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#7
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
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.

#8
Mr. Versipellis

Mr. Versipellis
  • Members
  • 206 messages
 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 .