View Single Post
  #4  
Old 07-03-2010, 10:24 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
Eeek!

This:
PHP Code:
function onActionServerSide() 
  { 
  switch (
params[0]) 
    { 
    case 
"Profile"
    { 
      
this.player.clear(); 
      for (
temp.0temp.allplayerscounttemp.++) 
        if (
params[1in allplayers[temp.i].x,allplayers[temp.i].| && params[2in allplayers[temp.i].y,allplayers[temp.i].| && allplayers[temp.i].level != NULL
          { 
        
this.player allplayers[temp.i]; 
        
triggerClient("weapon",this.name,"Profile",this.player,this.player.clientr.communityname,this.player.clientr.upgradestatus); 
        break; 
      } 
    } 
  } 

is all wrong. Not only are you looking through allplayerscount, which is every player on the server and not the level, but you should also use foreach loops.

PHP Code:
function onActionServerSide(cmd) {
  switch (
cmd) {
    case 
"profile":
      for (
temp.pl players) {
        if (
pl.x in |x3| && pl.y in |y3| && pl != player) {
          
triggerClient("weapon"this.name"profile"pl.accountpl.communitynamepl.upgradestatus); 
        }
      }
    break;
  }

Your trigger also had a few errors:
  • You were sending "this.account" which referred directly to the player object, not the player's account. This works because of some guess work in Gscript which converts it to a string based on the object's name, but the proper way to do it is 'this.player.account'.
  • You were using 'player.clientr.communityname', 'player.clientr.upgradestatus' -- I see that you're saying to define those on login, but there's no reason to since they are all values of the TServerPlayer object.

In addition, you should use temporary variables instead of variables on the weapon in order to save memory and make the code cleaner.

PHP Code:
temp.pl allplayers[temp.i];

// instead of
this.pl allplayers[temp.i]; 
However, this still isn't right. There's no reason to go serverside in order to find out where a player you're right clicking is. If anything, you won't be able to right click players because by the time the trigger reaches the server the player may have moved, especially if you lag.

A small snippet with clientside finding players:
PHP Code:
function onActionServerSide(cmdacc) {
  if (
cmd == "profile") {
    
temp.pl findPlayer(acc);
    
triggerClient("weapon"this.name"profile"pl.accountpl.communitynamepl.upgradestatus);
  }
}
//#CLIENTSIDE
function onMouseDown(button) {
  if (
button == "right") {
    
temp.pl findPlayerAtPosition(mousexmousey);
    
    if (
pl != null) {
      
triggerServer("weapon"this.name"profile"pl.account);
    }
  }
}

function 
findPlayerAtPosition(xy) {
  for (
temp.pl findNearestPlayers(xy)) {
    if (
pl.x in |x3| && pl.y in |y3| && pl != player) {
      return 
pl;
    }
  }

And also, in your onCreated event, this is going to cause an error if Profile_Window has not been defined yet.

PHP Code:
Profile_Window.hide(); 
should be:

PHP Code:
if (Profile_Window.visible) {
  
Profile_Window.hide();

I don't mean to be rude, but I'd suggest this thread be moved out of the code gallery.
__________________
Reply With Quote