Generating Gold Upon Destroying Crate
#1
Posté 09 janvier 2011 - 01:53
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
#2
Posté 09 janvier 2011 - 02:23
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 .
#3
Posté 09 janvier 2011 - 02:27
#4
Posté 09 janvier 2011 - 02:53
Actually that will spawn 10-99 gold pieces because the random function returns values from 0 to max int -1.Lightfoot8 wrote...
void main() { int amount = Random(90)+10; CreateItemOnObject("nw_it_gold001",OBJECT_SELF,amount); }
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 .
#5
Posté 09 janvier 2011 - 02:59
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 .
#6
Posté 09 janvier 2011 - 03:00
Modifié par ArcanixIncantrix, 09 janvier 2011 - 03:02 .
#7
Posté 09 janvier 2011 - 03:02
#8
Posté 09 janvier 2011 - 03:25
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 .
#9
Posté 09 janvier 2011 - 03:32
#10
Posté 09 janvier 2011 - 03:51
#11
Posté 09 janvier 2011 - 03:54
#12
Posté 09 janvier 2011 - 04:10
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 .





Retour en haut






