Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   function similar to move() (https://forums.graalonline.com/forums/showthread.php?t=134266765)

Alpho 07-04-2012 02:54 AM

function similar to move()
 
Hey all, i'm wondering if there's a function that behaves similar to move(), but it's used for guicontrol images. I want to move an image from point a to point b.

Thanks, Alpho.

DeCeaseD 07-04-2012 03:07 AM

Quote:

Originally Posted by Alpho (Post 1698906)
Hey all, i'm wondering if there's a function that behaves similar to move(), but it's used for guicontrol images. I want to move an image from point a to point b.

Thanks, Alpho.

Couldn't you just alter the x/y of the GUIcontrol in a timeout loop? Or am I misunderstanding what you're trying to achieve?

DustyPorViva 07-04-2012 03:13 AM

As far as I know Stefan did add something like this in the more recent v6 releases. I don't know where to search though.

DeCeaseD 07-04-2012 03:15 AM

Quote:

Originally Posted by DustyPorViva (Post 1698910)
As far as I know Stefan did add something like this in the more recent v6 releases. I don't know where to search though.

It's something to do with GuiControl.createAnimation().. not exactly sure what the parameters are though. Or at least I think? lol

cbk1994 07-04-2012 04:05 AM

Quote:

Originally Posted by DeCeaseD (Post 1698911)
It's something to do with GuiControl.createAnimation().. not exactly sure what the parameters are though. Or at least I think? lol

See:

Quote:

Originally Posted by cbk1994 (Post 1663377)
For the animations,

PHP Code:

temp.animation this.createAnimation();
temp.animation.duration 1;
temp.animation.transition "moveoutleft"

Mostly for iPhone stuff, but it also works on v6 clients. It lets you easily fade in/out or move in/out GUI objects.

As far as I know, it's not possible to tween the position to arbitrary values. Look at something like this instead.

Tigairius 07-04-2012 08:23 AM

or you could edit the (much simpler) variable tweening that I suggested a while back. Join your GUI object to the class, and use tween on "x" or "y" instead of "alpha".

Alpho 07-04-2012 08:11 PM

Thank you everybody for the input! In the end, I went with Tigairius's variable tweening.

Quote:

Originally Posted by Tigairius (Post 1698923)
or you could edit the (much simpler) variable tweening that I suggested a while back. Join your GUI object to the class, and use tween on "x" or "y" instead of "alpha".

Tig, I got your example to work perfectly when I put the class clientsided. Though I can't get it to work with my gui controls. Any ideas?

Tigairius 07-04-2012 09:31 PM

Quote:

Originally Posted by Alpho (Post 1698953)
Thank you everybody for the input! In the end, I went with Tigairius's variable tweening.



Tig, I got your example to work perfectly when I put the class clientsided. Though I can't get it to work with my gui controls. Any ideas?

Sure, just post the portion of the script that you're trying to get to work and we'll get it working.

Alpho 07-04-2012 09:43 PM

PHP Code:

  with (HBUI_Point0) {
    
join("plugin_tween");
    
tween("x"1xx+50);
  } 

That's called upon clicking a gui button.

HBUI_Point0 is a GuiShowImgCtrl.

DustyPorViva 07-04-2012 10:06 PM

I don't think you need to join it to the specific object(in this case the control), but just to the script itself.

Alpho 07-04-2012 10:07 PM

Quote:

Originally Posted by DustyPorViva (Post 1698963)
I don't think you need to join it to the specific object(in this case the control), but just to the script itself.

Even just joining the script it's self to the class won't work for me. Thanks though.

Tigairius 07-04-2012 10:11 PM

Quote:

Originally Posted by Alpho (Post 1698960)
PHP Code:

  with (HBUI_Point0) {
    
join("plugin_tween");
    
tween("x"1xx+50);
  } 

That's called upon clicking a gui button.

HBUI_Point0 is a GuiShowImgCtrl.

Something like this should work:
PHP Code:

new GuiShowImgCtrl("HBUI_Point0") {
  
profile GuiDefaultProfile;
  
image "block.png";
  
height 32;
  
width 32;
  
300;
  
300;
  
this.join("plugin_tween");
}
...
HBUI_Point0.tween("x"1HBUI_Point0.xHBUI_Point0.50); 

The only thing is that you'll have to edit the class so that tween() is a public function so that it can be accessed by the object. Here it is:
PHP Code:

//#CLIENTSIDE
public function tween(valuetimeoldvalnewval) {
  
temp.dist newval oldval;
  
temp.step temp.dist time 0.05;
  
this.( @ value) = oldval;
  
this.trigger("TweenValue"valuetemp.stepnewval);
}

function 
onTweenValue(valuestepnewval) {
  
cancelEvents("TweenValue");
  if (
this.(@ value) == newval) return this.trigger("TweenFinished"value);
  
this.( @ value) += step;
  
scheduleEvent(0.05"TweenValue"valuestepnewval);



cbk1994 07-04-2012 10:11 PM

Quote:

Originally Posted by DustyPorViva (Post 1698963)
I don't think you need to join it to the specific object(in this case the control), but just to the script itself.

With Tig's, yeah, you do. Not the best way to do it in my opinion, clientside class joining on Graal is very touchy. Plus it can introduce issues with the class not being available immediately.

Tigairius 07-04-2012 10:16 PM

Quote:

Originally Posted by cbk1994 (Post 1698966)
With Tig's, yeah, you do. Not the best way to do it in my opinion, clientside class joining on Graal is very touchy. Plus it can introduce issues with the class not being available immediately.

It works fine, and the class is available immediately. The only time I have problems is when I join a class to an object that's already been created, but in my example, it's being joined upon creation.

Alpho 07-04-2012 10:21 PM

Works perfectly Tig, Thank you so much.

cbk1994 07-04-2012 11:03 PM

Quote:

Originally Posted by Tigairius (Post 1698967)
It works fine, and the class is available immediately. The only time I have problems is when I join a class to an object that's already been created, but in my example, it's being joined upon creation.

Joining classes on clientside requires a round-trip to the server; it's not immediately available, although you can use it immediately (in v6). For example:

Class "test":
PHP Code:

//#CLIENTSIDE
public function test() {
  return 
"it works!";


Weapon "test":
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.start timevar2;
  
  
temp.obj = new TStaticVar();
  
temp.obj.join("test");
  echo(
"result: " temp.obj.test());
  
  echo(
"total time: " @ (timevar2 temp.start));


On a low-latency network, the delay is generally tolerable:
Quote:

result: it works!
total time: 0.108752069
On an (artificially) high-latency network, however, it becomes a real problem:

Quote:

result: it works!
total time: 0.901618003
This can be very problematic depending on the situation: the best case is that nothing happens for a second, the worst is that the player's left with a half-drawn interface on the screen while the class is fetched.

And even worse, on v5:

Quote:

result: 0
total time: 0.000670057
v5 doesn't even wait for the class -- and 32% of Era is still using v5 right now.

An easy fix is to join the class serverside before joining it to any objects clientside:

PHP Code:

function onCreated() {
  
this.join("test");
}

//#CLIENTSIDE
function onCreated() {
  
temp.start timevar2;
  
  
temp.obj = new TStaticVar();
  
temp.obj.join("test");
  echo(
"result: " temp.obj.test());
  
  echo(
"total time: " @ (timevar2 temp.start));


Now your clientside class works on v5 and v6, and without waiting for the network :).

xXziroXx 07-04-2012 11:11 PM

I share Chris' experience with loading classes on clientside, and even had to write a work around for it:

PHP Code:

//#CLIENTSIDE
function onCreated()
{
//echo("Classes:" SPC player.joinedclasses);
//return;
  
temp.classList = {
    
"functions_buffs",
    
"functions_items",
    
"functions_messages",
    
"functions_misc",
    
"functions_stats",
    
"functions_skills",
    
"gui_initializer",
    
"gui_basics",
    
"gui_buff",
    
"gui_item",
    
"gui_skill",
    
"gui_spell",
    
"player_system",
    
//"quest_npc"
  
};
  
  for (
temp.classNametemp.classList) {
    
// Load the class to the player
    
if (!player.isInClass(temp.className))
      
player.join(temp.className);
    
    
// Maybe the class is loaded already?
    
if (isClassLoaded(temp.className))
      continue;
    
    
loadClass(temp.className);
    
    while (!
isClassLoaded(temp.className))
      
sleep(0.05);
  }
  
  
triggerServer("gui"this.name"initialized");


Causes a 1-5 second delay in our "login level" depending on your latency when you first login during the session, but it's worth not getting any errors because of classes not having loaded yet.


All times are GMT +2. The time now is 08:10 PM.

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