Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-24-2010, 02:10 AM
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
(sorry for the slow reply)

The problem with what you want to do is that there's no way to access another player's client or clientr variables from clientside. The reason for this is because it would require far too much bandwidth to transfer all of this data every time a player logs on or enters a new level.

However, you can place certain values in something called the "attr" array. Values in the "attr" array can be accessed by another player as long as they are in the same level.

In order to place clientr.guild in one of the player's attrs, you would need to update it each time the player's "clientr.guild" flag changes.

PHP Code:
player.attr[10] = player.clientr.guild
It's also a good idea to set this on login in case the player's guild changed while offline (e.g. a staff edited the attributes).

Then, when you want to access another player's guild, you can use a script like

PHP Code:
//#CLIENTSIDE
function onCreated() {
  for (
temp.pl players) { // this lets you loop through each player in your current level
    
if (pl.attr[10] != null) { // if the player has a guild
      
echo(pl.communityname " is in the guild " pl.attr[10]); // output it to F2
    
}
  }


Also, instead of using players[i].value, you can use a "for each" loop.

Quote:
Originally Posted by cbk1994 View Post
Another, different type of for loop is like a foreach loop in other languages. It's done like this:

PHP Code:
for (variable : array) {
  echo(
variable);

Arrays are defined like this

PHP Code:
temp.array = {"one""two""three""hello""world"}; 
which means you can also do

PHP Code:
for (variable : {"one""two""three""hello""world"}) {
  echo(
variable);

however, you need to specify a variable

PHP Code:
for (temp.number : array) {
  echo(
number);

would output

Quote:
one
two
three
hello
world
Be sure not to get the two types of for loops mixed up. The for each loop does the same thing as

PHP Code:
temp.array = {"one""two""three""hello""world"};

for (
temp.0< array.size(); ++) {
  
temp.variable = array[i];

The way this works is like this:

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.trigger("timeOut"null); // start the timeout loop
}

function 
onTimeOut() {
  
temp.didShow false;
  
  for (
temp.pl players) {
    if (
pl == player) {
      continue; 
// if it's yourself, skip it
    
}
    
    if (
mousex in |pl.xpl.2| && mousey in |pl.ypl.2|) { // the coordinates probably need to be improved
      
with (findimg(200)) {
        if (
pl.attr[10] != null) { // are they in a guild?
          
text "Guild: " pl.attr[10]; // if in a guild
        
} else {
          
text "Guild: (not in a guild)"// if not in a guild
        
}
        
        
mousex 2;
        
mousey;
      }
      
      
didShow true;
      break; 
// end the loop
    
}
  }
  
  if (! 
didShow) {
    
hideimg(200); // hide the image since it wasn't shown this frame
  
}
  
  
this.setTimer(0.05);

Each 0.05 seconds, the script looks through every player in the level. If the player it is looking at is the current player, it skips it since you don't want to display it for yourself (if you do, you wouldn't want that part of course). It checks if the player's mouse is on that player. If it is, it shows the text. If not, it doesn't.

Notice that this:

PHP Code:
for (temp.pl players) { 
is equivalent to this:

PHP Code:
for (temp.0players.size(); ++) {
  
pl players[i]; 
It's just easier to do.

Sorry for the long post, I hope it answers your questions. And as always, sorry if I come off as condescending.
__________________
Reply With Quote
 


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 06:37 PM.


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