Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   this.alpha and showpoly (https://forums.graalonline.com/forums/showthread.php?t=134257919)

Engine 02-06-2010 07:19 PM

this.alpha and showpoly
 
I cannot figure out how to change the alpha on polygons, could anyone help me? I want to use polygons with the particle engine to mess around but I can't seem to figure it out.
PHP Code:

function ShowPolyTest(){
  
showpoly(200,{22,22,22,25,25,25,25,22});
  
this.alpha 0.5;
  
with(findimg(200)){
      
this.alpha 0.5;
  }



Immolate 02-06-2010 07:28 PM

Quote:

Originally Posted by Engine (Post 1554603)
I cannot figure out how to change the alpha on polygons, could anyone help me? I want to use polygons with the particle engine to mess around but I can't seem to figure it out.
PHP Code:

function ShowPolyTest(){
  
showpoly(200,{22,22,22,25,25,25,25,22});
  
this.alpha 0.5;
  
with(findimg(200)){
      
this.alpha 0.5;
  }



PHP Code:

function ShowPolyTest(){
  
temp.polygonObj showpoly(200,{22,22,22,25,25,25,25,22});
  
temp.polygonObj.mode 1;
  
temp.polygonObj.alpha 0.5;


As I PMed you on Testbed, this seems to do the trick, if that's the effect you're looking for.

Engine 02-06-2010 07:33 PM

Oh, thanks I didn't see your pm.

Engine 02-06-2010 08:24 PM

I have another problem with showpoly, I figuired I might as well put it in here instead of making a new thread.
PHP Code:

function blahblah(){
  
polytest showpoly(200,{blah,blah,blah,ect});
}
function 
ifthishappens(){
  
polytest.mode 1;//works
  
polytest.red 0.5;//works
  
polytest.blue polytest.green 0//works
  
polytest.player.x//doesnt work
  
polytest.player.y//doesnt work


Is there a reason why this wont work?

Immolate 02-06-2010 08:26 PM

Quote:

Originally Posted by Engine (Post 1554628)
I have another problem with showpoly, I figuired I might as well put it in here instead of making a new thread.
PHP Code:

function blahblah(){
  
polytest showpoly(200,{blah,blah,blah,ect});
}
function 
ifthishappens(){
  
polytest.mode 1;//works
  
polytest.red 0.5;//works
  
polytest.blue polytest.green 0//works
  
polytest.player.x//doesnt work
  
polytest.player.y//doesnt work


Is there a reason why this wont work?

Well, I think it's because polygons have multiple coordinates, but I'm not sure. To make it equal to the player's coordinates, you'd just draw every point on the polygon relative to them. For example:

PHP Code:

showpoly200, { player.xplayer.yplayer.5player.} ); 

This would draw a straight horizontal line relative to the player's position.

It's also probably a better idea to use a this. variable instead of a global variable.

Engine 02-06-2010 08:31 PM

Well, what i'm trying to do is make a hit box and then make it so I can widen it with a slider and anything in the hit box will set this.chat to it's npcs[i].id. I'm just messing around and this really has no purpose, I'm just trying to learn.

Edit: So there isn't a way to change the entire showpoly's x/y with this.polytest.x?

Immolate 02-06-2010 08:37 PM

Quote:

Originally Posted by Engine (Post 1554630)
Well, what i'm trying to do is make a hit box and then make it so I can widen it with a slider and anything in the hit box will set this.chat to it's npcs[i].id. I'm just messing around and this really has no purpose, I'm just trying to learn.

Edit: So there isn't a way to change the entire showpoly's x/y with this.polytest.x?

I don't think so. Probably best just to have your own variables that you can edit which acts as the base position.

Engine 02-06-2010 08:40 PM

Would I have to put the showpoly in a timeout to have it so it checks for updates constantly?

Immolate 02-06-2010 08:44 PM

Quote:

Originally Posted by Engine (Post 1554633)
Would I have to put the showpoly in a timeout to have it so it checks for updates constantly?

Yeah, but only check if the variables change. If they do, call a function to update the polygon's position. Don't repeatedly redraw the polygon.

It'd be great if we could bind an event to certain variables that is triggered when the variable changes.

Engine 02-06-2010 08:52 PM

Alrighty, thanks a lot I finally figured it out. I'm glad you told me just to check it when it updates otherwise I would have had it looping every 0.1 seconds haha.

Engine 02-06-2010 09:40 PM

Alright, this might as well be renamed to my help thread
Can I do this clientside because it's not working for me clientside and I seem to remember reading that you can seartch through all the players x/y clientside?
PHP Code:

  for (plallplayers) {
    
pl.chat "test";
    if (
pl.x in HBx 1.5HBy 1.5 | && pl.y in HBx 1.5HBy 1.5 | ) {
      
pl.chat "hit.";
    }
  } 


cbk1994 02-06-2010 09:58 PM

Polygon alpha has always been really sketchy. Sometimes it doesn't even work in v5, but it is fixed in v6.

Grey 02-06-2010 10:03 PM

Quote:

Originally Posted by Engine (Post 1554647)
Alright, this might as well be renamed to my help thread
Can I do this clientside because it's not working for me clientside and I seem to remember reading that you can seartch through all the players x/y clientside?
PHP Code:

  for (plallplayers) {
    
pl.chat "test";
    if (
pl.x in HBx 1.5HBy 1.5 | && pl.y in HBx 1.5HBy 1.5 | ) {
      
pl.chat "hit.";
    }
  } 


I think your problem is that you're checking the player x and player y against both an x and y value.

PHP Code:

if (pl.x in HBx 1.5HBx 1.5 | && pl.y in HBy 1.5HBy 1.5 | ) { 

But also, if you need to player actions serverside you can use FindPlayer(), for example finding a player's x would be done via

PHP Code:

FindPlayer(pl).

And finally, allplayers I believe is all players on the server and players is all players in the current level (not sure what you're trying to do but players might be a better option)

Immolate 02-06-2010 10:06 PM

Quote:

Originally Posted by Engine (Post 1554647)
Alright, this might as well be renamed to my help thread
Can I do this clientside because it's not working for me clientside and I seem to remember reading that you can seartch through all the players x/y clientside?
PHP Code:

  for (plallplayers) {
    
pl.chat "test";
    if (
pl.x in HBx 1.5HBy 1.5 | && pl.y in HBx 1.5HBy 1.5 | ) {
      
pl.chat "hit.";
    }
  } 


Use 'players' instead of 'allplayers'. That might work for you. The if statement seems correct, though it might be useful to provide how you're setting HBx and HBy.

Engine 02-06-2010 10:12 PM

The center x/y of the polygon.

Engine 02-06-2010 11:57 PM

And yet another problem, I cannot seem to get this to work. I have tried multiple variations of it but nothing I could conjure up in my head seems to work. Could someone point me in the right direction.
PHP Code:

function onActionServerSide(){
  for(
pl:allplayers){
    if (
players[pl.id].x in player.-5player.| && players[pl.id].y in player.y-5player.+| ) {     
      
findplayer(pl).chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"nameNULL);
  }



Immolate 02-07-2010 12:04 AM

Quote:

Originally Posted by Engine (Post 1554676)
And yet another problem, I cannot seem to get this to work. I have tried multiple variations of it but nothing I could conjure up in my head seems to work. Could someone point me in the right direction.
PHP Code:

function onActionServerSide(){
  for(
pl:allplayers){
    if (
players[pl.id].x in player.-5player.| && players[pl.id].y in player.y-5player.+| ) {     
      
findplayer(pl).chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"nameNULL);
  }



You could, instead of 'players[pl.id]', just use 'pl', since it's just a reference of the player object anyway.

DustyPorViva 02-07-2010 12:04 AM

You need to pass the player data serverside. On the serverside your player is not the only player object, thus you need to give the script scope.

PHP Code:

function onActionServerSide(){
  for(
temp.p:allplayers){
    
temp.pl findplayer(p);
    
temp.mypl findplayer(params[0]);
    if (
pl.x in mypl.-5mypl.| && pl.y in mypl.y-5,mypl.+| ) {     
      
pl.chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"name,player.account);
  }


Also, you can instead on the clientside use findnearestplayers(x,y), loop through, find the players you wish to send the chat and send the array to the serverside, instead of letting the server handle the loop.

Immolate 02-07-2010 12:07 AM

Quote:

Originally Posted by DustyPorViva (Post 1554678)
You need to pass the player data serverside. On the serverside your player is not the only player object, thus you need to give the script scope.

PHP Code:

function onActionServerSide(){
  for(
temp.p:allplayers){
    
temp.pl findplayer(p);
    
temp.mypl findplayer(params[0]);
    if (
pl.x in mypl.-5mypl.| && pl.y in mypl.y-5,mypl.+| ) {     
      
pl.chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"name,player.account);
  }



Using the player object has mostly worked for me serverside when using triggerserver, since I think it still keeps the player who triggered serverside in scope. Could be completely wrong though and it's probably a good idea to get into the habit of not assuming the player obect is always in scope.

cbk1994 02-07-2010 12:17 AM

Quote:

Originally Posted by Engine (Post 1554676)
And yet another problem, I cannot seem to get this to work. I have tried multiple variations of it but nothing I could conjure up in my head seems to work. Could someone point me in the right direction.
PHP Code:

function onActionServerSide(){
  for(
pl:allplayers){
    if (
players[pl.id].x in player.-5player.| && players[pl.id].y in player.y-5player.+| ) {     
      
findplayer(pl).chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"nameNULL);
  }



Try this:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd == "hitPlayers") {
    
// before you were using 'allplayers' which is an array of every player on the server
    // 'players' is an array of every player in the current level
    // 'findNearestPlayer(x, y)' just returns every player within a level or so of the x/y given. It's a lot more efficient when used on GMAPs.
    
for (temp.pl findNearestPlayers(player.xplayer.y)) {
      if (
pl.x in |player.5player.5| && pl.y in |player.5player.5|) {
        
pl.chat "oww!!!";
        
player.chat "I hit " pl.communityname "!";
      }
    }
  }
}
//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    
triggerserver("gui"this.name"hitPlayers"); // it is customary to always send a command for verification purposes
  
}


Quote:

Originally Posted by DustyPorViva (Post 1554678)
You need to pass the player data serverside. On the serverside your player is not the only player object, thus you need to give the script scope.

PHP Code:

function onActionServerSide(){
  for(
temp.p:allplayers){
    
temp.pl findplayer(p);
    
temp.mypl findplayer(params[0]);
    if (
pl.x in mypl.-5mypl.| && pl.y in mypl.y-5,mypl.+| ) {     
      
pl.chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"name,player.account);
  }


Also, you can instead on the clientside use findnearestplayers(x,y), loop through, find the players you wish to send the chat and send the array to the serverside, instead of letting the server handle the loop.

No offense intended to Dusty, but I would ignore everything he said. You should always do things like hit detection serverside. You should always assume that the player can change any clientside code, and do everything you can serverside to prevent against hackers.

Second, if you trigger serverside, your player object is always in scope. Sending your player account with it is a huge security risk because a hacker could change this to make other players do something.

Third, this is completely unnecessary:

PHP Code:

  for(temp.p:allplayers){
    
temp.pl findplayer(p); 

p in this case is already a TServerPlayer object. Technically findPlayer(String account) shouldn't even find the player correctly. The only reason it does work is because it interprets the object as object.name, which happens to be the account name of the player. For example, you can do:

PHP Code:

for (temp.pl allplayers) {
  
pl.chat "hello";
  
pl.setlevel2("start.nw"3030);
  
  if (
pl.32) {
    
pl.16// example
  
}


Again, sorry if I give off the feeling of being offensive, just trying to help :)

Engine 02-07-2010 07:35 AM

Thanks for the awesome explanation Chris and Dusty. I have another question, is there a better way to have a more accurate hit detection? I tried making a showpoly that would show me the area being hit but it doesn't seem to hit correctly in the box.
PHP Code:

function onActionServerSide(hittxhitty) {
  
this.range = - 3;
  for (
plfindNearestPlayers(player.xplayer.y)) {
    if (
pl.account != player.account) {
      if (
pl.x in hittx this.rangehittx | && pl.y in hitty this.rangehitty | ) {
       
//Do stuff
      
}
    }
  }
}
//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    
temp.hitx player.1.4 vecx(player.dir) * 2;
    
temp.hity player.1.5 vecy(player.dir) * 2;
    
test.lol showpoly(200, {
                          
temp.hitx 1.5temp.hity 1.5,
                          
temp.hitx 1.5temp.hity 1.5,
                          
temp.hitx 1.5temp.hity 1.5,
                          
temp.hitx 1.5temp.hity 1.5});
    
test.lol.mode 1;
    
test.lol.alpha .5;
    
triggerserver("gui"nametemp.hitxtemp.hity);
  }



DustyPorViva 02-07-2010 07:57 AM

Serverside HD will always feel inaccurate unless you have a good ping/connection, as it's detecting player's where the server knows they are, rather than where you're seeing them on the clientside. However, a lot of how you do HD will depend on what sort of HD you want and a lot of logic.

For example, you'll want the 'hit origin' of the target to be at player.x+1.5 and playery+2. That's the center of the player's blocking area. So instead of detecting if the player's x is in the range, you detect iif the center is, like so:

if (pl.x+1.5 in |hittx + this.range,hittx|)

However, before the days of 'in', we would calculate HD via delta's. Like so:
PHP Code:

temp.hitx player.x+1.5+vecx(player.dir)*2;
temp.hity player.y+2+vecy(player.dir)*2;
if (
abs((pl.x+1.5) - hitx) <= 1.5 && abs((pl.y+2) - hity) <= 1.5) {
  
// Will hit a player in a 3 tile block of the player's immediate direction.
  // abs() calculates the absolute value. So whether the player is -2 tiles away from the hit, or 2, it will return as 2.
  // this makes it easier to process the data


However, using 'in' is just as well anymore.

cbk1994 02-07-2010 08:00 AM

Here's what we use on Era Dev. It's as accurate as possible, just make sure you have the actual point you hit at the right location. Try showing a polygon dot there until it's correct.

PHP Code:

function attackPlayers(dxdy) {
  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |pl.xpl.3| && dy in |pl.ypl.3|)) {
      continue;
    }
    
    
pl.chat "owww!!!";
  }


We're using this for melee attacks:
PHP Code:

temp.dx player.1.5 vecx(dir) * 2;
temp.dy player.vecy(dir) * 2

so looks like everything is good :)

Engine 02-07-2010 08:13 AM

It's late and maybe I'm just over thinking this but I don't get what the "if (NOT(dx in |" is for, wouldn't you want them to be in the the hitbox?

cbk1994 02-07-2010 08:22 AM

Quote:

Originally Posted by Engine (Post 1554745)
It's late and maybe I'm just over thinking this but I don't get what the "if (NOT(dx in |" is for, wouldn't you want them to be in the the hitbox?

The command "continue" in that if clause is skipping to the next player in the array. Alternatively you could just put the hit commands in the clause and remove the "!".

Engine 02-07-2010 08:24 AM

Is there any downfall to doing it that way?

cbk1994 02-07-2010 08:31 AM

Quote:

Originally Posted by Engine (Post 1554747)
Is there any downfall to doing it that way?

Nope. I did it with continue because there was some more stuff down there and it gets messy with lots of indents. It's also good for stuff like:

PHP Code:

for (temp.pl players) {
  if (
pl.clientr.hp <= 0) {
    continue;
  }
  
  if (
pl == player) {
    continue;
  }
  
  if (
pl.onStaffTag()) {
    continue;
  }
  
  if (
pl.guild == player.guild && player.guild != "") {
    continue;
  }
  
  
pl.chat "oww!!!";


as opposed to

PHP Code:

for (temp.pl players) {
  if (
pl.clientr.hp && pl != player && ! pl.staffTag() && (pl.guild != player.guild && player.guild != "")) {
    
pl.chat "oww!!!";
  }



Engine 02-07-2010 08:33 AM

Oh, alright. I get it now, I was totally confused for a second. Thanks again.


All times are GMT +2. The time now is 06:21 AM.

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