Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Serverside Joining of Clientside Player Functions (https://forums.graalonline.com/forums/showthread.php?t=134259499)

ffcmike 06-14-2010 02:08 AM

Serverside Joining of Clientside Player Functions
 
Joining classes to the Player Clientside is a useful feature that cuts down on replicate coding and makes important actions/data retrieving more easily accessible, however you have to use player.join("classname"); Clientside rather than whatever Clientside parts of the class script loading when joined Serverside and it seems as if your client has to retrieve the class script from the server before loading on the client, this causes a delay in the script being accessable which while possible to work around can be frustrating.

Would it be possible for Serverside player.join(""); (if not a seperate function) to also join Clientside functions to the player object, and as a result enabling these functions to be accessable as soon as the player logs in?

On a side note, it's annoying that you have to completely restart your client whenever a Clientside player class script is updated in order for it to kick in, this seems to be the case even if you unjoin and re-join the class to the player after updating.

cbk1994 06-14-2010 06:06 AM

I agree at the annoyance of restarting the client. It'd be nice if the delay was fixed as well. On Era we do:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd "requestReady") {
    
player.triggerClient("gui"this.name"clientsideReady");
  }
}
//#CLIENTSIDE
function onCreated() {
  
player.join("player");
  
player.triggerServer("gui"name"requestReady");
}

function 
onActionClientSide(cmd) {
  if (
cmd == "clientsideReady") {
    for (
temp.weapon player.weapons) {
       
weapon.trigger("playerReady"null);
    }
  }


And then any scripts that call player functions can use the event onPlayerReady instead of onCreated. Hope that helps someone with this problem.

ffcmike 06-14-2010 08:56 AM

Quote:

Originally Posted by cbk1994 (Post 1581842)
I agree at the annoyance of restarting the client. It'd be nice if the delay was fixed as well. On Era we do:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd "requestReady") {
    
player.triggerClient("gui"this.name"clientsideReady");
  }
}
//#CLIENTSIDE
function onCreated() {
  
player.join("player");
  
player.triggerServer("gui"name"requestReady");
}

function 
onActionClientSide(cmd) {
  if (
cmd == "clientsideReady") {
    for (
temp.weapon player.weapons) {
       
weapon.trigger("playerReady"null);
    }
  }


And then any scripts that call player functions can use the event onPlayerReady instead of onCreated. Hope that helps someone with this problem.

I find that some classes actually take longer to load than others (presumably down to their amount of characters), so I use an initialization class that waits until the function exists.

cbk1994 06-14-2010 09:46 AM

Quote:

Originally Posted by ffcmike (Post 1581869)
I find that some classes actually take longer to load than others (presumably down to their amount of characters), so I use an initialization class that waits until the function exists.

Probably not a bad idea. Something like

PHP Code:

while (! ("myfunction" in player.getFunctions())) {
  
sleep(0.05);


?

ffcmike 06-14-2010 09:02 PM

Quote:

Originally Posted by cbk1994 (Post 1581871)
Probably not a bad idea. Something like

PHP Code:

while (! ("myfunction" in player.getFunctions())) {
  
sleep(0.05);


?

More like:

Weapon/NPC -

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
this.onAttemptInitialize();
}

function 
canInitialize(){
  return 
player.hasFunction("myFunction");
}

function 
initialize(){
  
player.myFunction();


Class -
PHP Code:

//#CLIENTSIDE
function onAttemptInitialize(){
  if(
this.canInitialize()){
    
this.initialize();
  }
  else{
    
this.scheduleEvent(0.05"AttemptInitialize"NULL);
  }



ffcmike 05-14-2011 08:24 AM

Bump.

fowlplay4 05-14-2011 03:17 PM

What about...

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
loadclass("player");
  
player.join("player");


Don't know if it's async or not though. If it is I guess it won't really help much.

cbk1994 05-14-2011 03:51 PM

Quote:

Originally Posted by fowlplay4 (Post 1649662)
What about...

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
loadclass("player");
  
player.join("player");


Don't know if it's async or not though. If it is I guess it won't really help much.

Tested it, didn't work :(.

Admins 05-16-2011 12:16 AM

Eventually use onClassDownloaded(classname), or after joining you call a function, which will automatically wait until the classes are downloaded and then call the function.

ffcmike 05-16-2011 01:01 AM

Quote:

Originally Posted by Stefan (Post 1649998)
or after joining you call a function, which will automatically wait until the classes are downloaded and then call the function.

Would this not still cause "function myFunction not found in script of npc" when logging into a level containing clientside NPCs that use a player function?

fowlplay4 05-16-2011 01:20 AM

This seemed to work for me:

wNPC A:

PHP Code:

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

//#CLIENTSIDE

function onCreated() {
  
this.leave("test"); // Not really necessary, just prevents function overwriting issues.
  
player.join("test");


wNPC B:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
player.hello();


Class: test

PHP Code:

//#CLIENTSIDE
public function hello() {
  
player.chat "world.";


Looks like it also resolves the 'have to restart client to update' issue as well. Just make sure A loads first, which should be as easy as placing it first in weaponsorder in server options.

ffcmike 05-16-2011 01:38 AM

Quote:

Originally Posted by fowlplay4 (Post 1650007)
This seemed to work for me:

wNPC A:

PHP Code:

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

//#CLIENTSIDE

function onCreated() {
  
this.leave("test"); // Not really necessary.
  
player.join("test");


wNPC B:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
player.hello();


Class: test

PHP Code:

//#CLIENTSIDE
public function hello() {
  
player.chat "world.";


Looks like it also resolves the 'have to restart client to update' issue as well. Just make sure A loads first, which should be as easy as placing it first in weaponsorder in server options.

Funnily enough before deciding to test this I tested the normal situation of logging in having restarted the client while containing a player.function clientside within weapon + NPC scripts onCreated, and the function happened to work each time, so I think this is only really a problem when lag is involved.

fowlplay4 05-16-2011 02:51 AM

Quote:

Originally Posted by ffcmike (Post 1650009)
Funnily enough before deciding to test this I tested the normal situation of logging in having restarted the client while containing a player.function clientside within weapon + NPC scripts onCreated, and the function happened to work each time, so I think this is only really a problem when lag is involved.

Joining it to a weapon should force it to pre-load on the client-side though, no?

ffcmike 05-16-2011 02:56 AM

Quote:

Originally Posted by fowlplay4 (Post 1650021)
Joining it to a weapon should force it to pre-load on the client-side though, no?

I'm not so sure this is the case with player objects, I have a class which is handling level types (nopk, quest, pk, spar etc) which is joined to players and a clientside wall checking script within a weapon, the problem can still occur when using these functions.

Admins 05-16-2011 03:22 AM

What he means is that you do one weapon which is using all needed classes, since it's preloading the classes for weapons.


All times are GMT +2. The time now is 06:52 PM.

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