Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Npc |Server - Clientside| Communication (https://forums.graalonline.com/forums/showthread.php?t=134260535)

Deathborn123 09-14-2010 01:39 AM

Npc |Server - Clientside| Communication
 
Hey guys!

I'm just making a baddysystem. So I'm wondering how you communicate between Clientside and Serverside in an npc class. To make a bit more understandable:

Baddy Class ( if the baddy gets hit)
PHP Code:

function onActionhurt()
{
if (
this.npchp params[0])
{
this.npchp -= params[0];
this.chat this.npchp;
}
else
{
this.npchp this.npchpmax;
this.chat this.npchp;
"-xpcalculator".Actionxp(this.npclevel);
}


Aight, so basicly what im doin is, whenever the baddy dies, it calls the public function "Actionxp" of the weapon "-xpcalculator". So everything works fine, if the baddy class is //#CLIENTSIDE. The problem is i dont want my baddies clientside, so my aim is to remove the //#CLIENTSIDE but if i do it he cant find the public function "Actionxp" anymore. Hope you got me and hope you got any resolutions for that

So far...

cbk1994 09-14-2010 01:49 AM

Move the "Actionxp" function to the serverside portion of the -xpcalculator script. You should be doing things like that on serverside anyway.

fowlplay4 09-14-2010 01:57 AM

When you're developing an EXP system you should have all those functions in a player-joined class. Here have some bare-bones for one.

class: playerfunctions
PHP Code:

public function getEXP() {
  return 
clientr.stat.exp;
}

public function 
getLevel() {
  return 
clientr.stat.level;
}

public function 
addEXP(amount) {
  
clientr.stat.exp += amount;
  
checkEXP();
}

public function 
setEXP(amount) {
  
clientr.stat.exp amount;
}

public function 
checkEXP() {
  if (
getEXP() > EXPRequired()) {
    
levelUP();
  }
}

public function 
getEXPRequired() {
  
// Add a custom formula here.
  
return 10000;
}

public function 
levelUP() {
  
setEXP(0);
  
clientr.stat.level++;
  
clientr.stat.expneeded getEXPRequired();


then in your Control-NPC:

PHP Code:

function onActionPlayerOnline() {
  
player.join("playerfunctions");


then in other scripts when you know the attacker or what not

PHP Code:

function onBaddyKilled(killedby) {
  
findplayer(killedby).addEXP(100);



Deathborn123 09-14-2010 02:00 AM

aight i see, simple as that.

Thanks =)

Deathborn123 09-14-2010 09:05 AM

Okay, yet another problem:

I surfed about 1hour in the forums now, but still can't find any good resolution. So for my baddyclass script i need Serverside > Clientside communication ( local npcs that joins baddyclass) . I found out that you can use attr[] , tried it but it seems i can only set them once and then cant change them anymore...
then i read that triggerAction would work from Serverside to Clientside aswell , well i tried it and nope unfortunately it doesnt seem to work.
At this point i just doubled everything like what i wrote clientside i wrote serverside aswell so it works in both purposes but this cant obviously be the best solution for it.

Hope you got any good ideas

MrOmega 09-14-2010 11:46 AM

Look up Inverns Clientside <-> Serverside thread in the code gallery, should be helpful, but what your could do, is if you start client side in a class use triggerserver(); to a weapon, then trigger down to the client (triggerclient();) in that weapon then call the function from the class. Or vice versa if starting serverside

cbk1994 09-14-2010 01:02 PM

What do you need to do on the client in your baddy script? Chances are it can be done better on the server.

Deathborn123 09-15-2010 04:19 PM

Yea the Problem is i need things like The hitdetection for the npc clientside aswell as dead animation and stuff

cbk1994 09-15-2010 11:01 PM

Quote:

Originally Posted by Deathborn123 (Post 1600912)
Yea the Problem is i need things like The hitdetection for the npc clientside aswell as dead animation and stuff

Why?

Deathborn123 09-16-2010 10:29 PM

How would you do an ani Serverside? And the hitdetection though, im doin it via triggeraction and as you will know, it'll bug out if more than one levelnpc is in the level.

thats why i'm doin it clientside, if you have any other suggestions your welcome

fowlplay4 09-16-2010 11:12 PM

All the same commands (setcharani) and the triggeraction will hit both the client-side and server-side functions provided there's a set shape or character for it to hit.

Deathborn123 09-17-2010 04:05 PM

Triggeraction wont work cause im triggering via this.x and this.y which wont work if the baddy is walking :o

Deathborn123 09-17-2010 05:57 PM

aight. so i just made everything work Clientside now. Its all fine except i thought i could easily just use an public image id (<200) and then everything would be perfect; every player would see the same healthstatus of the baddy but unfortunately im wrong :/

any help?

cbk1994 09-18-2010 12:50 AM

Maybe try something like this.


Quote:

Originally Posted by cbk1994 (Post 1574971)
You can also do

PHP Code:

function onCreated() {
  
this.level.tapThis this;
}

function 
onPow() {
  
this.chat "ouch!";
}

//#CLIENTSIDE
function onPlayerChats() {
  
triggerServer("npc""TriggerControl""Trigger"this.level.name"tapThis""Pow");


and then in an NPC TriggerControl

PHP Code:

function onActionTrigger(levelNamenpcNamecommand) {
  
findLevel(levelName).(@ npcName).trigger(command);


Though you'd want to add some security features. Usually something like this is preferable since you never know if a trigger will be received when using x/y.



All times are GMT +2. The time now is 11:37 PM.

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