Aller au contenu

Photo

Troublesome stores


  • Veuillez vous connecter pour répondre
30 réponses à ce sujet

#26
Greyfort

Greyfort
  • Members
  • 234 messages
Another issue is taking the stored string and turning it into a item prop as seen in this code:

int nMaxIndex= GetCampaignInt(sDBName,"NumItems",oObject);
int nIndex;
for (nIndex = 1; nIndex
{
sItmCreate=GetCampaignString(sDBName,"Item_"+IntToString( nIndex )+"",oObject);
object oItem=CreateObject(OBJECT_TYPE_ITEM,sItmCreate,GetLocation(OBJECT_SELF) );
if( !GetIsObjectValid (oItem) )
{
int nMaxIndexProp= GetCampaignInt(sDBName,"Item_"+IntToString( nIndex )+"_MaxItemProps",oObject);
int nIndexProp;
for (nIndexProp = 1; nIndexProp
{
itemproperty ipProperty;
string ipString= GetCampaignString(sDBName,"Item_"+IntToString( nIndex )+"_ItemProp_"+IntToString( nIndexProp )+"",oObject );
ipProperty = StringToInt( ipString );
AddItemProperty(DURATION_TYPE_PERMANENT,ipProperty,oItem);
}//end of for item props
}//end of if oItem valid
}//end of for number of items

ipProperty = StringToInt( ipString ); as seen in this line I get...ERROR: MISMATCHED TYPES
yet a Item property is a int when whe use StringToInt(Get2DAString(string s2DA, string sColumn, int nRow);

so I'm perplexed by the error. And on the aboved script trying to make a function, i see I was trying to make string tokens and forgot to code that right. man i was tired yesterday when I posted it.

Modifié par Greyfort, 15 janvier 2011 - 04:52 .


#27
Greyfort

Greyfort
  • Members
  • 234 messages
I was wandering If any know of the top of there head will what I have written here work correctly for the GetStringTokenizer(string sString, string sDelim) function? I'm trying to get the property of a item broken up and stored in nwnDB

//
//gets items properties sets to nwnDB
//
string SetDBItemProps(string sDBName,string sVarName,string sValue,object oObject);


string SetDBItemProps(string sDBName,string sVarName,string sValue,object oObject)
{
object oItem;
//Get the first itemproperty on the oItem
itemproperty ipLoop=GetFirstItemProperty(oItem);
int nType;
int nSubType;
int nDurType;
string sValue;

string sDelimiter = "|";
string sType;
string sSubType;
string sDurType;
//Loop for as long as the ipLoop variable is valid
while (GetIsItemPropertyValid(ipLoop))
{
ntype=GetItemPropertyType(ipLoop);
sType=IntToString(ntype);

nSubType=GetItemPropertySubType(ipLoop);
sSubType=IntToString(nSubType);

nDurType=GetItemPropertyDurationType(ipLoop);
sDurType=IntToString(nDurType);

//sValue=IntToString( ntype+"|"+ nSubType +"|"+ nDurType );
sValue= sType+ sDelimiter + sSubType + sDelimiter + sDurType;
//Next itemproperty on the list...
ipLoop=GetNextItemProperty(oItem);
}

return sValue;
}

Modifié par Greyfort, 15 janvier 2011 - 04:53 .


#28
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
If you are talking about the X0_I0_STRINGLIB function I dont see why it would not work.   Even though I use that include way to much, it is not that effecient.  I also normally only use the GetTokenByPosition function.  Using the other functions in the include can make it a little more effecient, But not by enough for me to go through the headach of using them. 

If you want an already written more efficent way to parse the string, I would sugest looking at

string StringParse(string sSource, string sDelimiter = " ", int bRightToLeft = FALSE)
and
string StringRemoveParsed(string sSource, string sParsed, string sDelimiter = " ", int bRightToLeft = FALSE)

From the 'x3_inc_string' include file.

#29
Greyfort

Greyfort
  • Members
  • 234 messages
ok once again, the issue I seem to have is when I get a item property and store it in the nwnDB as a string, and then retrive the string from the nwnDB I get...



itemproperty ipProperty;

string ipString= GetCampaignString(sDBName,"Item_"+IntToString( nIndex )+"_ItemProp_"+IntToString( nIndexProp )+"",oObject );

ipProperty = StringToInt( ipString );// error this line



itm_exam_get.nss(67): ERROR: MISMATCHED TYPES



Its my understanding that I need to store the Item props as strings then turn them into int but I keep getting error

#30
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
I think you are going the wrong way with this.  Yes you can tare the Iprop apart and rebuild it.  The reason you are getting you error is that  an itemproptery is not an 'int'  it is a structure of type itempoperty.  so you will have to rebuild it mor along the lines shown below.


#include "x0_i0_stringlib"

 void main()
{
  object oItem;
  // to turn the iproptery into a string.
  itemproperty  ipProperty =  GetFirstItemProperty (oItem);
  string sIprop = IntToString (GetItemPropertyType(ipProperty));
  sIprop +=       "|"+IntToString(GetItemPropertyCostTableValue(ipProperty));
  sIprop +=       "|"+ IntToString(GetItemPropertyDurationType (ipProperty));
  sIprop +=       "|"+ IntToString( GetItemPropertyParam1(ipProperty));
  sIprop +=       "|"+ IntToString( GetItemPropertyParam1Value(ipProperty));
  sIprop +=       "|"+ IntToString( GetItemPropertySubType(ipProperty));

  // To turn the string  back to an Iproperty is going to be harder.
  int nPropType= StringToInt( GetTokenByPosition(sIprop,"|",0));
  int nPropValue=StringToInt( GetTokenByPosition(sIprop,"|",1));
  int nDuration =StringToInt( GetTokenByPosition(sIprop,"|",2));
  int nPram1    =StringToInt( GetTokenByPosition(sIprop,"|",3));
  int nPram1Val =StringToInt( GetTokenByPosition(sIprop,"|",4));
  int nSubType  =StringToInt( GetTokenByPosition(sIprop,"|",5));

  object oNewItem;
  itemproperty ipRemadeProp;
  switch (nPropType)
  {
     case ITEM_PROPERTY_ABILITY_BONUS:
       ipRemadeProp= ItemPropertyAbilityBonus( nSubType, nPropValue);
       break;
     case ITEM_PROPERTY_AC_BONUS:
       ipRemadeProp = ItemPropertyACBonus( nPropValue);
       break;
     /// ect. making a case for each of the 48 or so item properties.
  }

  // add the prop to the item.
  AddItemProperty( nDuration ,ipRemadeProp,oNewItem);
}

I think you would be much better served writing a rutine to store all the items on an NPC. or more then one NPC depending on the number of items.  Along with a function to compare if items are the same or not. 

I once wrote such a function,  It however died with the hard drive i had it stored on.  I just have not gotten around to writting it again yet. 

Best of luck in what ever direction you decide to go,
L8

#31
Greyfort

Greyfort
  • Members
  • 234 messages
Thanks Lightfoot8, I'll keep at it