Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Custom Profile System (https://forums.graalonline.com/forums/showthread.php?t=134259728)

BlackTemplar 07-03-2010 09:54 PM

Custom Profile System
 
Profile System

Installing

1): Make a weapon-NPC, and name it '-System/Profile'.
2): Go to Control-NPC, and under 'onActionPlayerOnline()', add:


PHP Code:

clientr.account player.account;
clientr.communityname player.communityname;
clientr.upgradestatus player.upgradestatus


Enjoy!

-BlackTemplar


PHP Code:

/*
Custom Profile System
Made By BlackTemplar
7/3/2010
*/
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;
      }
    }
  }
}
//#CLIENTSIDE
function onActionClientSide()
  {
  
Profile(params[1],params[2],params[3]);
}
function 
onCreated()
  {
  
EnableFeatures(allfeatures 0x800); //Disables Default Profile
  
Profile_Window.hide();
}
function 
onMouseDown(button)
  {
  if (
button == "right")
    {
    
triggerServer("weapon",this.name,"Profile",mousex,mousey);
  }
}
function 
Profile(account,communityname,upgradestatus)
  {
  
Profile_Window.show();
  new 
GuiWindowCtrl("Profile_Window")
    {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "346,200";
    
canmaximize closequery destroyonhide false;
    
canmove canresize true;
    
text "*" account;
    
screenwidth - (width 2);
    
screenheight - (height 2);
    
    new 
GuiScrollCtrl("Profile_MultiLine_Scroll")
      {
      
profile GuiBlueScrollProfile;
      
height 168;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 346;
      
1;
      
      new 
GuiMLTextCtrl("Profile_MultiLine")
        {
        
profile GuiBlueMLTextProfile;
        
height 16;
        
horizsizing "width";
        
text "<center>Player Information</center>" NL "<center><u>Account</u></center>" NL "<center>" account "</center>" NL "<center><u>Community Name</u></center>" NL "<center>" communityname "</center>" NL "<center><u>Account Status</u></center>" NL "<center>" upgradestatus "</center>";
        
width 321;
      }
    }
    new 
GuiButtonCtrl("Profile_Button_Close")
      {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "Close";
      
width 346;
      
172;
    }
  }
}

function 
Profile_Button_Close.onAction()
  {
  
Profile_Window.hide();



Deas_Voice 07-03-2010 10:02 PM

Screenshots?

fowlplay4 07-03-2010 10:22 PM

Your initial suggestion is very redundant and a waste of clientr variable, and the method of finding the player dates back to the GS1 days.

Here's how it's done now, or at least how I do it.

PHP Code:

function onActionServerSide() {
  if (
params[0] == "getprofile") {
    
// Find Player Object
    
with (findplayer(params[0])) {
      
// Store Data into Temporary Variable
      
temp.data = {
        
player.accountplayer.communitynameplayer.upgradestatusclientr.somethingelseofinterest
      
};
    }
    
// Send Temporary Data back to Client
    
player.triggerclient(this.name"profiledata"temp.data);
  }
}

//#CLIENTSIDE

function onMouseDown(button) {
  if (
button == "right") {
    
temp.pid testplayer(mousexmousey);
    if (
temp.pid 0) {
      
getPlayerData(players[temp.pid].account);
    }
  }
}

function 
getPlayerData(acct) {
  
// Request Player Profile Data
  
triggerserver("gui"name"getprofile"acct);
}

function 
onActionClientSide() {
  if (
params[0] == "profiledata") {
    
temp.profiledata params[1];
    
// Data Handling Code Here
  
}



cbk1994 07-03-2010 10:24 PM

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.


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

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