Author Topic: Death Script  (Read 493 times)

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« on: June 08, 2011, 09:38:34 am »


               Hi, Once again im after your help.
 
I need a script that ondeath of a boss will randomly select items and amount from a store and drop it ditectly into all players inventory that are in the same area as the kill

Hope this makes sence.

Thanks
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
Death Script
« Reply #1 on: June 08, 2011, 12:37:42 pm »


               If you are looking for help, you can loop through a merchants inventory with the first/next item in inventory functions. Make some check for bosses, like local integer and check it on death. Create a random number, loop through items, reducing one from that number every loop and if you loop through them all start from the first item again. Then another random number that would be the amount. After that, just get first/next object in area, check for PC, if it is, give them the item.

If however, you are looking for someone to write the complete script for you... Well, that requires certain mental state that I am lacking right now.
               
               

               


                     Modifié par Xardex, 08 juin 2011 - 11:39 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« Reply #2 on: June 08, 2011, 03:49:30 pm »


               yes im in need of someone to write it for me

Many thanks
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Death Script
« Reply #3 on: June 08, 2011, 06:49:33 pm »


               Well there are a few unanswered questions here. Not sure what you mean by random items and amount exactly.

~Do you want all the players to get the same random item or each player to get a different random item?
~What's the maximum amount of the random items the players can get?
~Can the players get multilples of more than one random item?
~Are you sure you want any player in the area to get the item or is it supposed to be any player in the party of the killer or within a certain distance of the killer?
~Do you want the items removed/destroyed from the store or will these items just be copies of items in the store?

Perhaps you could explain what types of items this store will have and a bit more about what you want to happen. Walk us through the scenario.

So far from the information you've given I kinda see something like this:


//OnDeath Boss
void CopyItemToAllPlayersInArea(object oItem, object oArea)
{
    object oPC = GetFirstPC();
    while (GetIsObjectValid(oPC))
    {
        if (GetArea(oPC) == oArea)
        {
            CopyItem(oItem, oPC, TRUE);
        }
        oPC = GetNextPC();
    }
}

void main()
{
    object oArea = GetArea(OBJECT_SELF);
    object oStore = GetNearestObjectByTag("Tag of store", OBJECT_SELF, 1);
    object oItem = GetFirstItemInInventory(oStore);

    while (GetIsObjectValid(oItem))
    {
        //How do you want to randomize the items from the store?
        CopyItemToAllPlayersInArea(oItem, oArea);
        oItem = GetNextItemInInventory(oStore);
    }
}
               
               

               


                     Modifié par GhostOfGod, 08 juin 2011 - 05:54 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« Reply #4 on: June 08, 2011, 08:27:12 pm »


               Hi ghost,

I want all players in the area to get different random gear and amount if possible. max number i recon per player about 4 - 6, and do not remove items from the store. no i dont want players to get multiples of the same item. hope this helps

Also I have tested the above script and it seems to be pulling loot in order fron the store not random

Thnaks
               
               

               


                     Modifié par Madasahatter, 08 juin 2011 - 07:36 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Death Script
« Reply #5 on: June 08, 2011, 09:36:28 pm »


               While I'm not the best scripter and if I had more time I could probably come up with something better, something like this might work for you:

//OnDeath Boss
void CopyItemToAllPlayersInArea(object oItem, object oArea)
{
    object oPC = GetFirstPC();
    effect eNeg = EffectDamage(20, DAMAGE_TYPE_NEGATIVE);
    while (GetIsObjectValid(oPC))
    {
        if (GetArea(oPC) == oArea)
        {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eNeg, oPC);
            if (!GetIsDead(oPC))
            CopyItem(oItem, oPC, TRUE);
        }
        oPC = GetNextPC();
    }
}

void main()
{
    object oArea = GetArea(OBJECT_SELF);
    object oStore = GetNearestObjectByTag("Tag of store", OBJECT_SELF, 1);
    int iRandom = Random(3) + 4;
    object oItem1;
    object oItem2;
    object oItem3;
    object oItem4;
    object oItem5;
    object oItem6;
    object oItem = GetFirstItemInInventory(oStore);

    while (iRandom > 0)
    {
        if (Random(3) == 0)
        {
            if (oItem != oItem1 &&
                oItem != oItem2 &&
                oItem != oItem3 &&
                oItem != oItem4 &&
                oItem != oItem5 &&
                oItem != oItem6)
            {
            CopyItemToAllPlayersInArea(oItem, oArea);
            if (oItem1 == OBJECT_INVALID)
            oItem1 = oItem;
            else if (oItem2 == OBJECT_INVALID)
            oItem2 = oItem;
            else if (oItem3 == OBJECT_INVALID)
            oItem3 = oItem;
            else if (oItem4 == OBJECT_INVALID)
            oItem4 = oItem;
            else if (oItem5 == OBJECT_INVALID)
            oItem5 = oItem;
            else if (oItem6 == OBJECT_INVALID)
            oItem6 = oItem;
            iRandom--;
            }
        }
        oItem = GetNextItemInInventory(oStore);
        if (oItem == OBJECT_INVALID)
        oItem = GetFirstItemInInventory(oStore);
    }
}


I haven't tested this and my logic might be a bit funky(half the time it is). But basically it will give all the players the same 4 to 6 items and not duplicate any of them.
Could also do an indvidual loop for each player but I think whichever method I've suggested you could potentially end up with TMIs.
Other thoughts: could write a function that recurses only 4 to 6 times, looping through each player and then looping through store inventory to grab some random items. But not duplicate the items. Not sure which method would work best here. It would probably also help to know how many different items your store will have.

Hope this at least gets you going in the right direction. Good luck.
               
               

               


                     Modifié par GhostOfGod, 09 juin 2011 - 03:05 .
                     
                  


            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« Reply #6 on: June 09, 2011, 08:14:14 am »


               Would it be possible to deal a configurable ammount negative dammage to all players in the area at death and before the loot is transfered to the players.. and if they are dead at the time of the boss kill i dont want them to recieve any loot... dos this make sence
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Death Script
« Reply #7 on: June 09, 2011, 04:07:32 pm »


               Sure. Edited the above script. I just added the three lines highlighted red. Right now the damage is set to 20 but you can just change it to whatever you want.
               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« Reply #8 on: June 11, 2011, 05:10:01 pm »


               Hi Ghost,

Sorry for the late reply.. been busy, im testing the script now and seems fine,  Just need to find away so all players in the area get different random loot ....

Again thanks for your help '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Death Script
« Reply #9 on: June 12, 2011, 12:58:31 am »


               No worries. Just glad to try and help.

I reworked the script so that each player will get thier own items. They will still not get duplicate items either. See if it works ok for you. You might still potentialy run into TMI issues. The way I have it working now is that you first roll the random number to see if you will get 4, 5, or 6 items. Then a loop starts that will count that number down to zero. Once at zero it will stop. Inside the loop though, you need a way to try to cycle through all the inventory of the store so that you can actually have a chance to get any of the items but still not cycle too much so that you don't end up with a TMI. That is what the other Random(3) is for. In addition to that you needed to not have duplicates. So this loop for the 4 to 6 items will keep looping if the item picked was an item that the player already got or if the Random(3) does not return a 0. This could end up doing a lot of loops.

There may be a better way to do it so it doesn't loop so much. I'll give it some thought. Perhaps some of the super awesomer scripters have some suggestions to improve it. '<img'>


//OnDeath Boss
void CreateBossLoot(object oPC, object oStore)
{
    int iRandom = Random(3) + 4;
    object oItem1;
    object oItem2;
    object oItem3;
    object oItem4;
    object oItem5;
    object oItem6;
    object oItem = GetFirstItemInInventory(oStore);

    while (iRandom > 0)
    {
        if (Random(3) == 0)
        {
            if (oItem != oItem1 &&
                oItem != oItem2 &&
                oItem != oItem3 &&
                oItem != oItem4 &&
                oItem != oItem5 &&
                oItem != oItem6)
            {
            CopyItem(oItem, oPC, TRUE);

            if (oItem1 == OBJECT_INVALID)
            oItem1 = oItem;
            else if (oItem2 == OBJECT_INVALID)
            oItem2 = oItem;
            else if (oItem3 == OBJECT_INVALID)
            oItem3 = oItem;
            else if (oItem4 == OBJECT_INVALID)
            oItem4 = oItem;
            else if (oItem5 == OBJECT_INVALID)
            oItem5 = oItem;
            else if (oItem6 == OBJECT_INVALID)
            oItem6 = oItem;
            iRandom--;
            }
        }
        oItem = GetNextItemInInventory(oStore);
        if (oItem == OBJECT_INVALID)
        oItem = GetFirstItemInInventory(oStore);
    }
}

void main()
{
    object oArea = GetArea(OBJECT_SELF);
    object oStore = GetNearestObjectByTag("Tag of store", OBJECT_SELF, 1);
    effect eNeg = EffectDamage(20, DAMAGE_TYPE_NEGATIVE);
    object oPC = GetFirstPC();

    while (GetIsObjectValid(oPC))
    {
        if (GetArea(oPC) == oArea)
        {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eNeg, oPC);
            if (!GetIsDead(oPC))
            CreateBossLoot(oPC, oStore);
        }
        oPC = GetNextPC();
    }
}
               
               

               
            

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Death Script
« Reply #10 on: June 15, 2011, 11:44:31 pm »


               Thanks Ghost

Been running with this for a couple of days now and seems ok.. I have gems in the store but never had one drop yet.. does this check the whole store ?
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Death Script
« Reply #11 on: June 16, 2011, 12:36:51 am »


               I just made this up as a possible replacement for the loot generation part of GOG's script suggestion. It should be able to plug in with his on death script, just comment his loot generation part temporarily if you want to try out this one. It compiles, and ~should~ work for most of what you wanted, but I didn't set up a store and creature to try it out.

void CreateBossLoot (object oPC, object oStore)
{
 //// This is so you don't have to manually count the number of items in the store.
 //// Will count once only, regardless of how many PCs are present, which will help
 //// some on the TMI front.
 int    nCount = GetLocalInt (oStore, "ITEM_COUNT");
 object oItem;
 if (!nCount)
    {
     oItem = GetFirstItemInInventory (oStore);
     while (GetIsObjectValid (oItem) )
        {
         nCount ++;
         oItem = GetNextItemInInventory (oStore);
        }
     SetLocalInt (oStore, "ITEM_COUNT", nCount);
    }
 ////  The only thing this doesn't do is check to make sure each item is unique.
 int nItem1, nItem2, nItem3, nItem4, nItem5, nItem6;
 int nRandom = d3() + 3;
 nItem1 = Random (nCount) + 1;
 nItem2 = Random (nCount) + 1;
 nItem3 = Random (nCount) + 1;
 nItem4 = Random (nCount) + 1;
 if (nRandom >= 5) nItem5 = Random (nCount) + 1;
 if (nRandom == 6) nItem6 = Random (nCount) + 1;

 //// This cycles through the inventory again, and at the item numbers matching
 //// the random ones it copies the item to the PC.
 //// nItems is counted just to end it early if all the items are copied already.
 //// There's no need to continue cycling the inventory at that point.
 int nItems;
 int nCounter = 1;
 oItem = GetFirstItemInInventory (oStore);
 while (GetIsObjectValid (oItem) && nItems < nRandom)
    {
     if (nCounter == nItem1 || nCounter == nItem2 || nCounter == nItem3 ||
         nCounter == nItem4 || nCounter == nItem5 || nCounter == nItem6 )
        {
         CopyItem (oItem, oPC, TRUE);
         nItems ++;
        }
     nCounter ++;
     oItem = GetNextItemInInventory (oStore);
    }
}
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Death Script
« Reply #12 on: June 16, 2011, 01:51:40 am »


               I thought of another way that might cut down on tmi is when you are creating item use GetIsItemPossessedByParty() this is of course if the players are in a group.  Other wise if just one player it may return true even for one player.  SO GHOST try a rebuild of your script with useing that function and if returns true rechoose item.  Just an idea...
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Death Script
« Reply #13 on: June 16, 2011, 08:19:41 am »


               Well alright. Failed.Bard's script  definitely has some good stuff in there so I "borrowed" from him.'<img'>

So I'm mixing it up a bit now but keeping everything that you originally asked for. Each player will get thier own roll of 4 to six items. Each player will then get his or her 4 to 6 random items(none the same). And now while each player might get some of the same items as the other players based on chance, it is still random for each player. This is also more efficient now thanks to Bard's suggestions.

So here's my last attempt. Hope it works.':lol:'


void CreateBossLoot(object oPC, object oStore, int iStock)
{
    int iItemsGet = d3() + 3;//Player gets 4 to 6 items
    int iItems = iItemsGet;

    //Get random and unique item place numbers we will use
    int iItem1, iItem2, iItem3, iItem4, iItem5, iItem6;
    while (iItemsGet > 0)
    {
        int iRand = Random(iStock)+1;
        if (iRand != iItem1 ||
            iRand != iItem2 ||
            iRand != iItem3 ||
            iRand != iItem4 ||
            iRand != iItem5)
        {
            if (!iItem1) iItem1 = iRand;
            else if (!iItem2) iItem2 = iRand;
            else if (!iItem3) iItem3 = iRand;
            else if (!iItem4) iItem4 = iRand;
            else if (!iItem5) iItem5 = iRand;
            else if (!iItem6) iItem6 = iRand;
            iItemsGet--;
        }
    }

    //Now lets make the items
    int iCurrentItem;
    object oItem = GetFirstItemInInventory(oStore);
    while (GetIsObjectValid(oItem) && iItems > 0)
    {
        iCurrentItem++;
        if (iCurrentItem == iItem1 ||
            iCurrentItem == iItem2 ||
            iCurrentItem == iItem3 ||
            iCurrentItem == iItem4 ||
            iCurrentItem == iItem5 ||
            iCurrentItem == iItem6)
        {
            CopyItem(oItem, oPC, TRUE);
            iItems--;
        }
        oItem = GetNextItemInInventory(oStore);
    }
}

void main()
{
    object oArea = GetArea(OBJECT_SELF);
    object oStore = GetNearestObjectByTag("Tag of store", OBJECT_SELF, 1);
    effect eNeg = EffectDamage(20, DAMAGE_TYPE_NEGATIVE);
    int iStock = GetLocalInt(oStore, "MY_NUM_ITEMS");
    if (!iStock)
    {
        int iInt;
        object oItem = GetFirstItemInInventory(oStore);
        while (GetIsObjectValid(oItem))
        {
            iInt++;
            oItem = GetNextItemInInventory(oStore);
        }
        SetLocalInt(oStore, "MY_NUM_ITEMS", iInt);
        iStock = iInt;
    }

    object oPC = GetFirstPC();
    while (GetIsObjectValid(oPC))
    {
        if (GetArea(oPC) == oArea)
        {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eNeg, oPC);
            if (!GetIsDead(oPC))
            CreateBossLoot(oPC, oStore, iStock);
        }
        oPC = GetNextPC();
    }
}



P.S. This script would be even more efficient if you preplaced, in the tooset, the int variable on the store for the amount of items it will have in it.

P.S.S. @ Greyfort. As far as players getting the same items, I think he just meant for them to not get all the exact same items as per my original script idea. He wanted each player to get their own random items. I think. ':blush:'