Author Topic: Help Needed With Script  (Read 375 times)

Legacy_Madasahatter

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Help Needed With Script
« on: March 02, 2014, 09:16:44 am »


               

Hi all,


 


I need a script that will remove slay good / lawfull and evil from equipped and none equipped weapons on enter.


 


Thanks in advance


 


 



               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help Needed With Script
« Reply #1 on: March 15, 2014, 10:49:14 am »


               

// Script Name:   _rem_slay_oe
/////////////////////////////////////////////////////////////////
// Created By Genisys / Guile
// Created On 3/15/2014
/////////////////////////////////////////////////////////////////

// This Script goes in an Area's or Trigger's OneEnter Event

/////////////////////////////////////////////////////////////////
// Declare Custom Prototypes..
int IsSlayWeapon(int nType);
void RemoveSlay(object oItem);

/////////////////////////////////////////////////////////////////
// Main Script
void main()
{
 object oPC = GetEnteringObject();
 if(!GetIsPC(oPC)) { return; }
 int iEntered = GetLocalInt(oPC, "SLAY_REMOVED");
 if(iEntered) { return; }
 else
 { SetLocalInt(oPC, "SLAY_REMOVED", TRUE); }

 int i, nBase;
 object oSlot;

 oSlot = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
 if(oSlot != OBJECT_INVALID){
 nBase = GetBaseItemType(oSlot);
 if(IsSlayWeapon(nBase))
 { RemoveSlay(oSlot); } }

 oSlot = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
 if(oSlot != OBJECT_INVALID){
 nBase = GetBaseItemType(oSlot);
 if(IsSlayWeapon(nBase))
 { RemoveSlay(oSlot); } }

 oSlot = GetItemInSlot(INVENTORY_SLOT_BULLET, oPC);
 if(oSlot != OBJECT_INVALID){
 { RemoveSlay(oSlot); }
 
 oSlot = GetItemInSlot(INVENTORY_SLOT_ARROW, oPC);
 if(oSlot != OBJECT_INVALID){
 { RemoveSlay(oSlot); }

 oSlot = GetItemInSlot(INVENTORY_SLOT_BOLT, oPC);
 if(oSlot != OBJECT_INVALID){
 { RemoveSlay(oSlot); }

 oSlot = GetFirstItemInInventory(oPC);
 while(GetIsObjectValid(oSlot))
 {
  nBase = GetBaseItemType(oSlot);
  if(IsSlayWeapon(nBase))
  {
   DelayCommand(0.5, RemoveSlay(oSlot));
  }
  oSlot = GetNextItemInInventory(oPC);
 }


// End Main Script
}

/////////////////////////////////////////////////////////////////
// Define Custom Prototypes

int IsSlayWeapon(int nType)
{
 switch(nType)
 {
  case BASE_ITEM_ARROW: { return TRUE; } break;
  case BASE_ITEM_BASTARDSWORD: { return TRUE; } break;
  case BASE_ITEM_BATTLEAXE: { return TRUE; } break;
  case BASE_ITEM_BOLT: { return TRUE; } break;
  case BASE_ITEM_BULLET: { return TRUE; } break;
  case BASE_ITEM_CLUB: { return TRUE; } break;
  case BASE_ITEM_DAGGER: { return TRUE; } break;
  case BASE_ITEM_DART: { return TRUE; } break;
  case BASE_ITEM_DIREMACE: { return TRUE; } break;
  case BASE_ITEM_DOUBLEAXE: { return TRUE; } break;
  case BASE_ITEM_DWARVENWARAXE: { return TRUE; } break;
  case BASE_ITEM_GLOVES: { return TRUE; } break;
  case BASE_ITEM_GREATAXE: { return TRUE; } break;
  case BASE_ITEM_GREATSWORD: { return TRUE; } break;
  case BASE_ITEM_HALBERD: { return TRUE; } break;
  case BASE_ITEM_HANDAXE: { return TRUE; } break;
  case BASE_ITEM_HEAVYCROSSBOW: { return TRUE; } break;
  case BASE_ITEM_HEAVYFLAIL: { return TRUE; } break;
  case BASE_ITEM_KAMA: { return TRUE; } break;
  case BASE_ITEM_KATANA: { return TRUE; } break;
  case BASE_ITEM_KUKRI: { return TRUE; } break;
  case BASE_ITEM_LIGHTCROSSBOW: { return TRUE; } break;
  case BASE_ITEM_LIGHTFLAIL: { return TRUE; } break;
  case BASE_ITEM_LIGHTHAMMER: { return TRUE; } break;
  case BASE_ITEM_LIGHTMACE: { return TRUE; } break;
  case BASE_ITEM_LONGBOW: { return TRUE; } break;
  case BASE_ITEM_LONGSWORD: { return TRUE; } break;
  case BASE_ITEM_MORNINGSTAR: { return TRUE; } break;
  case BASE_ITEM_QUARTERSTAFF: { return TRUE; } break;
  case BASE_ITEM_RAPIER: { return TRUE; } break;
  case BASE_ITEM_SCIMITAR: { return TRUE; } break;
  case BASE_ITEM_SCYTHE: { return TRUE; } break;
  case BASE_ITEM_SHORTBOW: { return TRUE; } break;
  case BASE_ITEM_SHORTSPEAR: { return TRUE; } break;
  case BASE_ITEM_SHORTSWORD: { return TRUE; } break;
  case BASE_ITEM_SHURIKEN: { return TRUE; } break;
  case BASE_ITEM_SICKLE: { return TRUE; } break;
  case BASE_ITEM_SLING: { return TRUE; } break;
  case BASE_ITEM_THROWINGAXE: { return TRUE; } break;
  case BASE_ITEM_TRIDENT: { return TRUE; } break;
  case BASE_ITEM_TWOBLADEDSWORD: { return TRUE; } break;
  case BASE_ITEM_WARHAMMER: { return TRUE; } break;
  case BASE_ITEM_WHIP: { return TRUE; } break;
 }
 return FALSE;
}


void RemoveSlay(object oItem) // OnHit Slay Alignment Group ONLY!
{
 int nType, nSub;
 itemproperty iProp = GetFirstItemProperty(oItem);
 while(GetIsItemPropertyValid(iProp))
 {
  nType = GetItemPropertyType(iProp);
  nSub = GetItemPropertySubType(iProp);
  if(nType == ITEM_PROPERTY_ON_HIT_PROPERTIES){
  if(nSub == IP_CONST_ONHIT_SLAYALIGNMENTGROUP)
  { RemoveItemProperty(oItem, iProp); } }
  iProp = GetNextItemProperty(oItem);
 }

}

I tested it & it works perfectly, however, you should only use this in a trigger that the PC will only ever pass by one time / entrance into the module, and NOT in the OnClientEnter event, as it can be rather intensive cycling through a players inventory & properties...



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Help Needed With Script
« Reply #2 on: March 15, 2014, 10:57:00 am »


               


 


however, you should only use this in a trigger that the PC will only ever pass by one time / entrance into the module, and NOT in the OnClientEnter event, as it can be rather intensive cycling through a players inventory & properties...

 




No need for triggers.


 


PC has 0 xp? -> PC is entering with a new character (ofc requires to keep his XP later above 0 even if he respawns - but its better solution than using database for this)


PC doesnt have a local variable LOGIN == 1 ? -> PC is entering for the first time in this server session (ofc requires to set this variable to 1 in this case)


PC has a local variable LOGIN > 0? -> PC is relogging with this character


 


Alternatively, you can use the first area OnEnter script to determine first login, but really no need for triggers.



               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help Needed With Script
« Reply #3 on: March 15, 2014, 10:58:30 am »


               


No need for triggers.


 


PC has 0 xp? -> PC is entering with a new character (ofc requires to keep his XP later above 1 even if he respawns - but its better solution than using database for this)


PC doesnt have a local variable LOGIN == 1 ? -> PC is entering for the first time in this server session (ofc requires to set this variable to 1 in this case)


PC has a local variable LOGIN > 0? -> PC is relogging with this character




 


Before you critique me bro, maybe you should look at the OP's request... This is for items, not New Players...


 


This script would be run every time the PC logged in and passed the trigger or entered the area (depending upon where you put the script), but never again if the PC walks over the trigger or enters the area again (if they haven't logged out).



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Help Needed With Script
« Reply #4 on: March 15, 2014, 11:01:43 am »


               


Before you critique me bro, maybe you should look at the OP's request... This is for items, not New Players...




I stand correct. And btw wasn't critique but suggestion to make things better.


               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help Needed With Script
« Reply #5 on: March 15, 2014, 11:08:22 am »


               


I stand correct. And btw wasn't critique but suggestion to make things better.




 


  Don't get me wrong, I didn't mean critique in the "criticize" context, but rather the "opinionated review" context. '<img'>