Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   players in room (https://forums.graalonline.com/forums/showthread.php?t=47367)

bashjgovers 08-21-2003 03:36 PM

players in room
 
hey i wanna make a event house where the people dont need ET to play events. I wanna make the doors will open automatic when there are enough players in the room. Can anyone help me with this?

Neoreno 08-21-2003 03:48 PM

Use a for loop and the playercount variable.

Snakeandy7 08-21-2003 04:28 PM

Wasnt there a command like
if (playerscount == 2){..}
Bla, But i'd listen to kiirar, the loop is the best direction to go :)

Knuckles 08-21-2003 04:44 PM

Quote:

Originally posted by Snakeandy7
Wasnt there a command like
if (playerscount == 2){..}
Bla, But i'd listen to kiirar, the loop is the best direction to go :)

...That's close to what Kirrar's saying.
Quote:

Use a for loop and the playercount variable.
And you mean a timeout loop?

Neoreno 08-21-2003 05:00 PM

No. I mean a for loop.


Edit: I re-read what they wanted, a timeout loop would be more useful in this case.

marcoR 08-21-2003 06:27 PM

ok... i'm no scripting genius, heck, i can barelly make a door ;)

but wouldn't it look like this?
NPC Code:

timeout=0.5;

if (timeout && playercount>5){
do something;
timeout=0.5;
}



but I don't know, i've never used player count, and heck, i suck at scripting..

protagonist 08-21-2003 06:32 PM

Quote:

Originally posted by marcoR
ok... i'm no scripting genius, heck, i can barelly make a door ;)

but wouldn't it look like this?
NPC Code:

timeout=0.5;

if (timeout && playercount>5){
do something;
timeout=0.5;
}



but I don't know, i've never used player count, and heck, i suck at scripting..

Don't declare flags/variables etc. outside of code blocks. In addition, do not have an event check and a conditional check in the same if (statement). I suggest defining timeout in playerenters.

Neoreno 08-21-2003 06:33 PM

Well. The timeout is too infrequent. A timeout of 0.05 would do.
The variable is playerscount I believe. Not to mention it doesn't conform to KSI-GS standards.

Tseng 08-21-2003 06:38 PM

Quote:

Originally posted by protagonist


In addition, do not have an event check and a conditional check in the same if (statement).

The logic behind this is...?

marcoR 08-21-2003 06:40 PM

not the standards!? NO!!! *cuts hand off* it was an example, sheesh, and what's wrong with doing that? (give me a good reason and i'll never do it again)

[edit]
sorry about the timeout I always do that.. I don't even know why, I meant 0.05 tho.
[/edit]

protagonist 08-21-2003 06:50 PM

Quote:

Originally posted by Tseng


The logic behind this is...?


It is neater. Read KSI-GS standards thread.

marcoR 08-21-2003 06:58 PM

meh, I guess I'll fall to the wrain of kai...

so would it be like this?

NPC Code:


timeout=0.05;

if (timeout){
if(playerscount>5){
do something, please!;
}
timeout=0.05;
}



atleast that's how I understood it...

protagonist 08-21-2003 06:59 PM

Quote:

Originally posted by marcoR
meh, I guess I'll fall to the wrain of kai...

so would it be like this?

NPC Code:


timeout=0.05;

if (timeout){
if(playerscount>5){
do something, please!;
}
timeout=0.05;
}



atleast that's how I understood it...

You should still need to define timeout in a code block.

marcoR 08-21-2003 07:00 PM

than like this!?

NPC Code:


if (created){
timeout=0.05;
}

if (timeout){
if(playerscount>5){
do something, please!;
}
timeout=0.05;
}




!?

osrs 08-21-2003 07:27 PM

Quote:

Originally posted by marcoR
than like this!?

NPC Code:


if (created){
timeout=0.05;
}

if (timeout){
if(playerscount>5){
do something, please!;
}
timeout=0.05;
}




!?

Yes.

Snakeandy7 08-21-2003 09:12 PM

Lol, finally he got it, still chance for you zero:p.
Anywho you could of done
if (playerenters || timeout){
}
lol, Anywho :p

marcoR 08-21-2003 09:22 PM

I knew how to make it work, I just didn't know how to do it propperly.

Snakeandy7 08-21-2003 09:37 PM

Quote:

Originally posted by marcoR
I knew how to make it work, I just didn't know how to do it propperly.
You got there in the end ;)

Riot-Starter 08-21-2003 11:01 PM

Just a side note:
playerscount includes NPCs when used clientside.

Python523 08-21-2003 11:06 PM

Quote:

Originally posted by Riot-Starter
Just a side note:
playerscount includes NPCs when used clientside.

only showcharacter ones I believe, unless that was changed

Riot-Starter 08-21-2003 11:20 PM

Quote:

Originally posted by Python523


only showcharacter ones I believe, unless that was changed

I think it is only showcharacters, I just remember problems with gralats causing spar room doors to stay closed. ;)
Although there is an easy fix to determine whether it’s an NPC or player.

Tseng 08-21-2003 11:38 PM

Quote:

Originally posted by protagonist



It is neater. Read KSI-GS standards thread.

Neater? Subjective. I find it neater to have a balance of lines and lengths. You find it neater to have one check per line. When they are related (as they are in this case), I find it unnecessary to split it up. Perhaps I should paste the first line of the first if check in the hpfunctions subroutine on graal2001, and ask if those shouldn't be split up. ;)

One line of two related checks (an event and a condition) and splitting them up one to each line is the same code - so you can't really argue efficiency or optimization, but only a stylistic choice.

(Additionally, the standards thread does not mention putting an event and a condition on separate lines. :)

marcoR 08-21-2003 11:40 PM

I'm not a script head, so.. these rules would not be worth remembering, nor practicing.

protagonist 08-22-2003 12:51 PM

Quote:

Originally posted by Tseng


Neater? Subjective. I find it neater to have a balance of lines and lengths. You find it neater to have one check per line. When they are related (as they are in this case), I find it unnecessary to split it up. Perhaps I should paste the first line of the first if check in the hpfunctions subroutine on graal2001, and ask if those shouldn't be split up. ;)

One line of two related checks (an event and a condition) and splitting them up one to each line is the same code - so you can't really argue efficiency or optimization, but only a stylistic choice.

(Additionally, the standards thread does not mention putting an event and a condition on separate lines. :)

I also find it more efficient to have one check per line in MOST cases. It adds flexibility to a script. You can add in additional commands and statements very easily as compared to having multiple checks in your if statement.

osrs 08-22-2003 07:52 PM

Quote:

Originally posted by Riot-Starter

I think it is only showcharacters, I just remember problems with gralats causing spar room doors to stay closed. ;)
Although there is an easy fix to determine whether it’s an NPC or player.

Yep,also these new gralats are showcharacters =p

Dach 08-22-2003 10:41 PM

Quote:

Originally posted by protagonist


I also find it more efficient to have one check per line in MOST cases

that's not more efficient, it's just your style. dang, that word is getting thrown around to often nowadays

KainDaMan 08-22-2003 11:14 PM

you can solve the problem of it counting npc characters by doing a for statement that includes the playerscount and a check if players[i].id>=0; as -1 = npc character. then if it's true add to a variable. this, however, would require resetting the string every time the event is called. I would go right out and post the script, but I fear it is against the rules of the NPC Scripting Forums

Tseng 08-23-2003 01:04 AM

Quote:

Originally posted by protagonist


I also find it more efficient to have one check per line in MOST cases. It adds flexibility to a script. You can add in additional commands and statements very easily as compared to having multiple checks in your if statement.

Um, the first 'check' is when the action is called, so that happens regardless. The second 'check', be it on another line or in the same if ( ) statement, will be executed regardless; efficiency is not something you can debate with this.

Very easily? I don't go around putting '&& otherflag==true' for every check I add, but it is arguably easier to type two ampersands than 'if ( ) { }'. That does not make it better, but you are incorrect in saying it's easier. :)

Kaimetsu 08-23-2003 01:18 AM

It depends on Graal's inner workings. If you're using a literal compiler/interpreter that doesn't make a distinction between & and && then it's more efficient to split up the checks - if you combine them then it'll happily evaluate the whole condition without stopping to check if it's already invalidated itself.

Tseng 08-23-2003 03:46 AM

Quote:

Originally posted by Kaimetsu
It depends on Graal's inner workings. If you're using a literal compiler/interpreter that doesn't make a distinction between & and && then it's more efficient to split up the checks - if you combine them then it'll happily evaluate the whole condition without stopping to check if it's already invalidated itself.
Well, I think I said it before, but I am only talking about an:

if (event && flag=true) {

compared to:

if (event) {
if (flag==true) {

type situation - if the event occurs, how could it invalidate itself in either?

Or, are you talking about if the event doesn't occur at all? That's the only way I can think that it could be invalidated...

Kaimetsu 08-23-2003 03:48 AM

Ah, yes, in that case you are correct. I tend to favour separation of event checks from normal conditional statements, but that's just a stylistic thing. Wouldn't affect efficiency.

mhermher 08-23-2003 11:52 AM

NPC Code:

//#CLIENTSIDE
if (timeout||playerenters) {
if (playerscount=>5) {
//Stuff here
}
timeout=0.05;
}


Also note if you have showcharacter NPCS (the ones which stefan put in.. that have heads, bodies and stuff counts as players to, so if you got lets say 2 of them, change the 5 to 7.

Snakeandy7 08-23-2003 12:31 PM

//#CLIENTSIDE
if ((playerenters && strequals(#L,levelname.nw)) || timeout){
for(i=0; i<playerscount; i++;){
stuff here :o
}
timeout=0.05;
}
Isnt that one way?
I dont think it is.. not sure tho :o..

mhermher 08-23-2003 02:09 PM

Snake, no need for the level thing, playerscount is the players in the level, allplayers is players in the server.

Snakeandy7 08-23-2003 03:31 PM

I see, Thanks for mensioning:D

KainDaMan 08-23-2003 06:46 PM

the npc character's problem can be solved like this
NPC Code:

for (i=0; i<playerscount; i++) {
if (players[i].id>=0) {
this.players++;
}
}


of course the "this.players" variable would have to be reset to zero before called. and the variable "this.players" everytime would equal to the amount of "real players" in the room.

protagonist 08-24-2003 03:04 AM

Quote:

Originally posted by Tseng


Um, the first 'check' is when the action is called, so that happens regardless. The second 'check', be it on another line or in the same if ( ) statement, will be executed regardless; efficiency is not something you can debate with this.

Very easily? I don't go around putting '&& otherflag==true' for every check I add, but it is arguably easier to type two ampersands than 'if ( ) { }'. That does not make it better, but you are incorrect in saying it's easier. :)

It seems bluntly obvious that it is in the interest of readability to seperate your conditional checks.

Tseng 08-24-2003 06:31 AM

Quote:

Originally posted by protagonist


It seems bluntly obvious that it is in the interest of readability to seperate your conditional checks.

What part of 'stylistic choice' don't you understand? Readability is subjective.

Dach 08-24-2003 07:23 AM

I prefer Tsengs way actually, because if you ask me its alot easier to see all the checks at once instead of making new brackets for each one

just so you know it's not jut Tseng whose crazy ;)

Tseng 08-24-2003 07:27 AM

Quote:

Originally posted by Dach
I prefer Tsengs way actually, because if you ask me its alot easier to see all the checks at once instead of making new brackets for each one

just so you know it's not jut Tseng whose crazy ;)

Well, you can liken it to reading. Different cultures have come up with different ways to read books. Some go left to right, then up to down; others go right to left, up to down; others just go straight down, right to left; still others go in other ways. Can you argue that our style of reading is better than the Japanese, or Hebrew?

Stylistic. choice. :)


All times are GMT +2. The time now is 09:38 PM.

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