My Scripts: giving random gold automaticly on killing :D

I leave this nice script in case someone like it:


//To override the maximum and minimum ranges, put integer variables "nGoldRangeMax" and "nGoldRangeMin" on the placeable with the new value.

string sGOLDRANGE_MAX = "nGoldRangeMax";    //Defaults to 300, 0 is not a valid entry.
string sGOLDRANGE_MIN = "nGoldRangeMin";    //Defaults to 100, if MAX is specified it will default to 1/3 of that, 0 is not a valid entry.

void main()


        int nGoldRangeMax = GetLocalInt(OBJECT_SELF,sGOLDRANGE_MAX);
        int nGoldRangeMin = GetLocalInt(OBJECT_SELF,sGOLDRANGE_MIN);

        if (nGoldRangeMax == 0)
            nGoldRangeMax = 150;
        if (nGoldRangeMin == 50)
            nGoldRangeMin = nGoldRangeMax/3;

        int nGP = Random(nGoldRangeMax-nGoldRangeMin)+nGoldRangeMin;

  // posibility of 50
	     if (d100()>50)

	   object oPC = GetLastKiller();


Im working for it runs simply on killed creature, by anyone… i wish find the way :frowning:

If you wish it , change:

object oPC = GetLastKiller();


object oPC = OBJECT_SELF;

for giving a random gold post mortem to creature, but I prefer create a placectable “goldpile”, its the true… :smiley:

I suppose you wanted to write

if (nGoldRangeMax == 0)
        nGoldRangeMax = 300; // was 150
if (nGoldRangeMin == 0) // was 50
        nGoldRangeMin = nGoldRangeMax/3;


Note: this is a canned (predefined) reply.

If you wish for your scripts to be readable on this forum, try posting them as code:

paste your script code here

You can edit your post(s) to make the changes.

Additional code posting guidelines (click here to expand).
  1. Split different scripts into separate [code] sections for extra readability.
  2. You can use ``` instead of [code] and [/code] (also in separate lines).
  3. If NWScript is not automatically detected by syntax highlighter, force it with ```nwscript in the first line. Use ```plain to disable the highlighting.
  4. Write inline code like this: `short code fragment` ([code] works too).
  5. “Hide details” function (under :gear: icon in the post editor) can collapse code sections, significantly reducing post size. Select the code, then choose that option. Result:
void main()
    // this is code of my_script

lool, thanks… :sweat_smile:

1 Like

Red Prince you seem a nice guy so i want to partecipate to this thread.
Usually i don’t share code not because im jealous but i think here is plenty of more skilled scripter than me,homever i want to share the portion of the script we used on our former action PW.

void CreateRandomGoldOnCreature( object oCreature, int nMinGP, int nMaxGP)

inside the onDeath (we use this inside OnUserDefine event but it’s basically the same) put:


It looks nice, thanks :smiley: