Aller au contenu

Photo

CEP & the default script / Gold Encumberance


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

#1
Scarss

Scarss
  • Members
  • 7 messages
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);
   }
}


#2
TSMDude

TSMDude
  • Members
  • 865 messages
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.

#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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 .


#4
Scarss

Scarss
  • Members
  • 7 messages
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?

#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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 .


#6
Shadooow

Shadooow
  • Members
  • 4 468 messages
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
 }
}



#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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. 

#8
Scarss

Scarss
  • Members
  • 7 messages
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. :)  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.

#9
Shadooow

Shadooow
  • Members
  • 4 468 messages

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 .


#10
TSMDude

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

#11
TSMDude

TSMDude
  • Members
  • 865 messages
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

#12
Genisys

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

#13
kalbaern

kalbaern
  • Members
  • 824 messages

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.

#14
Genisys

Genisys
  • Members
  • 525 messages
TY kalbaern, you saved me a lot o time!. :)

#15
Genisys

Genisys
  • Members
  • 525 messages
Double post somehow, hmmm.... woops sorry

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


#16
the.gray.fox

the.gray.fox
  • Members
  • 127 messages
Hello.

Be aware, the OnAcquireItem event does not fire -for GP- in case you acquire
a pile of GP from a placeable, and drag it directly into a sub-inventory in
your inventory (that is, drag from placeable -> to -> a bag of holding of yours).

There is no solution for this, other than to periodically check for clandestine GP
into a character possession. And then convert the GP found to whatever you want to.

Either you go with a HB for it, or you run a GP-check every time an item is
acquired or unacquired (this 2nd method is what I chose).
It shall not be flawless, but it will ensure that you do not get to retain your
clandestine GP amounts for long.


Side note:

I have built up a custom system for Gold Weight some time ago, wherein GP amounts
are converted into Gold Coins supposed to be kept inside a "wallet" bag (Gold Bag).
The amount of Gold Bags you possess determines how many Gold Coins you can carry
with you. Gold Bags are supposed to only accomodate Gold Coins. If you attempt to put
some other item inside a Gold Bag, or also if you try to relocate Gold Coins outside of
your Gold Bags, the next time you acquire or unacquire something -> your inventory is
rearranged (Gold Coins are moved inside Gold Bags, and non-Gold Coins are moved
out of Gold Bags).
If you interact with a shop, all your Gold Coins are converted to GP (so you trade as usual).
If you close the shop, any GP in your possession is converted back to Gold Coins.

Let me know if you are interested in it.


-fox

Modifié par the.gray.fox, 07 août 2010 - 01:15 .


#17
Scarss

Scarss
  • Members
  • 7 messages
Well, I removed the crp_s hak after importing it as an erf, overwrote the default script with my own and discovered that the core I've built doesnt allow it to work as it does in a standard mod.  Deffinetly one of those "Doh!" moments..  Not really sure whats stopping it, and I deffinetly have no clue what calls the default script to make it function.  Posted Image

fox:  I'm interested.  Is this the one I saw on the vault? 

#18
TSMDude

TSMDude
  • Members
  • 865 messages

TSMDude wrote...

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

Not to sound like a broken record but the one I linked is used in our module and works very well for us. We have np with it or its implmenation on our module. It ise asily adapted and probally something you would like if you take a look at it.

It works on the UnAquire and Aquire Scripts converting gold from treasure, placeables and several other spots. If you do need help you can contact me on Skype or on our forums or here and I will gladly walk you through implmenting it.

#19
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
There is nothing that could stop it from running. Unless you have altered something in the characters BIC file. 'default' is the name given to the script for every event in the players bic file. the HB is just the only one fires. (or at least people keep saying that I have never tested it to make sure. But Axe was pretty adimate about it.) So if your script is not firing It is probably a problem withthe script. Or he does not have the "rp_ce_marker" on him. whatever that is. What ever it is If he does not have it the script stops and does not run.

#20
Shadooow

Shadooow
  • Members
  • 4 468 messages

Lightfoot8 wrote...

There is nothing that could stop it from running. Unless you have altered something in the characters BIC file. 'default' is the name given to the script for every event in the players bic file. the HB is just the only one fires.

LINK

Modifié par ShaDoOoW, 08 août 2010 - 05:58 .


#21
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

ShaDoOoW wrote...

Lightfoot8 wrote...

There is nothing that could stop it from running. Unless you have altered something in the characters BIC file. 'default' is the name given to the script for every event in the players bic file. the HB is just the only one fires.

LINK


Yes, I mentioned the trap thing earlyer in the thread.  I still also question the other PC events fireing or not.  Short answer here is there are a lot of people the support the use of 'default' as a PC heart beat.  I myself advoid it and refuse to use it.  Even if they are right on it being the only PC Event it fires for. It was never meant to be used this way.  It is nothing short of Side Effect programing.  Now I am not one to avoid Side Effect programming, I do it all the time. But not without more information on how the system works and you always have to be ready for it to came back and bit you in the ........

All in all ShaDoOoW is right.  You would be better off useing a pseudoheartbeat instead.

My opinion anyway.  Im sure Axe would disagree with me again.
 
L8

#22
Shadooow

Shadooow
  • Members
  • 4 468 messages
I heard default also fire for OnDeath and OnConversation event, I think it was Virusman who claimed that, long time ago anyway.

#23
Knight_Shield

Knight_Shield
  • Members
  • 444 messages
I don't want CRAP in my module either.:bandit:*shifty eyes*