NWScript :
//:: //
//:: Updated 2006-03-21 Lylver
//:: NWN-FF 4.1.00 used
//:: //
//:: Updated 2006-03-14 Lylver
//:: prefetch 2da Cache
#include "ly_lib_time"
#include "bbs_lib_item" // disponible dans "vos scripts"
#include "ff_include" // optionnel j'utilise maintenant NWN-FF 4.1.00
void main(){
object oMod = GetModule() ;
// ajout NWN-FF 21 Mars 2006
int FFDB = GetLocalInt(oMod,"FFDB");
//
switch (GetUserDefinedEventNumber()) {
case 900:{
// 2da prefetch
// fetch some 2da from DB or from 2da file
// create a database for faster prefetch
object o2da = GetWaypointByTag("DB_2DA");
int nSpell = GetLocalInt(o2da,"2DA_SPELL");
int bLoop = TRUE ;
float fDelay = 12.0;
while( bLoop ){ //FFDB : test 2*805 fetch
if( nSpell == ((nSpell / 20) * 20) ){
bLoop = FALSE;
fDelay = 1.0;
WriteTimestampedLogEntry("2da Spell Fetch : nSpell = "+IntToString(nSpell));
}
if( nSpell > 805 ){
WriteTimestampedLogEntry("2da Spell Fetch Completed !");
break ; // finished !
}
int nLevel;
string sImmunity;
string sSQL;
int iRes;
// Log
// WriteTimestampedLogEntry(" ;2da Spell Fetch : "+IntToString(nSpell));
//
// avec NWN-FF
//
if( FFDB ){
// Try dDB first
sSQL = "SELECT Innate FROM 2daSpells WHERE SpellID=" + IntToString(nSpell) ;
iRes = SQLLocalExecAndFetchDirect(sSQL);
nLevel = SQLLocalEatDataInt();
//
if( nLevel <= 0 ){
nLevel = 1 + StringToInt(Get2DAString("spells","Innate",nSpell)) ;
sSQL = "INSERT INTO 2daSpells (SpellID,Innate) VALUES(" +
IntToString(nSpell) + "," + IntToString(nLevel) +")";
SQLExecDirect(sSQL);
bLoop = FALSE; // force le DELAYCOMMAND si lecture 2da : plusieurs passes
}
SetLocalInt(o2da,"spellsInnate"+IntToString(nSpell),nLevel);
//
sSQL = "SELECT ImmunityType FROM 2daSpells WHERE SpellID=" + IntToString(nSpell) ;
iRes = SQLLocalExecAndFetchDirect(sSQL);
sImmunity = SQLLocalEatData();
//
if( sImmunity == "" ){
sImmunity = Get2DAString("spells","ImmunityType",nSpell) ;
// ajout d'un prefixe #
sSQL = "UPDATE 2daSpells SET ImmunityType='#" + sImmunity +
"' WHERE SpellID=" + IntToString(nSpell);
SQLExecDirect(sSQL) ;
bLoop = FALSE; // force le DELAYCOMMAND si lecture 2da : plusieurs passes
} else { // retrait du prefixe #
sImmunity = GetStringRight(sImmunity,GetStringLength(sImmunity)-1);
}
//
SetLocalString(o2da,"spellsImmunityType"+IntToString(nSpell),sImmunity);
} else { // no NWN-FF
//
// pour le cas sans NWN-FF
//
bLoop = FALSE; // force le DELAYCOMMAND : plusieurs passes
// Try dDB first
struct MemDB dDB;
dDB.sDB = "2DA_SPELL";
/* non utile si on utilise pas le systeme de CACHE
dDB.oChi = GetLocalObject(oMod,"DBI_ READ");
dDB.oChs = GetLocalObject(oMod,"DBS_ READ");
dDB.oDbi = GetLocalObject(oMod,"DBI_ FIFO");
dDB.oDbs = GetLocalObject(oMod,"DBS_ FIFO");
*/
dDB.sVar = "";
dDB.nValue = 0;
dDB.sValue = "";
//
dDB.sVar = "Innate"+IntToString(nSpell);
// nLevel = GCacheInt(dDB) ;
nLevel = GetCampaignInt(dDB.sDB,dDB.sVar)
if( nLevel == 0 ){
nLevel = 1 + StringToInt(Get2DAString("spells","Innate",nSpell)) ;
dDB.nValue = nLevel ; // SCacheInt(dDB) ;
SetCampaignInt(dDB.sDB,dDB.sVar,dDB.nValue) ;
} else {
fDelay = 0.4;
}
SetLocalInt(o2da,"spellsInnate"+IntToString(nSpell),nLevel);
//
dDB.sVar = "ImmunityType"+IntToString(nSpell);
// sImmunity = GCacheString(dDB) ;
sImmunity = GetCampaignString(dDB.sDB,dDB.sVar) ;
if( sImmunity == "" ){
sImmunity = Get2DAString("spells","ImmunityType",nSpell) ;
dDB.sValue = "#"+sImmunity; // SCacheString(dDB) ;
SetCampaignString(dDB.sDB,dDB.sVar,dDB.sValue) ;
} else {
sImmunity = GetStringRight(sImmunity,GetStringLength(sImmunity)-1);
}
//
SetLocalString(o2da,"spellsImmunityType"+IntToString(nSpell),sImmunity);
}
SetLocalInt(o2da,"2DA_SPELL",++nSpell);
} // while
// Continue Slow fetch
if( !(bLoop) ) DelayCommand(fDelay, SignalEvent(OBJECT_SELF, EventUserDefined(900)));
break ;
}
}
}Note : le code affiché ci-dessus n'est pas rendu tel qu'il devrait l'être réellement, en particulier des sauts de lignes sont automatiquement insérés pour éviter de casser la mise en page. En le copiant/collant, vous résoudrez ce problème.
//:: //
//:: Updated 2006-03-21 Lylver
//:: NWN-FF 4.1.00 used
//:: //
//:: Updated 2006-03-14 Lylver
//:: prefetch 2da Cache
#include "ly_lib_time"
#include "bbs_lib_item" // disponible dans "vos scripts"
#include "ff_include" // optionnel j'utilise maintenant NWN-FF 4.1.00
void main(){
object oMod = GetModule() ;
// ajout NWN-FF 21 Mars 2006
int FFDB = GetLocalInt(oMod,"FFDB");
//
switch (GetUserDefinedEventNumber()) {
case 900:{
// 2da prefetch
// fetch some 2da from DB or from 2da file
// create a database for faster prefetch
object o2da = GetWaypointByTag("DB_2DA");
int nSpell = GetLocalInt(o2da,"2DA_SPELL");
int bLoop = TRUE ;
float fDelay = 12.0;
while( bLoop ){ //FFDB : test 2*805 fetch
if( nSpell == ((nSpell / 20) * 20) ){
bLoop = FALSE;
fDelay = 1.0;
WriteTimestampedLogEntry("2da Spell Fetch : nSpell = "+IntToString(nSpell));
}
if( nSpell > 805 ){
WriteTimestampedLogEntry("2da Spell Fetch Completed !");
break ; // finished !
}
int nLevel;
string sImmunity;
string sSQL;
int iRes;
// Log
// WriteTimestampedLogEntry(" ;2da Spell Fetch : "+IntToString(nSpell));
//
// avec NWN-FF
//
if( FFDB ){
// Try dDB first
sSQL = "SELECT Innate FROM 2daSpells WHERE SpellID=" + IntToString(nSpell) ;
iRes = SQLLocalExecAndFetchDirect(sSQL);
nLevel = SQLLocalEatDataInt();
//
if( nLevel <= 0 ){
nLevel = 1 + StringToInt(Get2DAString("spells","Innate",nSpell)) ;
sSQL = "INSERT INTO 2daSpells (SpellID,Innate) VALUES(" +
IntToString(nSpell) + "," + IntToString(nLevel) +")";
SQLExecDirect(sSQL);
bLoop = FALSE; // force le DELAYCOMMAND si lecture 2da : plusieurs passes
}
SetLocalInt(o2da,"spellsInnate"+IntToString(nSpell),nLevel);
//
sSQL = "SELECT ImmunityType FROM 2daSpells WHERE SpellID=" + IntToString(nSpell) ;
iRes = SQLLocalExecAndFetchDirect(sSQL);
sImmunity = SQLLocalEatData();
//
if( sImmunity == "" ){
sImmunity = Get2DAString("spells","ImmunityType",nSpell) ;
// ajout d'un prefixe #
sSQL = "UPDATE 2daSpells SET ImmunityType='#" + sImmunity +
"' WHERE SpellID=" + IntToString(nSpell);
SQLExecDirect(sSQL) ;
bLoop = FALSE; // force le DELAYCOMMAND si lecture 2da : plusieurs passes
} else { // retrait du prefixe #
sImmunity = GetStringRight(sImmunity,GetStringLength(sImmunity)-1);
}
//
SetLocalString(o2da,"spellsImmunityType"+IntToString(nSpell),sImmunity);
} else { // no NWN-FF
//
// pour le cas sans NWN-FF
//
bLoop = FALSE; // force le DELAYCOMMAND : plusieurs passes
// Try dDB first
struct MemDB dDB;
dDB.sDB = "2DA_SPELL";
/* non utile si on utilise pas le systeme de CACHE
dDB.oChi = GetLocalObject(oMod,"DBI_ READ");
dDB.oChs = GetLocalObject(oMod,"DBS_ READ");
dDB.oDbi = GetLocalObject(oMod,"DBI_ FIFO");
dDB.oDbs = GetLocalObject(oMod,"DBS_ FIFO");
*/
dDB.sVar = "";
dDB.nValue = 0;
dDB.sValue = "";
//
dDB.sVar = "Innate"+IntToString(nSpell);
// nLevel = GCacheInt(dDB) ;
nLevel = GetCampaignInt(dDB.sDB,dDB.sVar)
if( nLevel == 0 ){
nLevel = 1 + StringToInt(Get2DAString("spells","Innate",nSpell)) ;
dDB.nValue = nLevel ; // SCacheInt(dDB) ;
SetCampaignInt(dDB.sDB,dDB.sVar,dDB.nValue) ;
} else {
fDelay = 0.4;
}
SetLocalInt(o2da,"spellsInnate"+IntToString(nSpell),nLevel);
//
dDB.sVar = "ImmunityType"+IntToString(nSpell);
// sImmunity = GCacheString(dDB) ;
sImmunity = GetCampaignString(dDB.sDB,dDB.sVar) ;
if( sImmunity == "" ){
sImmunity = Get2DAString("spells","ImmunityType",nSpell) ;
dDB.sValue = "#"+sImmunity; // SCacheString(dDB) ;
SetCampaignString(dDB.sDB,dDB.sVar,dDB.sValue) ;
} else {
sImmunity = GetStringRight(sImmunity,GetStringLength(sImmunity)-1);
}
//
SetLocalString(o2da,"spellsImmunityType"+IntToString(nSpell),sImmunity);
}
SetLocalInt(o2da,"2DA_SPELL",++nSpell);
} // while
// Continue Slow fetch
if( !(bLoop) ) DelayCommand(fDelay, SignalEvent(OBJECT_SELF, EventUserDefined(900)));
break ;
}
}
}