Author Topic: Endless List of HomeBrew Functions [post functions only, not for asking questions]  (Read 1391 times)

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               Repeating + continuing from old forums:

I'm pasting there functions I found usefull:

Author: Primogenitor
Here are some map-pin manipulation functions. They come from this thread: Click Here
One word of warning though, map pins dont change until a player enters the area (either by load/save, logoff/logon or normally).

//return the total number of map pins this PC has placed
int     GetNumberOfMapPins(object oPC);
//get the area object of a specific map pin
object  GetAreaOfMapPin(object oPC, int nPinNo);
//delete a specific map pin
void    DeleteMapPin(object oPC, int nPinNo);
int GetNumberOfMapPins(object oPC)
{
    return GetLocalInt(oPC, "NW_TOTAL_MAP_PINS");
}
object  GetAreaOfMapPin(object oPC, int nPinNo)
{
    return GetLocalObject(oPC, "NW_MAP_PIN_AREA_"+IntToString(nPinNo));
}
void DeleteMapPin(object oPC, int nPinNo)
{
    if(nPinNo < 1)
        return;
    if(!GetIsObjectValid(oPC))
        return;
    int nPinCount = GetNumberOfMapPins(oPC);
    if(nPinCount < 1)
        return;
    if(nPinCount < nPinNo)
        return;
    DeleteLocalString(oPC, "NW_MAP_PIN_NRTY_"+IntToString(nPinNo));
    DeleteLocalFloat( oPC, "NW_MAP_PIN_XPOS_"+IntToString(nPinNo));
    DeleteLocalFloat( oPC, "NW_MAP_PIN_YPOS_"+IntToString(nPinNo));
    DeleteLocalObject(oPC, "NW_MAP_PIN_AREA_"+IntToString(nPinNo));
    int i = nPinNo+1;
    for (i=nPinNo+1;i<nPinCount;i++)
    {
        SetLocalString(oPC, "NW_MAP_PIN_NRTY_"+IntToString(i), GetLocalString(oPC, "NW_MAP_PIN_NRTY_"+IntToString(i+1)));
        SetLocalFloat( oPC, "NW_MAP_PIN_XPOS_"+IntToString(i), GetLocalFloat (oPC, "NW_MAP_PIN_XPOS_"+IntToString(i+1)));
        SetLocalFloat( oPC, "NW_MAP_PIN_YPOS_"+IntToString(i), GetLocalFloat (oPC, "NW_MAP_PIN_YPOS_"+IntToString(i+1)));
        SetLocalObject(oPC, "NW_MAP_PIN_AREA_"+IntToString(i), GetLocalObject(oPC, "NW_MAP_PIN_AREA_"+IntToString(i+1)));
    }
    DeleteLocalString(oPC, "NW_MAP_PIN_NRTY_"+IntToString(nPinCount));
    DeleteLocalFloat( oPC, "NW_MAP_PIN_XPOS_"+IntToString(nPinCount));
    DeleteLocalFloat( oPC, "NW_MAP_PIN_YPOS_"+IntToString(nPinCount));
    DeleteLocalObject(oPC, "NW_MAP_PIN_AREA_"+IntToString(nPinCount));
    SetLocalInt(oPC, "NW_TOTAL_MAP_PINS", nPinCount-1);
}

And few my functions:

These are based on Magic's Action() function, basically you use them in delays

//Use if you need to put inside delay command function that returns object
void ObjectToVoid(object oObject);

//Use if you need to put inside delay command function that returns string
void StringToVoid(string sString);

//Use if you need to put inside delay command function that returns int
void IntToVoid(int nInt);

//Use if you need to put inside delay command function that returns float
void FloatToVoid(float fFloat);

void ObjectToVoid(object oObject)
{}

void StringToVoid(string sString)
{}

void IntToVoid(int nInt)
{}

void FloatToVoid(float fFloat)
{}


Author: ShaDoOoW
Hey guys, there is another function of my: GetLastUnEquipEventType() .
This function allow to reequip item in right moment. If you do it in
normal UnEquip script nothing gonna happen becose item is still in slot.
It could also repair item - switching bug to bypassing custom ILR or
similars systems but untested!.

void main();

// Determine the type (UNEQUIP_EVENTTYPE_UNEQUIP_*) of the last unequip event (as
// returned from the OnUnequip module event).
int GetLastUnEquipEventType();

const int UNEQUIP_EVENTTYPE_UNEQUIP_INVALID = -1;
const int UNEQUIP_EVENTTYPE_UNEQUIP_STARTED = 0;
const int UNEQUIP_EVENTTYPE_UNEQUIP_FINISHED = 1;

int GetSlotByItem(object oItem, object oCreature=OBJECT_SELF)
{
int nTh;
 for(;nTh < NUM_INVENTORY_SLOTS;nTh++)
 {
 object oitem = GetItemInSlot(nTh,oCreature);
  if(oitem == oItem)
  {
  return nTh;
  }
 }
return -1;
}

void GetUnEquipFinishedEvent(object oPC, object oItem, int nSlot)
{
object oItem2 = GetItemInSlot(nSlot,oPC);
 if(!GetIsObjectValid(oItem2))
 {
 SetLocalInt(oPC,"GetLastUnEquipEventType()",UNEQUIP_EVENTTYPE_UNEQUIP_FINISHED);
 main();
 DeleteLocalInt(oPC,"GetLastUnEquipEventType()");
 }
 else if(oItem2 != oItem)
 {
 SetLocalInt(oPC,"GetLastUnEquipEventType()",UNEQUIP_EVENTTYPE_UNEQUIP_FINISHED);
 main();
 DeleteLocalInt(oPC,"GetLastUnEquipEventType()");
 }
 else
 {
 DelayCommand(0.1,GetUnEquipFinishedEvent(oPC,oItem,nSlot));
 }
}

int GetLastUnEquipEventType()
{
object oItem = GetPCItemLastUnequipped();
object oPC = GetPCItemLastUnequippedBy();
int ret = GetLocalInt(oPC,"GetLastUnEquipEventType()");
 if(GetIsObjectValid(oPC) && GetIsObjectValid(oItem))
 {
  if(!ret)
  {
  GetUnEquipFinishedEvent(oPC,oItem,GetSlotByItem(oItem,oPC));
  }
 }
 else
 {
 return UNEQUIP_EVENTTYPE_UNEQUIP_INVALID;
 }
return ret;
}

example

#include "above"

void main()
{
object oItem, oPC = GetPCItemLastUnequippedBy();
int nType = GetLastUnEquipEventType();
 if(nType == UNEQUIP_EVENTTYPE_UNEQUIP_STARTED)
 { //EVENT_MODULE_ON_PLAYER_UNEQUIP_ITEM_STARTED; item is still in slot
 oItem = GetPCItemLastUnequipped();
 //do some stuff here
 }
 else if(nType == UNEQUIP_EVENTTYPE_UNEQUIP_FINISHED)
 {//EVENT_MODULE_ON_PLAYER_UNEQUIP_ITEM_FINISHED item is in inventory now

 //But I'm not sure if GetPCItemLastUnequipped() is still valid...

 }
 else
 {//EVENT_MODULE_ON_PLAYER_UNEQUIP_ITEM_INVALID - didnt happened to me yet
 }
}

some XP functions I'm using quite often I'm author, but I took GetLeveByXP formula from someone else, don't know who, it appeared at forums so many times...

//count creatures level by her XP
int GetLevelByXP(object oCreature);

//returns XP amount that creature has above XP required to her level
int GetXPAboveLevel(object oCreature);

//returns XP amount that is required to gain this level
int GetXPToLevel(int nLevel);

//returns XP amount needed to next level
int GetXPNeededToNextLevel(object oCreature);

int GetXPNeededToNextLevel(object oCreature)
{
return GetXPToLevel(GetLevelByXP(oCreature)+1)-GetXP(oCreature);
}

int GetXPAboveLevel(object oCreature)
{
return GetXP(oCreature)-GetXPToLevel(GetLevelByXP(oCreature));
}

int GetXPToLevel(int nLevel)
{
return --nLevel<1 ? 0 : (nLevel+1)*nLevel*500;
}

int GetLevelByXP(object oCreature)
{
return FloatToInt(0.5+sqrt(0.25+(IntToFloat(GetXP(oCreature))/500)));
}

Author: PRC Team
If you want to allow more than one summon at the time, call this before
you apply summon effect.

void MultisummonPreSummon(object oPC = OBJECT_SELF);
void MultisummonPreSummon(object oPC = OBJECT_SELF)
{
int i=1;
object oSummon = GetAssociate(ASSOCIATE_TYPE_SUMMONED,oPC,i);
 while(GetIsObjectValid(oSummon))
 {
 AssignCommand(oSummon,SetIsDestroyable(FALSE,FALSE,FALSE));
 AssignCommand(oSummon,DelayCommand(6.0,SetIsDestroyable(TRUE,FALSE,FALSE)));
 oSummon = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC,++i);
 }
}


               
               

               


                     Modifié par ShaDoOoW, 19 juillet 2010 - 09:31 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               This function will hide just applied effect's icon. How it works? Simply, I apply this effect twice, first time normally, but second time with some other effect in link. And then I will strip the second linked effect, so effect icon will disappear but original effect will stay.

//nDurationType - only permanent and temporary, its logical
//may not work properly with linked effect, proper testing is recommended
void ApplyEffectToPCAndHideIcon(int nDurationType, effect eEffect, object oPC, float fDuration=0.0);
void ApplyEffectToPCAndHideIcon(int nDurationType, effect eEffect, object oPC, float fDuration=0.0)
{
ApplyEffectToObject(nDurationType,eEffect,oPC,fDuration);
eEffect = EffectLinkEffects(eEffect,EffectTurnResistanceIncrease(1));
ApplyEffectToObject(nDurationType,eEffect,oPC,fDuration);
RemoveEffect(oPC,eEffect);
}


               
               

               


                     Modifié par ShaDoOoW, 16 décembre 2011 - 10:53 .
                     
                  


            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0


               I seen alot of scripts on the forums and used alot.These forums are awesome. So here is something I would like to share.I will give credit to a guy named monrast who made this for me.

What it does.This is the girl statue placeable holding the greatsword.It explodes and the NPC pops out to get you .Made the NPC human girl with greatsword .

Place this onenter on a trigger .

Put waypoint for NPC to spawn at same location as statue. 


void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
int nActive = GetLocalInt(OBJECT_SELF, "ACTIVE");
if ((nActive == 0) !=0)
{
object oStatue = GetObjectByTag("X2_PLC_STATUE_F");
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_COM_CHUNK_STONE_MEDIUM), GetLocation(oStatue));
DestroyObject(oStatue, 0.0);
object oTarget = GetWaypointByTag("NW_CORI");
location lTarget = GetLocation(oTarget);
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "cori002", lTarget);
SetIsTemporaryEnemy(oPC, oSpawn);
AssignCommand(oSpawn, ActionAttack(oPC));
DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_AC_BONUS), GetLocation(oSpawn)));
SetLocalInt(OBJECT_SELF, "ACTIVE", 1);
DelayCommand(300.0, SetLocalInt(OBJECT_SELF, "ACTIVE", 1));
}
if ((nActive == 1) !=0)
{
return;
}
}
'Posted
               
               

               


                     Modifié par Knight_Shield, 22 juillet 2010 - 01:53 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               This workaround for not be able to loop all areas been posted on forums many times. First I saw this from Ggeorg Zoeller at old homebrew topic (using and destroying placeable in those times). Now it appeared there from Lightfoot as well.

I'm not providing new method, just a cleaner way to do this. Forget at initializing areas into module variable list, forget about first/next. This simple function will take care of everything except you still have to manually put waypoint with the same tag in all areas. (If I find the moneo letoscript which put this waypoint in all areas for you, I'll include it as well.)

//This function returns n-th area in module, but need you to put system waypoint into each area manually 
object GetNthArea(int nTh);
object GetNthArea(int nTh)
{
return GetArea(GetObjectByTag("GET_AREA_SYSTEM_WP",nTh-1));
}

if you already got system waypoint in your areas just change tag inside the function to your waypoint's tag
               
               

               


                     Modifié par ShaDoOoW, 25 juillet 2010 - 11:44 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0


               More homebrew scripts
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0


               

Test bump.  (Making sure this new address is linked to properly from sticky).



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0


               

Tarot's 10 line script challenge



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               

Since this thread appeared up again, im adding new function that can comes up handy.


 



 


//This function fixes the issue which happens when an item with charges is depleted to 0 and then recharged via script.


//The problem is, that the cast spell itemproperty will not be functional until player rests. This function solves this.


void UpdateItemCharges(object oItem, int nCharges)

{
int charges = GetItemCharges(oItem);

SetItemCharges(oItem,nCharges);

 if(charges > 0)

 return;
itemproperty ip = GetFirstItemProperty(oItem);
float fDelay = 0.0;

 while(GetIsItemPropertyValid(ip))

 {

  if(GetItemPropertyType(ip) == ITEM_PROPERTY_CAST_SPELL)

  {

  RemoveItemProperty(oItem,ip);

  DelayCommand(fDelay,AddItemProperty(DURATION_TYPE_PERMANENT,ip,oItem));

  fDelay+=0.01;

  }

 ip = GetNextItemProperty(oItem);

 }

}