Author Topic: Generating Gold Upon Destroying Crate  (Read 575 times)

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« on: January 09, 2011, 01:53:10 am »


               Hey Guys,

I'm new to nwn toolset and have been playing around with the basics. I think now it's time for me to learn how to script. I've successfully completed Celowin's Newbie Scrpting Tutorial. (It was a great help. Thanks Celowin.)

I've come across a scripter's block. I'm trying to create a script where when a placeable object is destroyed, it generates a random amount of gold where it was destroyed. Is anyone able to show me how to do this?

Here's what I'm trying to do: PC Destroys placeable object CRATE, and a random number of gold ranging from 10-100gp drops on the ground where the crate was destroyed.

Thanks,

Arcanix
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #1 on: January 09, 2011, 02:23:18 am »


               Gold is a little odd.   When it is on a player or creature it is just a number in there structure.  once it drops to the ground it turns into an item.  The problem here is that placeable do not have gold in there structure. So you will have to create the item to repersent the gold.  NWN standard uses the 'Gold pieces' Item.  ResRef : nw_it_gold001

This should work in the on death for the placeable/crate

void main()
{
    int amount = Random(90)+10;
    CreateItemOnObject("nw_it_gold001",OBJECT_SELF,amount);
}

               
               

               


                     Modifié par Lightfoot8, 09 janvier 2011 - 02:24 .
                     
                  


            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #2 on: January 09, 2011, 02:27:12 am »


               Ahhh I see. Yeah I tried to do something like that. Thank you, I didn't know about the random function. Cheers!
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #3 on: January 09, 2011, 02:53:43 am »


               

Lightfoot8 wrote...


void main()
{
    int amount = Random(90)+10;
    CreateItemOnObject("nw_it_gold001",OBJECT_SELF,amount);
}

Actually that will spawn 10-99 gold pieces because the random function returns values from 0 to max int -1.

This should give the desired ammount:

void main()
{
int nAmount = d10(10);
CreateItemOnObject("nw_it_gold001", OBJECT_SELF, nAmount);
}

-420
               
               

               


                     Modifié par 420, 09 janvier 2011 - 02:55 .
                     
                  


            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #4 on: January 09, 2011, 02:59:21 am »


               So I've tested the script but it doesn't seem to be working.
When I destroy the crates, no gold is spawned.

This is what I have at the moment:

[nwscript]

void main()
{
    int nValue = Random(90)+10;   // Range 10-99
    CreateItemOnObject("goldpiece", OBJECT_SELF, nValue); // Create Gold Peices where object was destroyed.
}

[/nwscript]
               
               

               


                     Modifié par ArcanixIncantrix, 09 janvier 2011 - 03:02 .
                     
                  


            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #5 on: January 09, 2011, 03:00:32 am »


               Oh Thanks 420.
               
               

               


                     Modifié par ArcanixIncantrix, 09 janvier 2011 - 03:02 .
                     
                  


            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #6 on: January 09, 2011, 03:02:03 am »


               Hmm.. Still not working.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #7 on: January 09, 2011, 03:25:44 am »


               

ArcanixIncantrix wrote...

So I've tested the script but it doesn't seem to be working.
When I destroy the crates, no gold is spawned.

This is what I have at the moment:


void main()
{
    int nValue = Random(90)+10;   // Range 10-99
    CreateItemOnObject("goldpiece", OBJECT_SELF, nValue); // Create Gold Peices where object was destroyed.
}


Your problem is that there is no item with a resref of goldpiece

you need to use the resref of the item that already exsists or create an new item with the goldpiece resref useing the item wizard.

So the script looks like with an update to take care of the one gold that 420 is worried about.

void main()
{
    int nValue = Random(91)+10;   // Range 10-100
    CreateItemOnObject("nw_it_gold001", OBJECT_SELF, nValue); // Create Gold Peices on the object before it is killed
}



Aslo the [ nwscript] dose not work on the social site.  I normally just use the [ code] bbcode.
               
               

               


                     Modifié par Lightfoot8, 09 janvier 2011 - 03:30 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #8 on: January 09, 2011, 03:32:28 am »


               There is also a differance between killing an object and destroying it.   If the object is killed it will drop its inventory.  If is is destroyed ie. DestroyObject( oObject) via the function. it will not drop its content.
               
               

               
            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #9 on: January 09, 2011, 03:51:08 am »


               Oh I see.
               
               

               
            

Legacy_ArcanixIncantrix

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #10 on: January 09, 2011, 03:54:32 am »


               Ahh I realise that the object HAS to have an inventory for this to work. It's not what I was trying to do, but it seems like it is the only option.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Generating Gold Upon Destroying Crate
« Reply #11 on: January 09, 2011, 04:10:38 am »


               Nope can still be done by creatiing the gold item at the location of the crate.
 


void main()
{
    object oGold;
    int nValue = Random(91)+10;   // Range 10-100

    // Create Gold Peices item at my location.
    oGold= CreateObject(OBJECT_TYPE_ITEM,"nw_it_gold001",GetLocation(OBJECT_SELF));

    //Set the stack size
    SetItemStackSize(oGold,nValue);
}

               
               

               


                     Modifié par Lightfoot8, 09 janvier 2011 - 04:10 .