Aller au contenu

Photo

Help destruction of equipped items


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

#1
Nebril2

Nebril2
  • Members
  • 59 messages

Hi all!

 

This piece of code should have a 25% of destroying target armor and weapons when it dies and replace it by a "broken object" when it dies (on death).

 

 

object oO = OBJECT_SELF;

 

if (d4(1) == 1)

  {
 
    if(GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_CHEST, oO)))
    {
    object oR = CreateItemOnObject("objetoroto", oO);
    SetName(oR, GetName(GetItemInSlot(INVENTORY_SLOT_CHEST, oO))+" Roto");
 
    AssignCommand( oO,DestroyObject(GetItemInSlot(INVENTORY_SLOT_CHEST, oO))); }
  }
  if (d4(1) == 1)
  {
 
    if(GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oO)))
    {
    object oR = CreateItemOnObject("objetoroto", oO);
    SetName(oR, GetName(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oO))+" Roto");
    AssignCommand( oO,DestroyObject(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oO))); }
 
  }
   if (d4(1) == 1)
  {
 
    if(GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oO)))
    {
    object oR = CreateItemOnObject("objetoroto", oO);
    SetName(oR, GetName(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oO))+" Roto");
    AssignCommand( oO,DestroyObject(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oO))); }
 
  }
 

 

This doesnt works! why?



#2
kamal_

kamal_
  • Members
  • 5 238 messages

Where are your debug messages that tell you what it's doing/not doing?



#3
Nebril2

Nebril2
  • Members
  • 59 messages

It just creates the broken object but doesnt destroys the item in the determined slot.



#4
kamal_

kamal_
  • Members
  • 5 238 messages

Well, to start with your code is incomplete, as SetName is not a normal function. You are missing either defining the function in the scope of this script or adding an include that defines it (and it's not defined in any of the includes in E.C.'s super include).

 

Plus, no debug code, so you don't know if SetName is completing successfully. It could be failing, preventing the destroy command from even being processed. You need some debug code.

 

Also, you don't have to AssignCommand, you can do the destroying directly (and probably should because I doubt the oO object is going to be able to carry out the command).



#5
Clangeddin86

Clangeddin86
  • Members
  • 220 messages

Try with this, attach it to OnPlayerDeath in Module Properties:

void main()
{
	object oPC = GetLastPlayerDied(); // the caller is the module not the creature.
	object oEQUIP; //definitions outside loop
	object oMISC; // the destroyed misc object
	int nSLOT = 1; //1 is armor, 4 and 5 are weapons
	int nROLL; // the dice roll
	while (nSLOT < 6)
	{
		switch(nSLOT)
		{
			case 1:
			case 4:
			case 5:
			nROLL = d4(1);
			oEQUIP = GetItemInSlot(nSLOT, oPC);
			if ((nROLL == 1)&&(oEQUIP != OBJECT_INVALID))
			{
				DestroyObject(oEQUIP);
				oMISC = CreateItemOnObject("n2_it_brokenitem", oPC);
			}
			break;
		}
		nSLOT = nSLOT + 1;
	}
}