Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Mudlib (https://forums.graalonline.com/forums/showthread.php?t=80447)

[email protected] 07-11-2008 08:55 PM

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? :)

Crow 07-11-2008 08:58 PM

this.clientr? Tells me this is a player joined class. Unsecure anyway, should move that function somewhere else.

[email protected] 07-11-2008 08:59 PM

Quote:

Originally Posted by Crow (Post 1402298)
this.clientr? Tells me this is a player joined class. Unsecure anyway, should move that function somewhere else.

so this is why the client flags are not saving?? o_o
it's not insecure at all

Chompy 07-11-2008 09:39 PM

Hmm, you use client/clientr as objects? ;o

Dunno if that is possible, not sure though..

Crow 07-11-2008 10:08 PM

Quote:

Originally Posted by [email protected] (Post 1402302)
so this is why the client flags are not saving?? o_o
it's not insecure at all

You know what a big problem item duping can be. Since this code is inside the player class, it could theoretically be stopped anywhere within, just needs to right portion of lag. That screams insecure to me, sorry D:

[email protected] 07-11-2008 10:14 PM

ok novo helped me, I can't save tstaticvars [they are removed upon r/c] and i can't transfer them to clientside :(:(

Chompy 07-11-2008 10:16 PM

I usually convert the object into an array serverside, then sends it clientside and builds up an object with the info in the array I sent :o

DustyPorViva 07-11-2008 10:16 PM

Ya, I had that problem too.
Oh, and you should add a unique ID system early on to remove any ability to duplicate.

[email protected] 07-11-2008 10:24 PM

ah good idea @ Dusty, why thank u

i was going to do that @ chompy, i found it strange that objects can't be transferable to clientside tbh

xXziroXx 07-12-2008 02:43 AM

PHP Code:

temp.data temp.data.savevarstoarray(false); // Maybe true? Cant remember, think its supposed to be false...
triggerClient("gui"name"foo"temp.data); // Sends the converted TStaticVar() as an array to client

//#CLIENTSIDE
function onActionClientSide()
{
  if (
params[0] == "foo"this.data.loadVarsFromArray(params[1]); // Back to a TStaticVar!



Maybe that helps you solve the object transfering?

[email protected] 07-12-2008 08:04 AM

ooo thanks !! i'll try it once i get back home ^^ ^^

[email protected] 07-12-2008 06:13 PM

Works a charm, having true sorts it [character]

thanks tuff guy ^^ ^^

zokemon 07-12-2008 06:42 PM

Keep it false unless you really need it sorted as sorting can take quite a bit of cpu if done every time you just want to transfer data clientside.

TheStan 07-12-2008 06:50 PM

Just to go over a few things that were said here, "clientr." and "client." can definitely NOT be made into TStaticVars, lol.

Also, this is quite a bit insecure. Anything Mudlib related should be done completely serverside with copies of the information sent clientside for reading usage from systems.

zokemon 07-12-2008 06:52 PM

Quote:

Originally Posted by TheStan (Post 1402664)
Just to go over a few things that were said here, "clientr." and "client." can definitely NOT be made into TStaticVars, lol.

Also, this is quite a bit insecure. Anything Mudlib related should be done completely serverside with copies of the information sent clientside for reading usage from systems.

Yes they can, they just lose their functionality as special variable headers ^^.

xXziroXx 07-13-2008 12:49 PM

Quote:

Originally Posted by zokemon (Post 1402666)
Yes they can, they just lose their functionality as special variable headers ^^.

Indeed, they can be.

Inverness 07-13-2008 08:21 PM

Quote:

Originally Posted by xXziroXx (Post 1402834)
Indeed, they can be.

So, don't do something just because you can.

xXziroXx 07-14-2008 12:11 AM

Quote:

Originally Posted by Inverness (Post 1402932)
So, don't do something just because you can.

I agree. :p

Vimerge 07-14-2008 01:12 AM

Heh this all seems so complicated e_e
I really wanna learn GS2, I don't know where to start..


All times are GMT +2. The time now is 10:57 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.