Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-12-2010, 12:41 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
allplayers global var

Having a bit of a problem...

I'm choosing a random player that isn't the player on another client, but its not optimizing as it should, any ideas?
HTML Code:
function onActionGrab() {
  temp.list = allplayers;
  echo(temp.list);
  while (temp.pl == null) {
    temp.pl = temp.list[int(random(0, temp.list.size()))];
    
    echo("testing" SPC temp.pl);
    echo("times" SPC temp.pl.computerfirstlogin SPC player.computerfirstlogin);
    
    if (temp.pl.computerfirstlogin = player.computerfirstlogin) {
      temp.list.remove(temp.pl);
      echo("REMOVED" SPC temp.pl);
      temp.pl = null;
    }
  }
  
  echo("found" SPC temp.pl);    
}
gives this result
HTML Code:
allplayers
testing Graal707396
times 1250035986 1250035986
REMOVED Graal707396
testing Graal707396
times 1250035986 1250035986
REMOVED Graal707396
testing Graal707396
times 1250035986 1250035986
REMOVED Graal707396
testing WanDaMan
times 1250035986 1250035986
REMOVED WanDaMan
testing Sp_lit
times 1262628732 1250035986
found Sp_lit
when really it shouldn't be checking the same account more than once.
__________________
Reply With Quote
  #2  
Old 07-12-2010, 12:57 AM
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
if (temp.pl.computerfirstlogin = player.computerfirstlogin) {

==
__________________
Quote:
Reply With Quote
  #3  
Old 07-12-2010, 01:06 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
You can't remove from the allplayers array (which I wonder if it is trying to do instead of copying the array) so instead use it read-only, it's also more efficient this way:
PHP Code:
function onActionGrab()
{
  while (
true)
  {
    
temp.pl allplayers[int(random(0allplayers.size()))];
    
    if (
temp.pl.computerfirstlogin == player.computerfirstlogin)
    {
      continue;
    }

    break;
  }
  
  echo(
"found" SPC temp.pl);    

__________________
Skyld
Reply With Quote
  #4  
Old 07-12-2010, 01:15 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
I was trying to replicate an array to save memory, skyld pointed it out that the loop will only ever run more than once if it matches someone using two accounts. Maximum loop size depending on how many clients are open and if they're even hit by the random number.

Thanks guys
__________________
Reply With Quote
  #5  
Old 07-13-2010, 06:41 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
Note that this is incorrect code:

PHP Code:
echo("found" SPC temp.pl); 
temp.pl is the player object, instead you should do this:

PHP Code:
echo(temp.pl.account); 
I mention this because you will get unexpected results if you try to use that object as a string (e.g. using it in a variable name or sending it in a trigger).
__________________
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 09:46 PM.


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