Skip to content

Trouble with "drop items to corspe" script from the nwnwiki

Hey everyone, I'm new to scripting and have been beginning to implement certain scripts into my modules, I haven't really written any scripts on my own, but defer to other resources like Script Generator and try to understand how they work in reference to how the script is written. Recently I wanted to implement a death script where when someone dies/respawns, they leave behind a corpse that has their gold and belongings, but it isn't firing properly and I'm unsure as to whether or not I've neglected to do something, or possibly the script isn't compatible with the EE. I got the script from the NWNwiki
Here's the aforementioned script http://nwn.wikia.com/wiki/Drop_items_to_corpse

Comments

  • dunahandunahan Member Posts: 139
    Hello Ranan,
    I clicked your link, but there was no script listed. I could done something wrong, cause I use my mobile to read and answer.
    But it would be better to show this script within this forum (or best, ask at neverwintervault.org) ;)
  • RananRanan Member Posts: 34

    Here's the script as it appears on the nwnwiki

    **********************************
    Script: Drop Items To Corpse
    Created By: Jaden Wagener
    Created On: 08/29/02
    **********************************/
    //Drops all player's equipment and half of gold onto the corpse.
    //Combination of Diablo I and II death styles.
    //Script should be placed in module's OnDeath slot
    void main()
    {
    //Set variables
    int xCount, xGold;
    object xPC, xCorpse, xItem;
    location xLoc;
    //Get player and find locations
    xPC = GetLastPlayerDying();
    xLoc = GetLocation(xPC);
    //Create corpse at player's feet
    xCorpse = CreateObject(OBJECT_TYPE_PLACEABLE,"corpse002",xLoc);
    //Drop equipment on corpse
    for (xCount = 1; xCount < 15; xCount++)
    {
    switch (xCount)
    {
    case 1: xItem = GetItemInSlot(INVENTORY_SLOT_ARMS,xPC); break;
    case 2: xItem = GetItemInSlot(INVENTORY_SLOT_ARROWS,xPC); break;
    case 3: xItem = GetItemInSlot(INVENTORY_SLOT_BELT,xPC); break;
    case 4: xItem = GetItemInSlot(INVENTORY_SLOT_BOLTS,xPC); break;
    case 5: xItem = GetItemInSlot(INVENTORY_SLOT_BOOTS,xPC); break;
    case 6: xItem = GetItemInSlot(INVENTORY_SLOT_BULLETS,xPC); break;
    case 7: xItem = GetItemInSlot(INVENTORY_SLOT_CHEST,xPC); break;
    case 8: xItem = GetItemInSlot(INVENTORY_SLOT_CLOAK,xPC); break;
    case 9: xItem = GetItemInSlot(INVENTORY_SLOT_HEAD,xPC); break;
    case 10: xItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,xPC); break;
    case 11: xItem = GetItemInSlot(INVENTORY_SLOT_LEFTRING,xPC); break;
    case 12: xItem = GetItemInSlot(INVENTORY_SLOT_NECK,xPC); break;
    case 13: xItem = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,xPC); break;
    case 14: xItem = GetItemInSlot(INVENTORY_SLOT_RIGHTRING,xPC); break;
    }
    if (GetIsObjectValid(xItem))
    {
    AssignCommand(xCorpse,ActionTakeItem(xItem,xPC));
    }
    }
    //Now drop half of player's gold.
    xGold = (GetGold(xPC)/2);
    AssignCommand(xItem,TakeGoldFromCreature(xGold,xPC,FALSE));
    //Now let's pop the death GUI
    DelayCommand(2.5, PopUpDeathGUIPanel(xPC,TRUE,TRUE));
    }
  • dunahandunahan Member Posts: 139
    Thank you!
    Okay, for me it seems correct, but this line here isn't it:
    CreateObject(OBJECT_TYPE_PLACEABLE,"corpse002",xLoc);
    I think those " " around corpse002 shouldn't be needed... Eventually the tag/resref there (I'm talking about that corpse002) isn't right. I can't check that now, would do it tomorrow.
  • squattingmonksquattingmonk Member Posts: 59
    edited December 2017
    There are two problems that prevent this script from functioning correctly. First, this line:
    //incorrect xPC = GetLastPlayerDying(); // correct xPC = GetLastPlayerDied();
    Rationale: The first will work on an OnPlayerDying script but not OnPlayerDeath.

    The second problem is the line:
    //incorrect xCorpse = CreateObject(OBJECT_TYPE_PLACEABLE,"corpse002",xLoc); //correct xCorpse = CreateObject(OBJECT_TYPE_PLACEABLE,"plc_corpse1",xLoc);
    Rationale: Unless you've created a placeable with the resref "corpse002", this will not do anything. The default corpse placeable has a resref of "plc_corpse1". I suspect the author of this script tried to view the blueprint of the placeable by right-clicking it in the palette and choosing "Edit copy", which will create a copy of the item with a unique resref.
    Post edited by squattingmonk on
  • squattingmonksquattingmonk Member Posts: 59
    edited December 2017
    For learning purposes: here is a re-written version of this script that does the same thing. Look at the differences between the two and see if you can figure out why I made these changes.
    void main() { object oPC = GetLastPlayerDied(); location lLoc = GetLocation(oPC); // Create a corpse at the PC's location object oCorpse = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_corpse1", lLoc); // Loop through the PC's equipped items and move them to the corpse int nSlot; object oItem; for (nSlot = 0; nSlot < 14; nSlot++) { oItem = GetItemInSlot(nSlot, oPC); AssignCommand(oCorpse, ActionTakeItem(oItem, oPC)); } // Take half the player's gold and place it on the corpse int nGold = GetGold(oPC) / 2; AssignCommand(oCorpse, TakeGoldFromCreature(nGold, oPC)); // Pop up the death GUI DelayCommand(2.5, PopUpDeathGUIPanel(oPC)); }
  • RananRanan Member Posts: 34
    Thanks a ton for this! I also really appreciate explaining what the parts of the script do, this is exactly the kind of information I'm looking for
Sign In or Register to comment.