Aller au contenu

Photo

Suggestions for Drop Gold script


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

#1
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

The module sells all itens with 330% of price and we started to create a script to make all monsters drop + gold because the only way to get money was opening crates/barrels in citys/houses.

 

 

I made this code to add in OnDeath events:

 

    ////////////////////////////
    //Check if MOB has a lot of GOLD
    ////////////////////////////
    if(Random(101) <= 11)
    {
    float fLevel = GetChallengeRating(OBJECT_SELF);
    int iRandom = Random(51);
    float fRandom = IntToFloat(iRandom);
    float fProduto = fLevel*fRandom;
    int iValue = FloatToInt(fProduto);
    int iValuex2 = iValue*2;
    int iValuex3 = iValue*3;

    //Give GOLD to MOB
    GiveGoldToCreature(OBJECT_SELF, iValue);

    //EXTRA GP
    int iGoldExtra = Random(11);
    GiveGoldToCreature(OBJECT_SELF, iGoldExtra);

    //+Gold to High Mobs
    int iMobCheck = FloatToInt(fLevel);
    if(iMobCheck >= 19) GiveGoldToCreature(OBJECT_SELF, iValue);
    if(iMobCheck >= 29) GiveGoldToCreature(OBJECT_SELF, iValuex2);
    if(iMobCheck >= 39) GiveGoldToCreature(OBJECT_SELF, iValuex3);

    //Double of GOLD 1%
    if(Random(101) <= 11)
    {
    GiveGoldToCreature(OBJECT_SELF, iValue);
    if(iMobCheck >= 19) GiveGoldToCreature(OBJECT_SELF, iValue);
    if(iMobCheck >= 29) GiveGoldToCreature(OBJECT_SELF, iValuex2);
    if(iMobCheck >= 39) GiveGoldToCreature(OBJECT_SELF, iValuex3);
    }

    }
    ////////////////////////////
    ////////////////////////////
 
I am sharing with you my GOLD script and accepting suggestions to improve this system used in nw_c2_default7 or x2_def_ondeath events.
 
thank you


#2
henesua

henesua
  • Members
  • 3 882 messages

Add gold onspawn so that rogues can pick pocket your mobs.


  • WhiteTiger aime ceci

#3
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

it would be nice to have some gold for rogues, so they could use pick pocket.

I first tried using OnSpawn event, but if the Dungeon Master create a mob, he will not have gold. 



#4
henesua

henesua
  • Members
  • 3 882 messages

The OnSpawn event executes when a DM creates a creature.


  • WhiteTiger aime ceci

#5
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

Weird. This seems not to work here. I tried to use it with OnSpawn event, but no gold found.

 

What's happen?



#6
henesua

henesua
  • Members
  • 3 882 messages

Hard to tell without the full script posted. I equip my creatures on spawn.


  • WhiteTiger aime ceci

#7
BelowTheBelt

BelowTheBelt
  • Members
  • 394 messages

i reworked your script a bit.  I believe that it does the same thing, but more efficiently.  

 

A couple of things to point out.  You call "GiveGoldToCreature" as many as 4 times during the script.  You can minimize this down to just one by determining what the value of iValue is before you give the gold.  That way, you're saving game resources.

 

I also put an extra if statement in so that low CR creatures don't have to bother with the CR check.  And, I reordered your first 'if' statement to be able to use subsequent 'else if' statements, which could save on a couple of checks for your higher CR creatures.  

 

Also, I removed some of the variables that you had initialized, but only used once in the script.  The game engine has to allocate memory each time a variable is initialized, then has to release that memory once the script finishes.  That's wasted effort for a variable that is only used once in your script when that data can be used without initializing the variable.  It's to your benefit to minimize the number of variables in your scripts as much as possible, though people will say that the efficiency impact is negligible.  Personally, I believe that as much efficiency as possible should be the goal, even if that is measured in microseconds - it allows for more inefficiency elsewhere.

 

Another thing I noticed is that you're not actually 'doubling' the gold given to your creatures the way this is set up.  Based on your original script,  a level 40 creature gets iValue given to him, then some random  bonus amount, and then additional iValuex3.  that's 4x the iValue + the random.  If the 'double gold' roll is successful, you only award 3x iValue.  So, it's not doubling the gold.  I reworked it so that it truly gives double the gold.

 

Also, your script comments say that double gold chance is 1%, but you're actually setting it at 11%.  Not sure if this was intentional.

 

I've not compiled this to see if it works, so you may want to do it and test it out a bit.  Let me know if you have any questions:

////////////////////////////
    //Check if MOB has a lot of GOLD
    ////////////////////////////
    if(Random(101) <= 11)
    {
    float fLevel = GetChallengeRating(OBJECT_SELF);
    float fRandom = IntToFloat(Random(51));
    int iValue = FloatToInt(fLevel*fRandom) + Random(11);
    int iValueAdd;

    //+Gold to High Mobs
    if (fLevel >=19.0)
        {
        if(fLevel >= 39.0) iValue = iValue*4;
        else if(fLevel >= 29.0) iValue= iValue*3;
        else iValue= iValue*2;

        //Double of GOLD 1%
        if(Random(101) <= 11) //NOTE that at 11, this is actually 11%, not 1%
            {
            iValue = iValue*2;
            }
        }
    //Give GOLD to MOB
    GiveGoldToCreature(OBJECT_SELF, iValue);
    }
    ////////////////////////////
    ////////////////////////////

  • WhiteTiger aime ceci

#8
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

What is this I'm seeing? Simplicity, organized script and still save game resources.

Looks great! BelowTheBelt  :D  :) 



#9
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

//NOTE that at 11, this is actually 11%, not 1%

 

Because I thought this way: It's 10% of 10% = 1% XD



#10
BelowTheBelt

BelowTheBelt
  • Members
  • 394 messages

No problem.  Hope it works for you.

 

 

Because I thought this way: It's 10% of 10% = 1% XD

 

Ahh.  Yeah, that makes sense, then.

 

 

Also, I noticed that in the script I posted, I accidentally left in a variable I was originally playing around with, int iValueAdd.  You can delete that, as it's not used in the script and shouldn't be there any longer.


  • WhiteTiger aime ceci

#11
WhiteTiger

WhiteTiger
  • Members
  • 479 messages

Also, I noticed that in the script I posted, I accidentally left in a variable I was originally playing around with, int iValueAdd.  You can delete that, as it's not used in the script and shouldn't be there any longer.

 

I would like to ask about in this moment.

 

Also about "Double of Gold". If sucess, what's happen if mobs are level 40? you used iValue*4 and the double it's iValue*2. Don't it's iValue*8 for mobs 40?



#12
BelowTheBelt

BelowTheBelt
  • Members
  • 394 messages

Also about "Double of Gold". If sucess, what's happen if mobs are level 40? you used iValue*4 and the double it's iValue*2. Don't it's iValue*8 for mobs 40?

 

In my modified script, If a creature's CR is >=39.0, then a successful 'double gold' check takes the multiplier to effectively 8x the base iValue, yes.  In your original script, the multiplier was 7x the base iValue (not truly doubling the value of the gold - you gave the iValue to the creature, then twice the 3x iValue).

 

How this happens is by resetting the value of iValue each time.  That way, what we're multiplying *2 in the 'doubling' section is the value of the 4x value of iValue (not the base original value).

 

For example:

First, let's say that the script comes up with an even 100gp as the starting value of iValue.

 

At the first CR check, if the CR is below the threshold, the creature is given 100gp and exits.  Done.  But, if the CR is 40, we increase the value of iValue by 4x.  So, the value of iValue is changed from 100 to 400 (4x the 100 original value).  By expressing that iValue = iValue * 4, we are saying that from here on out in the script, iValue is now equal to 400 (not 100 any longer).

 

Then, if a 'doubling' check is successful, we do the same thing, but this time only need to multiply iValue by 2.  So, our 400 iValue *2 = 800 gp.  And again, by expressing that iValue = iValue*2, we change the value of iValue permanently from 400 to 800 (8x the original 100 starting value).

 

if you wanted to see this in action, you could put a little debug code in the script and then remove it later once you're satisfied:

SendMessageToPC(GetFirstPC(), "DEBUG:  iValue = "+IntToString(iValue));

 

You put a copy of that statement after each of the 3 times that iValue is changed (after the variable is initialized, after the CR check, and then after the doubling check.  You could also add a further statement within the doubling check to say that the double check was successful.

 

 

Hope that helps.  


  • WhiteTiger aime ceci

#13
WhiteTiger

WhiteTiger
  • Members
  • 479 messages
SendMessageToPC(GetFirstPC(), "DEBUG:  iValue = "+IntToString(iValue));

It's pretty nice.

 

Surely helps, thanks BelowTheBelt  :lol: