Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-03-2010, 09:54 PM
BlackTemplar BlackTemplar is offline
Registered User
Join Date: Jul 2010
Posts: 9
BlackTemplar is on a distinguished road
Red face 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();

Reply With Quote
  #2  
Old 07-03-2010, 10:02 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Screenshots?
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #3  
Old 07-03-2010, 10:22 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
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
  
}

__________________
Quote:

Last edited by fowlplay4; 07-03-2010 at 10:32 PM..
Reply With Quote
  #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
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 05:37 PM.


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