Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   player to player interaction (https://forums.graalonline.com/forums/showthread.php?t=134262718)

skillmaster19 04-06-2011 04:41 AM

player to player interaction
 
How would I make it so the actions of one player trigger someone elses? For example if a player fires a weapon all players within a 8x4 area of the players direction are effected.(like being hit by a sword).

Another example would be a slap item that causes the player next to the player that uses the weapon to say "owww, that hurt!" I understand there are projectile functions, but I want to know the best way to immediatly effect the players within a certain area.

0PiX0 04-06-2011 04:51 AM

I am not sure if there is an equivalent of getareanpcs( x,y,width,height ) to get players. One way to accomplish what you want is to loop through the players object. Test each player's coordinates to determine whether they are inside your rectangle.

MrOmega 04-06-2011 05:36 AM

PHP Code:

for ( temp.p = 0; temp.p < allPlayerscount; temp.p ++;)
{

//Use if to check player coords with players[ temp.p]

} 


Mark Sir Link 04-06-2011 05:41 AM

I imagine you ask for the slap example because of UN's, the way UN's works is by using a triggeraction. The other player then receives the triggeraction and handles it to change ani

cbk1994 04-06-2011 05:44 AM

Quote:

Originally Posted by MrOmega (Post 1641688)
PHP Code:

for ( temp.p = 0; temp.p < allPlayerscount; temp.p ++;)
{

//Use if to check player coords with players[ temp.p]

} 


If you're using allplayerscount, then you need to use allplayers, not players.

You should also use allplayers.size() rather than allplayerscount as it makes no sense to use the latter.

I would recommend using a foreach loop.

PHP Code:

function hitPlayers(x, y, radius) {
  for (
temp.pl : findNearestPlayers(x, y)) {
    if (
getDistance(pl.x, pl.y, x, y) < radius && pl != player) {
      
pl.chat = "I was hit!";
    }
  }
}

function 
getDistance(x1, y1, x2, y2) {
  return (((
x1 - x2) ^ 0.5) + ((y1 - y2) ^ 0.5)) ^ 2;
} 

This should work, haven't tested it though.

Deas_Voice 04-06-2011 08:45 PM

tirggeraction sounds about right

fowlplay4 04-06-2011 08:52 PM

Quote:

Originally Posted by Deas_Voice (Post 1641802)
tirggeraction sounds about right

To cover an 8x4 section of tiles. Hell no.

Best plan of action would be to...

1. Loop through the players on clientside and check if they're in the '8x4' section
2. Send the list of players in the section to the server-side
3. Double-check that they're in the square (perhaps with some leniency)
4. Triggerclient each person in the square, or even just change their animation and chat if that's all that's necessary.

It looks like this:

PHP Code:

function onActionServerSide() {
  if (
params[0] == "hitpeople") {
    
// Do the same check up here, or maybe even a radius check like cbk suggested.
    
for (temp.pl: players) {
      if (
temp.pl.x in |tx,tx+dw| && temp.pl.y in |ty,ty+dh|) {
        
temp.pl.chat = "Ow!";
        
temp.pl.setani("hurt", "");
      }
    }
  }
}

//#CLIENTSIDE
function hitPeople() {
  
// Determine the 8x4 Section
  // tx = topleft x
  // ty = topleft y
  // dw = width of section
  // dh = height of section
  // Find Players
  
for (temp.pl: players) {
    
// Check if Player is in Section
    
if (temp.pl.x in |tx,tx+dw| && temp.pl.y in |ty,ty+dh|) {
      
// Add Account to the List of those being Hit
      
temp.hitting.add(temp.pl.account);
    }
  }
  
// Check if Hitting Anyone
  
if (temp.hitting.size() > 0) {
    
// Trigger the server
    
triggerserver("gui", this.name, "hitpeople", temp.hitting);
  }
} 


Deas_Voice 04-06-2011 08:57 PM

Quote:

Originally Posted by fowlplay4 (Post 1641804)
To cover an 8x4 section of tiles. Hell no.

Best plan of action would be to...

1. Loop through the players on clientside and check if they're in the '8x4' section
2. Send the list of players in the section to the server-side
3. Double-check that they're in the square (perhaps with some leniency)
4. Triggerclient each person in the square, or even just change their animation and chat if that's all that's necessary.

ouch, didn't read too well. saw "oww, that hurts" and the word "slap".

your right, i'm sorry. :)


All times are GMT +2. The time now is 02:39 AM.

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