Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How to detect RC login (https://forums.graalonline.com/forums/showthread.php?t=134263776)

Arch_Angel 07-07-2011 02:31 AM

How to detect RC login
 
Hello. I'm not new to GS2, but I am new to now trying to take it seriously in creating my own things and not just know a few commands and loops and such.

I am currently trying to make a message (or announcement) to echo on RC when a players RC is logged on.

I am using the control NPC to do this, and am wondering if it is possible. Right now I can only get a message to be triggered when the players client logs in. So I have something like.....

PHP Code:

function onCreated()
{
   
this.staff = { "Arch_Angel", "Omaster", "littlekinky" }
}

function 
onActionPlayerOnline()
{
   if( 
pl.account in this.staff )
   {
      echo( 
"Welcome back " @pl.account );
   }
} 

Now this of course, is aimed to just send the message to RC when the players client logs in. Is there another function or something I can do that would recognize the RC instead?

Sorry if this is so simple, just trying to progress. Thanks ahead for any responses. Will rep accordingly.

Cubical 07-07-2011 04:25 AM

check the level name

fowlplay4 07-07-2011 04:42 AM

Unless a function was added to handle it, I've been using a timeout loop. I.e:

PHP Code:

function onCreated() {
  
// Clear array of detected RCs
  
this.lastRCs = "";
  
// Start Loop
  
onTimeout();
}

function 
onTimeout() {
  
// Declare an Empty Array for RCs
  
temp.rcs = {};
  
// Loop through All Players currently online
  
for (temp.a: allplayers) {
    
// Check if they're in a level
    // No level usually means they're an RC
    
if (temp.a.level == NULL) {
      
// Player's level was NULL
      // Player is actually an RC
      // Add Player to Array of RCs
      
temp.rcs.add(temp.a);
    }
  }
  
// Check if the amount of RCs is greater than the last amount of RCs online.
  
if (temp.rcs.size() > this.lastRCs.size()) {
    
// RCs have logged on.
    
sendtorc("Staff Reminder! You're all special C:");
  }
  
// Record the new array of RCs for the next timeout
  
this.lastRCs = temp.rcs;
  
// Continue Looping
  
setTimer(0.5);
} 

That's just a way I've doing it though.

Also instead of maintaining a 'this.staff' array you can just directly reference your server options.

temp.staff = serveroptions.staff.tokenize(",");

The tokenize(",") is just in case someone messes up the array formatting.

Arch_Angel 07-07-2011 05:00 AM

Quote:

Originally Posted by fowlplay4 (Post 1657714)
Unless a function was added to handle it, I've been using a timeout loop. I.e:

PHP Code:

function onCreated() {
  
this.lastRCs = "";
  
onTimeout();
}

function 
onTimeout() {
  
temp.rcs = {};
  for (
temp.a: allplayers) {
    if (
temp.a.level == NULL) {
      
temp.rcs.add(temp.a);
    }
  }
  if (
temp.rcs.size() > this.lastRCs.size()) {
    
// RCs have logged on.
    
sendtorc("Staff Reminder! You're all special C:");
  }
  
this.lastRCs = temp.rcs;
  
setTimer(0.5);
} 

That's just a way I've doing it though.

Also instead of maintaining a 'this.staff' array you can just directly reference your server options.

temp.staff = serveroptions.staff.tokenize(",");

The tokenize(",") is just in case someone messes up the array formatting.

little complicated for me to fully understand how you coded everything, but thats a giant help. Thanks, appreciate it.!

rep++ if i can

fowlplay4 07-07-2011 05:12 AM

Quote:

Originally Posted by Arch_Angel (Post 1657718)
little complicated for me to fully understand how you coded everything, but thats a giant help. Thanks, appreciate it.!

rep++ if i can

I updated my post with the proper documentation for the script, so you should get a better idea of what's actually going on now.

Arch_Angel 07-07-2011 05:20 AM

Quote:

Originally Posted by fowlplay4 (Post 1657719)
I updated my post with the proper documentation for the script, so you should get a better idea of what's actually going on now.

<3

perfectly explained.

cbk1994 07-07-2011 09:21 AM

Annoying that we can't get basic events like onRemotePlayerLogin and have to use timeouts for stuff like this.

ffcmike 07-07-2011 09:36 AM

Like Cubical was suggesting can't you just check to see if the level exists or not with onPlayerLogin(obj)?

Or am I missing something?

cbk1994 07-07-2011 09:37 AM

Quote:

Originally Posted by ffcmike (Post 1657773)
Like Cubical was suggesting can't you just check to see if the level exists or not with onPlayerLogin(obj)?

Or am I missing something?

99% certain it's not called when RCs log in.

ffcmike 07-07-2011 09:41 AM

Quote:

Originally Posted by cbk1994 (Post 1657774)
99% certain it's not called when RCs log in.

I'm 100% sure it's called when an RC logs out :p.

Edit: Yeah that is odd.

Cubical 07-07-2011 01:42 PM

Quote:

Originally Posted by ffcmike (Post 1657773)
Like Cubical was suggesting can't you just check to see if the level exists or not with onPlayerLogin(obj)?

Or am I missing something?

I've never had a reason to try it on login, I assumed that it would work on login because it works on logout.

Crow 07-07-2011 01:51 PM

Quote:

Originally Posted by Cubical (Post 1657787)
I've never had a reason to try it on login, I assumed that it would work on login because it works on logout.

That's Graal man.

xXziroXx 07-07-2011 05:56 PM

I posted this in the Code Gallery a while back, might be useful.

http://forums.graalonline.com/forums...ad.php?t=87280

scriptless 07-11-2011 05:26 AM

There should be an easier way to do this without timeout.. I have a script currently that shows players who login on your screen like XBL and PSN do.. it uses a funciton when the player logs in.. this also shows rc's... have you tried
on PlayerLogin() I think is the command.. might be wrong its been a while. then do a check for null level..

fowlplay4 07-11-2011 05:40 AM

Quote:

Originally Posted by scriptless (Post 1658313)
There should be an easier way to do this without timeout.. I have a script currently that shows players who login on your screen like XBL and PSN do.. it uses a funciton when the player logs in.. this also shows rc's... have you tried
on PlayerLogin() I think is the command.. might be wrong its been a while. then do a check for null level..

Only works for players (server-side) not RCs.

PHP Code:

// This code doesn't work!
function onPlayerLogin(pl) {
  if (
pl.level == NULL) {
    
sendtorc("HEY! Listen!" SPC pl.account);
  }
} 


scriptless 07-11-2011 05:45 AM

Quote:

Originally Posted by fowlplay4 (Post 1658317)
Only works for players (server-side) not RCs.

PHP Code:

// This code doesn't work!
function onPlayerLogin(pl) {
  if (
pl.level == NULL) {
    
sendtorc("HEY! Listen!" SPC pl.account);
  }
} 


This is what im using, and when an RC log's in.. my screen is alerted IMEDIATLY.. also, upon logoff.. therefor it MUST Be possible without a timeout.. im dead serious.. load this weapon on testbed for proof.. "public/scriptless/public"

PHP Code:

function onPlayerLogin( pl ) {
  for ( 
temp.npl : allplayers ) {
    if ( 
temp.npl.communityname != pl.communityname ) {
      
with( findplayer(temp.npl) ) {
        if ( 
temp.npl.level != NULL )
          
triggerclient("gui", this.name, "notify", pl.communityname, pl.head, "on");
      }
    }
  }
}

function 
onPlayerLogout( pl ) {
  for ( 
temp.npl : allplayers ) {
    
with ( temp.npl ) {
    if ( 
temp.npl.level != NULL )
      
findplayer(temp.npl).triggerclient("gui", this.name, "notify", pl.communityname, pl.head, "off");
    }
  }
}

//#CLIENTSIDE
function onActionClientside() {
  if ( 
params[0] == "notify" ) {
    
this.notify_account.add(params[1]);
    
this.notify_icon.add(params[2]);
    
this.notify_status.add(params[3]);
    
noti();
  }
} 

Looking at this script it looks like it would not show rc logins but it for some reason does.. o_o

And I know this for FACT because when I login my rc.. I get the error "you do not have admin rights" unless i use in-game rc.. and it will spam my notification system so bad i have to reconnect or sit thru a half hour of spam

fowlplay4 07-11-2011 06:50 AM

I just tested it again with the script in a weapon and it did not work.

scriptless 07-11-2011 06:58 AM

I retested my script, conclusion!

(F6) Does NOT show work.

(Remote Control) This works with my method.

Not sure why there is a difference. But I can post a demo script if you would like?

*EDIT* Tested using Graal6

Deas_Voice 07-11-2011 07:44 PM

i'm not sure triggerclient would work on RC's... for the reason that any clientside actions doesn't work on RC's "players"...

fowlplay4 07-11-2011 10:26 PM

I just tested the code on Testbed too and it doesn't work, at least not for the scenario this thread wanted to use it on.

"I am currently trying to make a message (or announcement) to echo on RC when a players RC is logged on."

I just tested your script and it didn't work either. Only onPlayerLogout worked not onPlayerLogin.

Therefore it's broken or not implemented.

cbk1994 07-11-2011 10:50 PM

onPlayerLogout really shouldn't be called either. I didn't realize it was—that's probably introduced a couple bugs in things I've made before. We need onRemotePlayerLogin and onRemotePlayerLogout.


All times are GMT +2. The time now is 12:42 PM.

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