here's a bit of code that you might find useful...
Code: Select all
use datafile;
function CacheGump(group, name, layout, data)
var gumpcache := OpenDataFile("::cachedgumps");
if (!gumpcache)
gumpcache := CreateDataFile("::cachedgumps");
endif
var cacheelem := gumpcache.FindElement(group);
if (!cacheelem)
cacheelem := gumpcache.CreateElement(group);
endif
var gump := struct{};
gump.layout := layout;
gump.data := data;
cacheelem.setprop(name, gump);
UnloadDataFile("::cachedgumps");
endfunction
function RestoreCachedGump(group, name)
UnloadDataFile("::cachedgumps");
var gumpcache := OpenDataFile("::cachedgumps");
if (!gumpcache)
CreateDataFile("::cachedgumps");
return 0;
endif
var cacheelem := gumpcache.FindElement(group);
if (!cacheelem)
return 0;
endif
var gump := cacheelem.getprop(name);
if (!gump)
return 0;
endif
if (gump.layout && gump.data)
return gump;
endif
return 0;
endfunction
in your gump code:
Code: Select all
var gump := RestoreCachedGump(group, name);
if (!gump)
//Build all unchanging items in your gump here.
CacheGump(group, name, layout, data);
else
layout := gump.layout;
data := gump.data;
endif
//Build all variable items in your gump here
The group and name variables you pass can be whatever you think of. For instance I have group := "crafting"; and name := "tinkering". If you have multiple tools with different menus, the group could be named after the skill and the gump name could be the tool name, ect...
Example: RestoreCachedGump("crafting", "tinkering");
if it returns 0, it means you'll have to build the gump and subsequently call CacheGump("crafting", "tinkering", layout, data); to cache the gump under that group/name.
to delete it, I have a text command .deletegump
Code: Select all
use datafile;
use os;
use uo;
program deletegump(who, text)
text := SplitWords(text);
var gumpcache := OpenDataFile("::cachedgumps");
if (!gumpcache)
return;
endif
var cacheelem := gumpcache.FindElement(text[1]);
if (!cacheelem)
return;
endif
SendSysMessage(who, CStr(cacheelem.eraseprop(text[2])));
endprogram
usage: .deletegump crafting tinkering
that will delete the tinkering gump and send you '1' in a SysMessage or show you an error. Also remember, the group/name variables are case sensitive.