Aller au contenu

Photo

trying to make a loot system but i stuck.


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

#1
Corvittin

Corvittin
  • Members
  • 23 messages

hello guys im trying to make a loot system instead of x0_i0_tresure.
its based on ResRefs. Codes are here. 
2 Diffrent scripts. First one is an include one:

//loot_table_includes

//*Generates loot on died creature
void GenLoot(string sResRef, object oDied)
{
const string sGold="nw_it_gold001";
if (sResRef=="c_dogwolf")
	{

	 	string sItem1="wolftooth";
		int nDR = d100(1);
  		if(nDR <= 50){}
    										
    	else if(nDR >= 51 && nDR <=70)
    			{
    				CreateItemOnObject(sItem1, oDied, 1);
				}
		else if(nDR >=71)
				{
				CreateItemOnObject(sGold , oDied , 10);
				}
	}
else if (sResRef=="c_deerfemale")	
	{

		string sItem1="deerpelt";
		int nDR =d100(1);
		if (nDR <= 50){}
		else if (nDR >=51 && nDR <=70)
			{
			CreateItemOnObject(sItem1, oDied,1);
			}
		else if (nDR >= 71)
			{
			CreateItemOnObject(sGold,oDied,10);
			}
	
	}
}

and here is on_death script.

#include "loot_table_includes" 

void main()
{
object oPC=GetFirstPC();
object oDied=OBJECT_SELF;
string sResRef=GetResRef(OBJECT_SELF);
SendMessageToPC(oPC,sResRef); // printin resref to pc
GenLoot(sResRef,oDied);

}

i think my logic is wrong..Goal is Generate loot on died creature in contidion of resref.

i can get gold or wolftooth on wolf but nothing on deers. Deers resrefs are correct checked 10 times.
 



#2
AGhost_7

AGhost_7
  • Members
  • 62 messages

I can't really see any problem with your logic. I'd recommend starting by checking off each piece of your logic. You already checked if your resref was copied properly but is it loading into your module as it should? Try creating the deer pelt outside of the on-death event.

 

Another thing you could do is validate wether its reaching your logic branch by adding some prints: 

if (sResRef=="c_deerfemale")  
{
  SendMessageToPC(GetFirstPC(), "Is a deer.");
  string sItem1 ="deerpelt";
  int nDR = d100(1);
  if (nDR <= 50){}
  else if (nDR >=51 && nDR <=70)
  {
    CreateItemOnObject(sItem1, oDied,1);
    SendMessageToPC(GetFirstPC(), "Creating deer pelt");
  }
  else if (nDR >= 71)
  {
    CreateItemOnObject(sGold,oDied,10);
    SendMessageToPC(GetFirstPC(), "Making gold.");
  }
}


#3
Dann-J

Dann-J
  • Members
  • 3 161 messages

I did something similar for the module I'm currently working on. I modified the default creature OnDeath script to execute my own script, using the creature's appearance type to spawn various items, with the option of overriding the appearance type using a local variable on the creature.

 

It includes references to some of the SoZ trophy items, as well as a heap of my own custom blueprints. Here's what it looks like so far:

//Spawn crafting items on dead creatures
void main()
{
object oSelf = OBJECT_SELF;
if ( GetLocalInt(oSelf, "X2_L_NOTREASURE") == 1) return;

int iType = GetAppearanceType(oSelf);
string sDistil;
string sHide;
string sAlchemy;
string sSpecial;//NX2 trophies

switch(iType)
{
case 8://NX2 trophies
	{
	sSpecial = "nx2_cp_badger";
	break;
	}
case 9://NX2 trophies
	{
	sSpecial = "nx2_cp_dbadger";
	break;
	}
case 10:
  {
  sDistil = "002";
  break;
  }
case 13:
  {//bear
  sDistil = "003";
  sHide = "leather";
  sSpecial = "nw_it_meat_bear";
  break;
  }
case 15:
  {//dire bear
  sDistil = "004";
  sHide = "leather";
  sSpecial = "nw_it_meat_bear";
  break;
  }
case 16:
  {
  sDistil = "012";
  break;
  }
case 18:
  {
  sDistil = "006";
  break;
  }
case 19:
  {
  sDistil = "007";
  break;
  }
case 21:
  {//boar
  sHide = "leather";
  sSpecial = "nw_it_meat_boar";
  break;
  }
case 22:
  {//dire boar
  sDistil = "008";
  sHide = "leather";
  sSpecial = "nw_it_meat_boar";
  break;
  }
case 24:
  {//worg
  sHide = "leather";
  sSpecial = "nx2_cp_worg";
  break;
  }
case 34:
  {//cow
  sHide = "leather";
  break;
  }
case 35:
  {//deer
  sHide = "leather";
  break;
  }
case 39:
  {
  sDistil = "023";
  break;
  }
case 41:
  {
  sDistil = "012";
  break;
  }
case 49:
  {//red dragon
  sDistil = "012";
  sHide = "dragon";
  break;
  }
case 73:
  {
  sDistil = "014";
  break;
  }
case 74:
  {
  sDistil = "016";
  break;
  }
case 76:
  {
  sDistil = "015";
  break;
  }
case 80:
  {
  sDistil = "018";
  break;
  }
case 81:
  {
  sDistil = "019";
  break;
  }
case 89:
  {
  sDistil = "020";
  break;
  }
case 105:
  {
  sDistil = "022";
  break;
  }
case 109:
  {
  sDistil = "024";
  break;
  }
case 110:
  {
  sDistil = "025";
  break;
  }
case 129:
  {
  sDistil = "026";
  break;
  }
case 158:
  {
  sDistil = "030";
  break;
  }
case 159:
  {
  sDistil = "030";
  break;
  }
case 160:
  {
  sDistil = "031";
  break;
  }
case 161:
  {
  sDistil = "032";
  break;
  }
case 163:
  {
  sDistil = "010";
  break;
  }
case 167:
  {
  sDistil = "033";
  break;
  }
case 168:
  {//umberhulk
  sDistil = "034";
  sHide = "umber";
  break;
  }
case 175:
  {//dire wolf
  sDistil = "036";
  sHide = "leather";
  break;
  }
case 179:
  {
  sDistil = "021";
  break;
  }
case 180:
  {
  sDistil = "027";
  break;
  }
case 181:
  {//wolf
  sHide = "leather";
  break;
  }
case 184:
  {
  sDistil = "037";
  break;
  }
case 186:
  {
  sDistil = "038";
  break;
  }
case 187:
  {
  sDistil = "038";
  break;
  }
case 288:
  {
  sDistil = "035";
  break;
  }
case 289:
  {
  sDistil = "035";
  break;
  }
case 387://NX2 trophies
	{
	sSpecial = "nx2_cp_drat";
	break;
	}
case 481:
  {
  sDistil = "011";
  break;
  }
case 488:
  {
  sDistil = "010";
  break;
  }
case 489:
  {//pig
  sDistil = "011";
  break;
  }
case 493://NX2 trophies
	{
	sSpecial = "nx2_cp_golemblade";
	break;
	}
case 496:
  {
  sDistil = "027";
  break;
  }
case 497:
  {
  sDistil = "027";
  break;
  }
case 498:
  {
  sHide = "leather";
  break;
  }
case 500:
  {
  sDistil = "028";
  break;
  }
case 512:
  {
  sAlchemy = "nw_it_msmlmisc19";
  break;
  }
case 514:
  {
  sDistil = "008";
  break;
  }
case 521:
  {
  sAlchemy = "nw_it_msmlmisc19";
  break;
  }
case 522:
  {
  sDistil = "010";
  break;
  }
case 537:
  {
  sDistil = "029";
  break;
  }
case 538:
  {
  sDistil = "005";
  break;
  }
case 543:
  {
  sDistil = "009";
  break;
  }
case 1002:
  {//panther
  sHide = "leather";
  break;
  }
case 1003://NX2 trophies
	{
	sSpecial = "nx2_cp_wolverine";
	break;
	}
case 1008:
  {
  sDistil = "029";
  break;
  }
case 1014://NX2 trophies
	{
	sSpecial = "nx2_cp_dwolverine";
	break;
	}
case 1015:
  {
  sDistil = "012";
  break;
  }
case 1020:
  {
  sDistil = "023";
  break;
  }
case 1026:
  {//snow leopard
  sHide = "leather";
  break;
  }
case 1027://NX2 trophies
	{
	sSpecial = "nx2_cp_treant";
	break;
	}
case 1030:
  {//wyvern
  sDistil = "039";
  sHide = "wyvern";
  sSpecial = "nw_wswmdg_wyvern";
  break;
  }
}

if (sDistil != "" && d2(1) == 1)
	{
	CreateItemOnObject("n2_crft_dist"+sDistil, oSelf, 1);
	}
if (sHide != "")
	{//n2_crft_hide+sHide
	int iNo = Random(2);
	if (sHide == "dragon") iNo = iNo + 1;
	if (iNo > 0) CreateItemOnObject("n2_crft_hide"+sHide, oSelf, iNo);
	}
if (sAlchemy != "" && d2(1) == 1)
	{
	CreateItemOnObject(sAlchemy, oSelf, 1);
	}
if (GetRacialType(oSelf) == 18) sSpecial = "nx2_cp_giant";

string sSpecial2 = GetLocalString(oSelf, "Special");
if (sSpecial2 != "") sSpecial = sSpecial2;

if (sSpecial != "" && d2(1) == 1)
	{
	CreateItemOnObject(sSpecial, oSelf, 1);	
	}
}


#4
Dann-J

Dann-J
  • Members
  • 3 161 messages

I can see why the deer section won't work. Most of those 'elses' aren't necessary. Try this instead:

if (sResRef=="c_deerfemale")	
	{

		string sItem1="deerpelt";
		int nDR =d100(1);
		if (nDR >50 && nDR <71)
			{
			CreateItemOnObject(sItem1, oDied,1);
			}
		if (nDR > 70)
			{
			CreateItemOnObject(sGold,oDied,10);
			}
	
	}

It would also probably be better to define sItem1 once as an empty string at the start of the script.

string sItem1;

Then set the string where necessary without defining it as a string.

sItem1 = "text";

You only have to define a variable's type once.



#5
Corvittin

Corvittin
  • Members
  • 23 messages

Dann-j Thank you. i just solved my problem. with these single script on_death:



void main()
{
object oPC=GetFirstPC();
object oDied=OBJECT_SELF;
string sResRef=GetResRef(OBJECT_SELF);
string sItem1;
string sGold="nw_it_gold001";

//generate loot on dead creature
//wolf
if (sResRef == "c_dogwolf")
	{
	sItem1="wolfpelt";
	int nDice=d100(1);
	if (nDice <=50){SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"No Drop");}
	if (nDice >=51 && nDice <=70)
		{
		SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"Dropped item: "+sItem1);
		CreateItemOnObject(sItem1, oDied, 1);
		}
	else if (nDice >=89)
		{
		SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"Dropped item: "+sGold);
		CreateItemOnObject(sGold, oDied, 1);
		}
	}
//deer
if (sResRef == "c_deerfemale")
	{
	sItem1="deerpelt";
	int nDice=d100(1);
	if (nDice <=50){SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"No Drop");}
	if (nDice >=51 && nDice <=70)
		{
		SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"Dropped item: "+sItem1);
		CreateItemOnObject(sItem1, oDied, 1);
		}
	else if (nDice >=89)
		{
		SendMessageToPC(oPC,"dice ="+" "+IntToString(nDice)+" "+"sREF: "+sResRef+" "+"Dropped item: "+sGold);
		CreateItemOnObject(sGold, oDied, 1);
		}
	
	
	}
}

are there Any ideas how can i create a loot table like my old script up there. i mean im trying to make on_death script smaller and loot_table script bigger...
i imagine like;
if (odead=="wolf") {GenLoot("wolf")}

 

i think im gonna figure it out =) thx a lot bros!!

 



#6
Darin

Darin
  • Members
  • 282 messages

I did something somewhat similar, though mine was level based and based off of the generic treasure tables in 3.5 (for gold/gems/art/scrolls/potions/certain items).

 

You may want to write an "include" file...

//include file treasure_inc
void Treasure(string sResRef, object oTarget)
     {
          //code goes here...
     }

then, in the ondeath...

#include "treasure_inc"

void main()
{
        sResRef = GetResRef(OBJECT_SELF);
        //more code
        Treasure(sResRef,OBJECT_SELF);
        //more code
}

If it's a pelt system (and you want to make sure it doesn't generate unless the creature is dead to avoid, you know, people pick-pocketing skin) i'd suggest an include file, then in the ondeath have it check if the creature is of the animal type, then run an include function (maybe include a damage check to see if the pelt is ruined.  possibly a survival check by oKiller to see if they could skin it, or put that on the acquire for the pelt...).



#7
Corvittin

Corvittin
  • Members
  • 23 messages

Darin thank you for your interest... Last month i accidently lost my whole Module directory. computer deleted whole directory. i dont know why.. 
now instead of making a PW i decided to just play... im playing on BGTSCC for now. Thnks again.