Mudlib
I've decided to create one, they're alot of fun actually. However, I'm stuck on one part!
HTML Code:
function onCreated() {
temp.folder.loadFolder("mudlib/*", 1);
for (temp.e: folder) {
temp.i = e.tokenize("/");
if (!i[2].ends(".txt")) continue;
temp.d = new TStaticVar();
d.loadvars("mudlib/" @ e);
makevar("item_" @ d.realname).destroy();
makevar("item_" @ d.realname) = new TStaticVar();
for (temp.f: d.getdynamicvarnames()) {
if (f.starts("#")) continue;
makevar("item_" @ d.realname).(@ f) = d.(@ f);
}
echo("MUD: Created Item-:" SPC d.displayname);
d.destroy();
}
}
So this is what creates my mudlib, it works fine! [There are no problems here]
HTML Code:
public function onItem(temp.itemname, temp.amount) {
temp.data = makevar("item_" @ itemname);
if (data == null) return false;
temp.i = (this.onGetItemCount(itemname) + amount);
if (i =< 0) {
this.client.("i_" @ itemname) = null;
this.clientr.itemnames.remove(itemname);
("i_" @ itemname) = null;
} else {
data.itemamount = max(1, i);
this.client.("i_" @ itemname) = new TStaticVar();
this.client.("i_" @ itemname).copyfrom(data);
("i_" @ itemname) = data;
if (!(itemname in this.clientr.itemnames))
this.clientr.itemnames.add(itemname);
}
echo("Amount:" SPC this.onGetItemCount(itemname));
}
public function onGetItemCount(temp.itemname) {
return this.onGetItemStat(itemname, "itemamount");
}
public function onGetItemStat(temp.itemname, temp.flag) {
return ("i_" @ itemname).(@ flag);
}
Here is the problem, when I am giving the player an item
player.onItem("Item Name", amount);
it's not saving the client.flag in the players attributes. Maybe I'm doing the object copying part wrong, I don't quite know!
Any suggestions? :)
|