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 .