If you have a script that you feel would be helpful to the community at
large, and would like to share it with the community, post it here.
Here's a few useful ones from the old thread:
XP for level and level for XP:
// Data function: Return the corresponding level for the given XP.
int C_GetLevelByXP(int iXP);
// Data function: Return the corresponding XP for the given Level.
int C_GetXPByLevel(int iLevel);
// Data function: Return the corresponding level for the given XP.
int C_GetLevelByXP(int iXP)
{
int iLevel = 1;
int iXPLimit = 0;
while (iXPLimit <= iXP) {
iXPLimit += (iLevel * 1000);
iLevel++;
}
return iLevel - 1;
}
// Data function: Return the corresponding XP for the given Level.
int C_GetXPByLevel(int iLevel)
{
return 500 * iLevel * (iLevel - 1);
}
Posted by: weby
A rest script, hardcoded for 8 hours rest:
void main()
{
object oPC ;
int nRest ;
location nloc ;
int hour ;
int thour ;
int day ;
int lhour ;
int lday ;
int diff ;
day = GetCalendarDay() ;
hour = GetTimeHour() ;
nRest = GetLastRestEventType();
oPC = GetLastPCRested() ;
if (nRest == REST_EVENTTYPE_REST_FINISHED) {
SetLocalInt(oPC, "LastRestedDay", day) ;
SetLocalInt(oPC, "LastRestedHour", hour) ;
}
else if (nRest == REST_EVENTTYPE_REST_STARTED) {
if (GetIsObjectValid(oPC)) {
nloc = GetLocation(oPC) ;
lday = GetLocalInt(oPC, "LastRestedDay") ;
lhour = GetLocalInt(oPC, "LastRestedHour") ;
thour = hour+(day-lday)*24 ;
diff = thour-lhour ;
if (diff < 8) {
SendMessageToPC(oPC, "You are not tired enough to rest. Wait "+IntToString(8-diff)+" more hours.") ;
AssignCommand(oPC, ClearAllActions());
}
}
}
}
Posted by: Olblach[/b]
Inventory locking script:
Here's a custom function that will identify all carried items, make them undroppable and make them unremovable (i.e. cursed). Helpful say for a companion whose inventory you don't want the player to empty. Also circumvents having to create identified versions of blueprints of magic items. Use anywhere, but a logical place is in an OnSpawn script.
[nwscript]
void HandsOffMyInventory( object oTarget )
{
//Check inventory items
object oItem = GetFirstItemInInventory( oTarget );
while ( GetIsObjectValid( oItem ) )
{
SetIdentified( oItem, TRUE );
SetDroppableFlag( oItem, FALSE );
SetItemCursedFlag( oItem, TRUE );
oItem = GetNextItemInInventory( oTarget );
}
//Check equipped items
int nSlot;
for (nSlot=0; nSlot<NUM_INVENTORY_SLOTS; nSlot++)
{
oItem=GetItemInSlot( nSlot, oTarget );
if (GetIsObjectValid( oItem ))
{
SetIdentified( oItem, TRUE );
SetDroppableFlag( oItem, FALSE );
SetItemCursedFlag( oItem, TRUE );
}
}
}
[/nwscript]
Posted by: ciViLiZed
Treasure pile script:
Here's a simple script to use for a treasure placeable to give the PC some gold when they click on it and destroy the gold pile afterwards. Placeable must be useable and non-static, and attach a variable - integer called iGold, set to the amount of gold you wish to give
void main()
{
object oPC = GetLastUsedBy();
int nGP = GetLocalInt(OBJECT_SELF, "iGold");
GiveGoldToCreature(oPC, nGP, TRUE);
DestroyObject(OBJECT_SELF);
}Posted by: Wyrin_D'njargo
Universal door/lever script:
I've seen several requests for a "pull a lever and the door opens" script over the last couple months, so thought I would offer this.
The nice thing about this script is that it's tag based, so you can use the same script for every lever and door without altering the script. The lever should have the tag leverXX and the door should have the tag doorXX where XX is the same for both.
[nwscript]
/*
Modified from standard template "use_lever"
Assumes initial state is deactivated.
If initial state is activated, apply variable
set "ActivatedState" to placeable
Assumes the Tag of the activating lever is
"leverXX" and the target door is "doorXX" where
XX is the same for both.
*/
void main()
{
PlaySound("as_sw_lever1");
ExecuteScript("x2_plc_used_act", OBJECT_SELF);
int bActivated = GetLocalInt(OBJECT_SELF,"X2_L_PLC_ACTIVATED_STATE");
// Get the right target
object oTarget; //The door to be opened
string sSubstring; //The lever number
sSubstring = GetSubString(GetTag(OBJECT_SELF), 5, 2);
// SpeakString("Using lever number: " + sSubstring);
oTarget = GetObjectByTag("gate" + sSubstring);
// SpeakString("Affecting door with tag: " + GetTag(oTarget));
// Open or close it depending on the current state.
// Play the sound effect for the lever.
if (bActivated == TRUE)
{
SetLocked(oTarget, FALSE);
AssignCommand(oTarget, ActionOpenDoor(oTarget));
SpeakString("Door unlocked and opened.");
}
else
{
AssignCommand(oTarget, ActionCloseDoor(oTarget));
SetLocked(oTarget, TRUE);
SpeakString("Door closed and locked.");
}
}
[/nwscript]
Posted by: ddaedelus
Feel free to post new ones or bring other ones over from the origenal topic.
[/b]





Retour en haut






