Author Topic: CEP & the default script / Gold Encumberance  (Read 978 times)

Legacy_Scarss

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« on: August 06, 2010, 11:21:59 pm »


               Ran into a problem while scripting a new core that I'm not sure how to work around.
I want to use UOAbigail's Gold Encumberance system on my server along with CEP 2.3.  Abigail's system is simple (code included) and replaces the default script to add weight to an item given to the character on log in pending how much gold they have.  It constantly updates itself as you gain / lose gold.  But CEP overwrites this script with one of its own and does not allow me to save it as default. 
How should I go about implementing this?  I've allready tried placing it onacquire/onunaquire to no avail.  Hoping there's a scripting guru still lurking here.

#include "x2_inc_itemprop"

void main()
{
  object oPC = OBJECT_SELF;
  object oTool = GetItemPossessedBy(oPC,"rp_ce_marker");
  if (oTool==OBJECT_INVALID) return;
  int iCurrentWeight = GetLocalInt(oTool,"iGoldWeight");
  //Set this variable on the module to equal the number of
  //gold coins it takes to make 5 pounds of weight.
  //If this is set to '0' then gold is weightless
  int iGoldWeight = GetLocalInt(GetModule(),"iGoldWeight");
  if (iGoldWeight==0) return;
  int iGoldOnPC = GetGold(oPC);
  int iWeightUnits = iGoldOnPC/iGoldWeight;
  if (iGoldOnPC<iGoldWeight) iWeightUnits=0; //Make sure that less gold than '5 lbs worth' does not add weight.
  if (iWeightUnits==iCurrentWeight) return; //No change.. nothing to do
  SetLocalInt(oTool,"iGoldWeight",iWeightUnits);
  int iWeightTotal = iWeightUnits*5;
  int iWeight100;
  int iWeight50;
  int iWeight30;
  int iWeight15;
  int iWeight10;
  int iWeight5;
  itemproperty ipWeight100 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_100_LBS);
  itemproperty ipWeight50 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_50_LBS);
  itemproperty ipWeight30 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_30_LBS);
  itemproperty ipWeight15 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_15_LBS);
  itemproperty ipWeight10 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_10_LBS);
  itemproperty ipWeight5 = ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_5_LBS);
  if (iWeightTotal>99)
   {
    while (iWeightTotal>99)
     {
      iWeightTotal=iWeightTotal-100;
      iWeight100++;
      if (iWeightTotal<100) break;
     }
   }
  if (iWeightTotal>49)
   {
    while (iWeightTotal>49)
     {
      iWeightTotal=iWeightTotal-50;
      iWeight50++;
      if (iWeightTotal<50) break;
     }
   }
  if (iWeightTotal>29)
   {
    while (iWeightTotal>29)
     {
      iWeightTotal=iWeightTotal-30;
      iWeight30++;
      if (iWeightTotal<30) break;
     }
   }
  if (iWeightTotal>14)
   {
    while (iWeightTotal>14)
     {
      iWeightTotal=iWeightTotal-15;
      iWeight15++;
      if (iWeightTotal<15) break;
     }
   }
  if (iWeightTotal>9)
   {
    while (iWeightTotal>9)
     {
      iWeightTotal=iWeightTotal-10;
      iWeight10++;
      if (iWeightTotal<10) break;
     }
   }
  if (iWeightTotal>4)
   {
    while (iWeightTotal>4)
     {
      iWeightTotal=iWeightTotal-5;
      iWeight5++;
      if (iWeightTotal<5) break;
     }
   }

  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_100_LBS,DURATION_TYPE_PERMANENT,-1);
  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_50_LBS,DURATION_TYPE_PERMANENT,-1);
  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_30_LBS,DURATION_TYPE_PERMANENT,-1);
  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_15_LBS,DURATION_TYPE_PERMANENT,-1);
  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_10_LBS,DURATION_TYPE_PERMANENT,-1);
  //IPRemoveMatchingItemProperties(oTool,IP_CONST_WEIGHTINCREASE_5_LBS,DURATION_TYPE_PERMANENT,-1);
  itemproperty ipLoop=GetFirstItemProperty(oTool);

  while (GetIsItemPropertyValid(ipLoop))
   {
   if (GetItemPropertyType(ipLoop)==ITEM_PROPERTY_WEIGHT_INCREASE) RemoveItemProperty(oTool, ipLoop);
   ipLoop=GetNextItemProperty(oTool);
   }

  if (iWeight100>0)
   {
    for (iWeight100; iWeight100>0; iWeight100--)
     {
      AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight100,oTool);
     }
   }
  if (iWeight50>0)
   {
    AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight50,oTool);
   }
  if (iWeight30>0)
   {
    AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight30,oTool);
   }
  if (iWeight15>0)
   {
    AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight15,oTool);
   }
  if (iWeight10>0)
   {
    AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight10,oTool);
   }
  if (iWeight5>0)
   {
    AddItemProperty(DURATION_TYPE_PERMANENT,ipWeight5,oTool);
   }
}

               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #1 on: August 06, 2010, 11:53:30 pm »


               Easy way is open up the cep2_custom hak and add YOUR default script there and place the cep2_custom above the cep top hak.



We do it a different way and I would be glad to send you the script as a erf when i get home as we use a different system for gold weight but it works the same way as we *ahem* borrowed it from Abs.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #2 on: August 07, 2010, 12:04:32 am »


               Did I read that right? Cep2.3 has added a script named 'default' to one of there haks?

Edit: To answer the question.

Gold will not fire the OnAquire/Unaquire Events. Even if they did the PC is not OBJECT_SELF Per the first line of the script.

TSMDude has the right Idea, on how to override the script in CEP 2.3

The script does look a little heavy for being used as a PC HB. with a Heavy number of players on a server this script would fire several times a second, So would need to be cleaned up and
optimized
a bit. At leas a check to make sure it is a PC so the traps that also run the default script don't have to search the inventory for the Item every round.

I would suggest looking at what TSMDude has to offer and see if it will work for you.
 
               
               

               


                     Modifié par Lightfoot8, 06 août 2010 - 11:26 .
                     
                  


            

Legacy_Scarss

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #3 on: August 07, 2010, 12:18:25 am »


               The CEP 2.3 haks are the only ones used in the module.  The default script is being overwritten by CEP's included C.R.A.P. default script. 

I'd really rather not go modifying haks, mainly because this will likely get posted to the vault once its completed.

Any suggestions for a work around / modification?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #4 on: August 07, 2010, 12:43:58 am »


               SP module?

You could remove the C.R.A.P hak from the module.
If you are useing scripts and Bluprints from that hak. you could import the ones you are using into the module. Or import the entire hak into the module. I dont think that hak has anything in it that has to be in the hak.

Just checked. Every thing in the cep2_crp_s.hak can be imported into the module. You can do this by making a copy of the hak and renaming the hak to "NEW_NAME.erf" then just import it into you module and remove the Hak from the recource list.

Will put a few more resources in you mod file, but I dont know how tight you are on them.

The advantage is you will then be able to madify any of the scripts or remove the ones you dont use.


Option Two would be to use a sudo HB.  Name the script something else then  have it run on the PC on Client enter.  At the end of the script add a delay command to run the script in another 6-12 Seconds.   

Option three would be to look at the the system Dude had to offer and see if it will work for you. 
               
               

               


                     Modifié par Lightfoot8, 06 août 2010 - 11:50 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #5 on: August 07, 2010, 12:47:16 am »


               Well OnAcquire is able to catch gold acquired.

OnAcquire example

void main()
{
object oItem = GetModuleItemAcquired();
int nStackSize = GetModuleItemAcquiredStackSize();
 if(oItem == OBJECT_INVALID && nStackSize > 0)
 {
 //PC acquired gold
 }
}


               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #6 on: August 07, 2010, 01:08:02 am »


               

ShaDoOoW wrote...

Well OnAcquire is able to catch gold acquired.

OnAcquire example

void main()
{
object oItem = GetModuleItemAcquired();
int nStackSize = GetModuleItemAcquiredStackSize();
 if(oItem == OBJECT_INVALID && nStackSize > 0)
 {
 //PC acquired gold
 }
}



I just tested the OnAcquire when gaining gold from a merchant.  It never fired.   Since most PC gold wll most likely be gained from merchants or scripted adds and not the gold item picked up. OnAcquire is not a good option. 
               
               

               
            

Legacy_Scarss

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #7 on: August 07, 2010, 01:14:55 am »


               Think I'll just remove the cep_crp_s hak and import the scripts.  At this time I do not believe I'm using any of them.

Thanks for telling me that. '<img'>  Had completely forgotten it was possible..  Jast time I did any scripting was a few years ago.. 

*After a little trial and error.*  For anyone looking at this, its best to import the scripts as an erf before removing the hak.  No errors found this way during the module build.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #8 on: August 07, 2010, 01:43:17 am »


               

Lightfoot8 wrote...

I just tested the OnAcquire when gaining gold from a merchant.  It never fired.   Since most PC gold wll most likely be gained from merchants or scripted adds and not the gold item picked up. OnAcquire is not a good option. 

True it does run only in PCs barter or when player gain gold from placeable or ground. Its definitely not good option because nothing is fire if player drops gold to ground. However if you are selling to merchants you dont need to catch golds via OnAcquire. In this case you can use GetGold, sice its possible to know if player sold item to merchant.
               
               

               


                     Modifié par ShaDoOoW, 07 août 2010 - 12:44 .
                     
                  


            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #9 on: August 07, 2010, 02:01:17 am »


               I am home and will post it ina  fe wminutes as it seems our router is doing funny things on our server...hate hardware....
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #10 on: August 07, 2010, 02:23:29 am »


               Was going to print out the scripts BUT this might be better for you as it is the system we used and adapted. It works well, does not have any issues as far as I can see and is very easy to adapt to waht you want.

http://nwvault.ign.c...s.Detail&id=411
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #11 on: August 07, 2010, 05:38:43 am »


               I saw the "default" script in the CEP v2.2 as well, I don't want that system in my modules, nor CRAP either...
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #12 on: August 07, 2010, 06:30:30 am »


               

Genisys wrote...

I saw the "default" script in the CEP v2.2 as well, I don't want that system in my modules, nor CRAP either...



Simply omit "cep2_crp_s" from your hak list like most builders do.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #13 on: August 07, 2010, 07:07:30 am »


               TY kalbaern, you saved me a lot o time!. '<img'>
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
CEP & the default script / Gold Encumberance
« Reply #14 on: August 07, 2010, 07:07:31 am »


               Double post somehow, hmmm.... woops sorry
               
               

               


                     Modifié par Genisys, 10 août 2010 - 11:43 .