|
Post by icanseethat on Mar 2, 2016 19:06:37 GMT
i want to create inventory system. I have that before but it lost due to virus infection. now i need one. Can somebody help me. I would be helpfull. thanks Or you can give me any idea how to do that. I lost the compiled project.
|
|
|
Post by NicusorN5 on Jul 1, 2016 18:19:11 GMT
Hmmm, i have no idea...
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 1, 2016 23:20:40 GMT
I think I might know how to.
|
|
|
Post by TinSoldier on Jul 2, 2016 2:42:27 GMT
Try this HASHPOOL sript created by Jestermon ...
create an empty script obj, be sure to add or have a textprint obj in the project, link it to this script and check or update the OBJ_0 reference so it points to the text obj and away you go, you can delete any parts you wont need or use.
///============///============================================================================= /// Global Hash Pool, A simple mini database for 3d Rad ///============================================================================= /// /// Many programming languages have a data type called a hash-table or a /// dictionary. This data type allows you to save and retrieve data by a /// specific key. /// /// This Global Hash pool provides this functionality, to allow you to store /// and retrieve data from the 3D Rad global string list. /// The advantage of using thie method, is that the data is availailable /// acroess all scripts in the same project, as well as between all projects /// in a compiled game. /// /// This set of functions allowes you to store ints, floats, strings, vectors /// and quaternions by a key name, and then to retrieve that same data later /// from any script back into your own variables. /// /// There is a function to store and retrieve the different data types/ /// /// there is a function that can save your data pool to disk, so that it can /// be retrieved later with the load function ///=============================================================================
///=============================================================================
/// OBJ_0 = a textprint object that you must add
string[] GHPSplit(string s, string c) { int p; string[] strList(); int valve = 0; bool done = false; string s1,s2,s3; int Idx = 0;
s3 = s; strList.resize(0); //clear the array while (!done) { valve++; if(valve == 1000) break; //while pressure valve p = iStringFind(s3,c,0,false); //find splitter if(p != -1) { iStringLeft(s1,s3,p-1); //get the 1st part iStringRight(s2,s3,iStringLen(s3)-p); //get the second part Idx = strList.length(); Idx++; strList.resize(Idx); //increase list size strList[Idx-1] = s1; //stort string part in array s3 = s2; } else { if(iStringLen(s3) > 0) //tail piece of the string { Idx++; strList.resize(Idx); strList[Idx-1] = s3; done = true; } } } return strList; }
///============================================================================= string GHPJoin(string[] array, string c) { string s = ""; int i; int L = array.length();
for(i=0; i<L-2; i++) { s = s + array[i] + c; } s = s + array[L-1]; return s; }
///============================================================================= int GHPFindKey(string key) { string buffer; int res; int i; for(i=0;i<1000;i++){ iGlobalStringGet(buffer,i); res = iStringFind(buffer,key+",",0,true); if(res != -1){ return i; } if(iStringLen(buffer) == 0){ return i; } } return -1; }
///============================================================================= ///GHPLoad: Loads the global has pool from a disk file ///--------------------------------------------------------------------------- bool GHPLoad(string filename) { string data; int i,R=0; //record base int fh = iFileReadOpen(filename); //open file for read if(fh == -1) return false; //if no file, get out with indicator for(i=0;i<1000;i++) iGlobalStringSet("",i); //clear globals for(i=0;i<5100;i++){ //for all records iFileStringRead(fh,data); if(iStringLen(data) < 1) break; //if empty recored, stop reading R++; //next record iGlobalStringSet(data,R); //load data record t oglobals } iFileClose(fh); //close the file return true; //we have lift off }
///============================================================================= ///GHPSave: Saves the global has pool to a disk file ///--------------------------------------------------------------------------- bool GHPSave(string filename) { string data; int i,R=0;//record base int fh = iFileWriteOpen(filename); //open file for write if(fh == -1) return false; //if no file, get out with indicator for(i=0;i<1000;i++){ //for all recored R++; //next record iGlobalStringGet(data,R); //read global data if(iStringLen(data) < 1) break; //no more data, get out if(iStringLen(data)>0){ //if there is data iFileStringWrite(fh,data,true); //write to file } } iFileClose(fh); //close the file return true; //we have closure }
///============================================================================= ///GHPSetInt: Sets an int to the global hash pool by key name ///============================================================================= void GHPSetInt(string key, int data) { int i,idx; string ghdata = key + ","+data; idx = GHPFindKey(key); if(idx == -1) return; iGlobalStringSet(ghdata,idx); }
///============================================================================= ///GHPSetFloat: Sets a float to the global hash pool by key name ///============================================================================= void GHPSetFloat(string key, float data) { int i,idx; string ghdata = key + ","+data; idx = GHPFindKey(key); if(idx == -1) return; iGlobalStringSet(ghdata,idx); }
///============================================================================= ///GHPSetString: Sets a string to the global hash pool by key name ///============================================================================= void GHPSetString(string key, string data) { int i,idx; string ghdata = key + ","+data; idx = GHPFindKey(key); if(idx == -1) return; iGlobalStringSet(ghdata,idx); }
///============================================================================= ///GHPSetVector: Sets a vector to the global hash pool by key name ///============================================================================= void GHPSetVector(string key, Vector3 data) { int i,idx; string buffer; string ghdata = key + ","+data.x+","+data.y+","+data.z; idx = GHPFindKey(key); if(idx == -1) return; iGlobalStringSet(ghdata,idx); }
///============================================================================= ///GHPSetQuat: Sets a quaternion to the global hash pool by key name ///============================================================================= void GHPSetQuat(string key, Quaternion data) { int i,idx; string buffer; string ghdata = key + ","+data.x+","+data.y+","+data.z+","+data.w; idx = GHPFindKey(key); if(idx == -1) return; iGlobalStringSet(ghdata,idx); }
///============================================================================= ///GHPGetInt: Gets an int from the global hash pool by key name ///============================================================================= int GHPGetInt(string key) { int i,idx; string []list; float num; string buffer; idx = GHPFindKey(key); if(idx == -1) return -1; iGlobalStringGet(buffer,idx); list = GHPSplit(buffer,","); if(list.length() > 1){ num = iStringVal(list[1]); return num; } return -1; }
///============================================================================= ///GHPGetFloat: Gets a float from the global hash pool by key name ///============================================================================= float GHPGetFloat(string key) { int i,idx; string []list; float num; string buffer; idx = GHPFindKey(key); if(idx == -1) return -1; iGlobalStringGet(buffer,idx); list = GHPSplit(buffer,","); if(list.length() > 1){ num = iStringVal(list[1]); return num; } return -1; }
///============================================================================= ///GHPGetString: Gets a string from the global hash pool by key name ///============================================================================= string GHPGetString(string key) { int i,idx; string []list; string buffer; idx = GHPFindKey(key); if(idx == -1) return -1; iGlobalStringGet(buffer,idx); list = GHPSplit(buffer,","); if(list.length() > 1){ buffer = list[1]; return buffer; } return "-1"; }
///============================================================================= ///GHPGetVector: Gets a vector from the global hash pool by key name ///============================================================================= Vector3 GHPGetVector(string key) { int i,idx; string []list; string buffer; Vector3 v = Vector3(0,0,0); idx = GHPFindKey(key); if(idx == -1) return -1; iGlobalStringGet(buffer,idx); list = GHPSplit(buffer,","); if(list.length() > 3){ v.x = iStringVal(list[1]); v.y = iStringVal(list[2]); v.z = iStringVal(list[3]); return v; } return v; }
///============================================================================= ///GHPGetQuat: Gets a quaternion from the global hash pool by key name ///============================================================================= Quaternion GHPGetQuat(string key) { int i,idx; string []list; string buffer; Quaternion q = Quaternion(0,0,0,0); idx = GHPFindKey(key); if(idx == -1) return -1; iGlobalStringGet(buffer,idx); list = GHPSplit(buffer,","); if(list.length() > 4){ q.x = iStringVal(list[1]); q.y = iStringVal(list[2]); q.z = iStringVal(list[3]); q.w = iStringVal(list[4]); return q; } return q; }
///============================================================================= ///END OF GLOBAL HASH POOL FUNCTIONS - Add your script below ///=============================================================================
int PRINT = OBJ_0; string S;
///============================================================================= void Main() { int i; Vector3 v = Vector3(12.12, 34.34, 56.56); Quaternion q = Quaternion(1.1, 2.2, 3.3, 1); Quaternion q2 = Quaternion(2, 4, 6, 1);
if(iInitializing()){ GHPSetFloat("MyInt",123); GHPSetFloat("MyFloat",123.456); GHPSetString("MyString","Hello world"); GHPSetVector("MyVector",v); GHPSetQuat("MyQuat",q); GHPSetQuat("MyQuat2",q2); GHPSave("MyHash.txt"); }
for(i=0;i<20;i++){ iGlobalStringGet(S,i); iPrint(S,-14,11-i,PRINT); }
int myInt = GHPGetInt("MyInt"); iPrint(S=myInt,0,11,PRINT);
float myFloat = GHPGetFloat("MyFloat"); iPrint(S=myFloat,0,10,PRINT);
string myString = GHPGetString("MyString"); iPrint(myString,0,9,PRINT);
Vector3 myVector = GHPGetVector("MyVector"); iPrint(S=myVector.x+" "+myVector.y+" "+myVector.z,0,8,PRINT);
Quaternion myQuat = GHPGetQuat("MyQuat"); iPrint(S=myQuat.x+" "+myQuat.y+" "+myQuat.z+" "+myQuat.w,0,7,PRINT);
myQuat = GHPGetQuat("MyQuat2"); iPrint(S=myQuat.x+" "+myQuat.y+" "+myQuat.z+" "+myQuat.w,0,6,PRINT); }
try this
|
|