Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-11-2010, 11:28 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Post player.join and triggeraction?

I am curious as to how I would use a triggeraction to trigger an action in a joined class? Or is this not possible?

Class:
PHP Code:
//#CLIENTSIDE
public function onActionHurt(acct) {
  
player.hearts -= 0.5;
  
player.chat "hurt by" SPC acct;
  
setani"human2_hurt"NULL);

Weapon:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
player.join("hurt");
}
function 
onKeyPressed() {
  
ar = {player.+ (vecx(player.dir) * 2) + 1.5player.+ (vecy(player.dir) * 2) + 1.8};
  
triggeractionar[0], ar[1], "Hurt"player.account);

I have 2 accounts logged in. But only 1 account can hit the other. Is there any reason for this?
Reply With Quote
  #2  
Old 02-11-2010, 12:36 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by scriptless View Post
I am curious as to how I would use a triggeraction to trigger an action in a joined class? Or is this not possible?

Class:
PHP Code:
//#CLIENTSIDE
public function onActionHurt(acct) {
  
player.hearts -= 0.5;
  
player.chat "hurt by" SPC acct;
  
setani"human2_hurt"NULL);

Weapon:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
player.join("hurt");
}
function 
onKeyPressed() {
  
ar = {player.+ (vecx(player.dir) * 2) + 1.5player.+ (vecy(player.dir) * 2) + 1.8};
  
triggeractionar[0], ar[1], "Hurt"player.account);

I have 2 accounts logged in. But only 1 account can hit the other. Is there any reason for this?
While triggeraction can be used to trigger directly to the clients of players at a given coordinate I don't believe this is possible no, I believe they have to be recieved within weapons.
I'd suggest moving the "onActionHurt" into a weapon, but then simply calling a player.injured() or whatever in it's place within the class once recieved.
Reply With Quote
  #3  
Old 02-11-2010, 01:53 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
It is usually best to do the entire thing serverside


PHP Code:
function attack(dxdy) {
  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |player.xplayer.3| && dy in |player.yplayer.3|)) {
      continue;
    }
    
    if (
pl == player) { // if it's the attacking player, skip
      
continue;
    }
    
    
pl.hit(0.5player);
  }

then in the player class,

PHP Code:
public function hit(damagepl) {
  
this.hearts -= damage;
  
this.chat "Hurt by: " pl.account;
  
this.setAni("human2_hurt"null);


However, if you choose to do it clientside, you will need a weapon to intercept the trigger. Once you intercept it clientside in a weapon, you will need to trigger serverside again in that weapon then call the player function as player.hearts can't be modified clientside.
__________________
Reply With Quote
  #4  
Old 02-11-2010, 02:17 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by cbk1994 View Post
It is usually best to do the entire thing serverside


PHP Code:
function attack(dxdy) {
  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |player.xplayer.3| && dy in |player.yplayer.3|)) {
      continue;
    }
    
    if (
pl == player) { // if it's the attacking player, skip
      
continue;
    }
    
    
pl.hit(0.5player);
  }

then in the player class,

PHP Code:
public function hit(damagepl) {
  
this.hearts -= damage;
  
this.chat "Hurt by: " pl.account;
  
this.setAni("human2_hurt"null);


However, if you choose to do it clientside, you will need a weapon to intercept the trigger. Once you intercept it clientside in a weapon, you will need to trigger serverside again in that weapon then call the player function as player.hearts can't be modified clientside.
I think this is intended to be a Clientside Hit Detection, using the triggeraction method would only result in the function occuring if your player is positioned on the given coordinate at the time of the trigger being recieved on your own client.

I think the hearts variable can -falsely- be modified Clientside albeit for the illusion of no delay, which should be done along side the setting of the Gani, but yes hearts should definately be modified serverside either way.
(Edit: having tested it seemed hearts had saved having set a new value Clientside and reconnected)
Reply With Quote
  #5  
Old 02-11-2010, 05:14 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I join a damage class script to the weapon (not the player), and just make sure both players have the weapon, then it works fine.
__________________
Quote:
Reply With Quote
  #6  
Old 02-11-2010, 10:20 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Revised. Still not working.

PHP Code:
function punch(dxdy) {
  
player.chat "2";
  if ( 
player.ani != "human2_swim" ) {
    if ( 
player.ani != "human2_hthc_punch" setani"human2_hthc_punch"null);
    
freezeplayer(.5);

  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |player.xplayer.3| && dy in |player.yplayer.3|)) {
      continue;
    }
    if (
pl == player) continue;
    
pl.hit(0.5player);
  }

    
waitforGraalControl"punch".5);
    if ( 
this.keyb_d == true ) {
      
setani"human2_shield_hold"null );
      
onshield();
    } else  
setani"human2_idle" null );
  }
}

function 
onCreated() {
  
disableweapons();
  
addtiledef("picso2.png","psi_"0);
  
enablefeaturesallfeatures ---0x10 -0x20 );
  
showstats(256 512 1024);
  
  
// allow ourselves to hurt :o
  
player.join("hurt");
}

//#CLIENTSIDE
function GraalControl.onKeyDown(keycodekeychar) {
  
this.("keyb_" keychar) = true;
  switch( 
keychar ) {
    case 
"s":
      
player.chat "1";
      
punch(player.xplayer.y);
    break;
    case 
"d":
      
setani"human2_shield_hold"null );
      
this.playerdir player.dir;
      
onshield();
    break;
  }
  if ( 
keycode == ) {
    
this.keyb_d false;
    
setani"human2_idle"null );
    
shield();
  }

Reply With Quote
  #7  
Old 02-12-2010, 12:21 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
Revised. Still not working.
You can't call serverside functions like punch() directly. Instead you have to trigger serverside using the function triggerserver, like so:

PHP Code:
// this is the event invoked serverside by triggerserver
function onActionServerSide(cmd) {
  if (
cmd == "punch") {
    
punch(player.xplayer.y);
  }
}

function 
punch(dxdy) {
  
player.chat "2";
  if ( 
player.ani != "human2_swim" ) {
    if ( 
player.ani != "human2_hthc_punch" setani"human2_hthc_punch"null);
    
freezeplayer(.5);

  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |player.xplayer.3| && dy in |player.yplayer.3|)) {
      continue;
    }
    if (
pl == player) {
      continue;
    }
    
    
pl.hit(0.5player);
  }

   
// I'm not sure what this is supposed to do?
   /* waitfor( GraalControl, "punch", .5);
    if ( this.keyb_d == true ) {
      setani( "human2_shield_hold", null );
      onshield();
    } else  setani( "human2_idle" , null );
  }*/
}

// normally it is best to use the onActionPlayerOnline even evoked in
// Control-NPC since onPlayerLogin() isn't called for each player
// if the NPC-server restarts, which causes problems since
// classes don't join
function onPlayerLogin(pl) { // onCreated is only called when the script is updated
  // allow ourselves to hurt :o
  
pl.join("hurt");
}

//#CLIENTSIDE
function onCreated() {
  
// all of this has to be done clientside
  
disableweapons();
  
addtiledef("picso2.png","psi_"0);
  
enablefeaturesallfeatures ---0x10 -0x20 );
  
showstats(256 512 1024);
}
function 
GraalControl.onKeyDown(keycodekeychar) {
  
this.("keyb_" keychar) = true;
  switch( 
keychar ) {
    case 
"s":
      
player.chat "1";
      
triggerServer("gui"this.name"punch"); // tell serverside to punch
    
break;
    case 
"d":
      
setani"human2_shield_hold"null );
      
this.playerdir player.dir;
      
onshield();
    break;
  }
  if ( 
keycode == ) {
    
this.keyb_d false;
    
setani"human2_idle"null );
    
shield();
  }

A brief explanation of clientside and serverside:

Clientside is code that is ran directly on the players computer. This allows you to create effects, show images for only that player (including things like health interfaces), do things when the player presses a key, etc. The benefit to clientside code is that there is no delay between when the player tries to do something and when it happens. For example, if you had a clientside punching system, they would immediately see the punch. The disadvantage to clientside code is that it is run on the player's computer, and therefore it can be modified to some degree. It is very easy to disable onwall checks in a clientside movement system, for example. Because clientside code is local, it can't communicate with other players.

Serverside is code that is ran on the NPC-server. This allows you to create solid systems that can interact with every player. An example of serverside code would be a "monster" like on GK which runs serverside and sends back the updates such as position, GANI, and so on, where it is displayed clientside. The advantage to serverside scripting is that it is secure and can't be tampered with by any player. You can also communicate with other players. The disadvantage is that there is a "lag" time between when the user does something and when it happens, depending on the player's internet connection.


To communicate between the two you have to use things called triggers. There's a pretty good explanation of those in this thread.
__________________
Reply With Quote
  #8  
Old 02-12-2010, 12:48 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Thank you ckb. And the part you didnt understand was just some checks. Basically im using a system to check if a key is pressed or not. "this.keyb_" then the keychar. because tab+key seems to break alot of scripts under windows (not on linux from what i experienced).

Problem I am having now is you do not even have ot be remotly close to players to hit them.. and my sword seems to popoyt when i swing now. this did not happen before tho =/

Also, freezeplayer() no longer works. Possible because its being used serverside.

Quote:
Script: Function freezeplayer not found at line 11 in script of -System (in level onlinestartlocal.graal at pos (0, 0))
Or at least according to the link u provided. So I can fix that, however the player hitting from across the server is a problem I need help fixing lol

Last edited by scriptless; 02-12-2010 at 01:06 AM..
Reply With Quote
  #9  
Old 02-12-2010, 02:56 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Little note about onCreated() on the server-side in weapon scripts, it is called when the server starts up too, not just when it's updated.
__________________
Quote:
Reply With Quote
  #10  
Old 02-12-2010, 03:20 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
How inaccurate is it? Right not it's just using the player's x and y instead of the attack x/y, but if it's like a 10 tile difference, that's obviously not it.
__________________
Reply With Quote
  #11  
Old 02-12-2010, 03:35 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
i dont think its checking x/y at all. I mean were talking 64 tile difference in this level :o

No further need to reply.. i have fired myself from all development servers (except testbed) and devborn2kill.. didnt have rights to fully remove all my rights (ironic i know)

Last edited by scriptless; 02-12-2010 at 03:46 AM..
Reply With Quote
  #12  
Old 02-12-2010, 04:11 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Well, in case anybody was wondering, the problem was this line:

PHP Code:
if (! (dx in |player.xplayer.3| && dy in |player.yplayer.3|)) { 
It should have read:

PHP Code:
if (! (dx in |pl.xpl.3| && dy in |pl.ypl.3|)) { 
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:47 PM.


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