Author Topic: Suggestions for Drop Gold script  (Read 381 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« on: April 23, 2014, 06:19:03 pm »


               

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


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #1 on: April 23, 2014, 06:20:53 pm »


               

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



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #2 on: April 23, 2014, 06:38:06 pm »


               

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. 



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #3 on: April 23, 2014, 07:00:10 pm »


               

The OnSpawn event executes when a DM creates a creature.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #4 on: April 23, 2014, 07:12:36 pm »


               

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


 


What's happen?



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #5 on: April 23, 2014, 07:27:27 pm »


               

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



               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #6 on: April 23, 2014, 10:07:03 pm »


               

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);
    }
    ////////////////////////////
    ////////////////////////////

               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #7 on: April 23, 2014, 11:00:50 pm »


               

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


Looks great! BelowTheBelt  '<img'>  '<img'> 



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #8 on: April 23, 2014, 11:03:16 pm »


               

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



 


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



               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #9 on: April 23, 2014, 11:35:28 pm »


               

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.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #10 on: April 24, 2014, 12:49:00 am »


               

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?



               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #11 on: April 24, 2014, 04:51:04 am »


               


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.  



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Suggestions for Drop Gold script
« Reply #12 on: April 24, 2014, 06:37:20 pm »


               

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

It's pretty nice.


 


Surely helps, thanks BelowTheBelt  ':lol:'