Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Checking playercount in another level (https://forums.graalonline.com/forums/showthread.php?t=81626)

Vulgar 09-02-2008 11:01 PM

Checking playercount in another level
 
How would I check playercount in a level that the player isnt in.I'm having another brainfart and cannot figure this out.
NPC Code:

if (playercount = NULL in this.stageinstance){
deletelevel (this.stageinstance);
}


Dan 09-02-2008 11:13 PM

PHP Code:

if (findlevel("levelname.nw").players.size() == 0)
  
deletelevel("path/levelname.nw"); 

(if deletelevel is actually a command, I'm not sure)

Vulgar 09-02-2008 11:16 PM

I figured it out like 2 minutes ago but thank you.

Quote:

Originally Posted by Wiki
deletefile(str) - returns boolean
deletelevel(str) - returns boolean


Inverness 09-03-2008 12:01 AM

Perhaps try to reuse levels rather than copying and deleting them often?

Vulgar 09-03-2008 12:07 AM

Does that reduce lag or something?

Inverness 09-03-2008 12:16 AM

Quote:

Originally Posted by Vulgar (Post 1419858)
Does that reduce lag or something?

Overall I doubt you'll see a performance difference unless you're copying and deleting lots of levels. Though I don't know what happens behind the scenes when you use copylevel() or deletelevel().

But I just think reusing copied levels is a better way to do it. And only create more copies if you go over the amount already existing, and then delete extra copies down to the default amount.

Vulgar 09-03-2008 12:33 AM

I was setting it up so the players name is in the levelname. I don't exactly know how to do what you are talking about though. If you could give me an example or the Commands to look up that would be great.

Inverness 09-03-2008 12:45 AM

Quote:

Originally Posted by Vulgar (Post 1419865)
I was setting it up so the players name is in the levelname.

I assume you mean account name? Nicknames might have characters that won't do so well in filenames.
Quote:

Originally Posted by Vulgar (Post 1419865)
I don't exactly know how to do what you are talking about though. If you could give me an example or the Commands to look up that would be great.

If you don't know how to do it then don't worry about it.

Basically I would just have some system track what accounts are using what levels and create new levels if there aren't enough already and delete extras when they're not used anymore.

Vulgar 09-03-2008 12:50 AM

Oh ok, and yes i'm using account names.

edit: I ran into a problem, when someone logs off and then the level is deleted they get stuck 'loading'. Is there any way to check if the player's level has been deleted. Like would FindFile() or would player.level = NULL work?

Admins 09-03-2008 02:53 AM

Normally people are put back to the start level when they login to a level that doesn't exist.

Vulgar 09-03-2008 02:56 AM

I was testing on a Trial so I don't know if that makes any difference, it came out of observer and it kept 'loading.'

Inverness 09-03-2008 06:51 AM

Quote:

Originally Posted by Vulgar (Post 1419899)
I was testing on a Trial so I don't know if that makes any difference, it came out of observer and it kept 'loading.'

findlevel(levelname) returns the TServerLevel object.
PHP Code:

if (findlevel("levelname.nw") == null) {
  
// level does not exist


When a person logs off the PlayerLogout event is called everywhere on the server with the player's object being the first parameter. You should be able to use this to check their level but I don't know if you can actually change it since they've basically logged out. Try changing the level from there, and if it doesn't work then you need some kind of script to track whos logged out in a level that could be deleted.
PHP Code:

function onPlayerLogout(p) {
  if (
p.level.name == "levelname.nw") {
    
// they shouldn't be there
    
p.setlevel2("newlevelname.nw"3030);
    
// if this doesn't work, use a system to track them.
  
}



Crow 09-03-2008 04:25 PM

Quote:

Originally Posted by Stefan (Post 1419898)
Normally people are put back to the start level when they login to a level that doesn't exist.

That's broken for about 2-3 years then. It happens all the time, you can experience that on u/c playerworlds quite often.

Admins 09-08-2008 03:00 PM

Quote:

Originally Posted by Crow (Post 1419999)
That's broken for about 2-3 years then. It happens all the time, you can experience that on u/c playerworlds quite often.

It's working fine for me when testing. When a player logs in and the level is not existing then he/she is put in the start level (server option startlevel, startx, starty).

Crow 09-08-2008 03:18 PM

Quote:

Originally Posted by Stefan (Post 1421410)
It's working fine for me when testing. When a player logs in and the level is not existing then he/she is put in the start level (server option startlevel, startx, starty).

Might happen because the server options entries of those are empty then, might want to add an additional check for that.

[email protected] 09-08-2008 03:56 PM

You may clip our wings, but we will always remember what it was like to fly.

Crow 09-08-2008 04:10 PM

Quote:

Originally Posted by [email protected] (Post 1421416)
You may clip our wings, but we will always remember what it was like to fly.

Oookaay?


All times are GMT +2. The time now is 08:52 AM.

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