Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Bug Report (https://forums.graalonline.com/forums/forumdisplay.php?f=193)
-   -   NPC Setlevel2 problem (https://forums.graalonline.com/forums/showthread.php?t=134269510)

samich 08-26-2014 12:06 AM

NPC Setlevel2 problem
 
So I have a problem where setlevel2 is not acting appropriately.

Example: So imagine I'm building an hotel with 30 floors/levels that will all be 100% similar. The stairs will be on the north and south of the room, with NPC's as level warps. If the north and south npcs - that use selevel2 to change floors - are on the same x axis location, then it will enter the script of the next floor's npc to go to the next level, etc. In a split second, you go from floor 1 to floor 30.

The problem: Npcs using setlevel2 to transfer a player to another level which contains an npc with a setlevel2 call also, will send the player to that call's location as well IF they have the same x location; the y location is not important.

If you want to see an example, log onto my server - Aqua (Going to be renamed to Vivitron), and I will show you a hotel system I'm working on.

Torankusu 08-27-2014 03:27 PM

post some script(s) please.
don't really feel like logging onto a private server after aforementioned security flaws, and not really looking forward to hunting down some hotel system...

Just based on the description, you need to compensate for the direction the player is traveling in, because it seems you are probably warping him either:
1.) Directly on top of the next NPC, causing the player to touch the NPC event to occur, and warp him appropriately, or
2.) You are warping him too few tiles apart from the NPC and he is still traveling causing him to touch the NPC promptly after he warps.

A video here might help.

Also, is there any particular reason you are using NPCs to set the level here?
If this is some form of an elevator system, don't you think you could integrate it into a grab system you develop? ( onActionGrab() )

Jakov_the_Jakovasaur 08-27-2014 03:33 PM

sounds like a never-ending chain of onPlayerTouchsMe events, although its hard to tell given the lack of script or screenshots the problem could also involve needing to change the players direction

if you script the touch event on Clientside then trigger to Serverside on the npc to handle warping, that should definitely prevent this

samich 08-27-2014 05:49 PM

The reason they are NPC's is because they are copyLevel generated floors. It is an automated playerhouse-esque system, and I needed to dynamically set the level to go to next, as regular level links wouldn't work dynamically like that.

NPC Code:

function onCreated() {
setimg("vivitron_hotel-halfdoor.png");
// Get the next level up's floor number
this.floor = int(this.level.name.substring(12, -1).tokenize(".")[0]) + 1;
setshape(1, 32, 16);
dontblock();
drawunderplayer();
}

function onPlayerTouchsMe() {
if(!levelexists("hotel_floor_" @ this.floor @ ".nw")) return;
setlevel2("hotel_floor_" @ this.floor @ ".nw", player.x, 33.5);
}



Here is a video (disregard floors 1,2 and possibly 3, as they are made in a way that works, but is not the way I want the levels to look like): http://youtu.be/w6vKyZ8Pa_I

At around 18-20 seconds I demonstrate how moving slowly, the setlevel2 transition works just fine, but anytime before that, weird things happen, such as some images not loading (due to such immediate level switching, I'm assuming).

samich 08-27-2014 05:55 PM

Quote:

Originally Posted by Jakov_the_Jakovasaur (Post 1730590)
sounds like a never-ending chain of onPlayerTouchsMe events, although its hard to tell given the lack of script or screenshots the problem could also involve needing to change the players direction

if you script the touch event on Clientside then trigger to Serverside on the npc to handle warping, that should definitely prevent this


I think I'll try something like that. Hopefully the playertouchsme chain won't happen after taking time to chat with the npc server, and add a bit more precision by relying on clientside checking.

And I apologize for the initial post having no resources to review. In the middle of a house move and I didn't have internet for a bit.

MysticalDragon 08-27-2014 07:17 PM

On delteria when we generate levels we change the links via script

samich 08-27-2014 07:21 PM

You can change level links via script? How would you go about doing that, if you don't mind me asking? I haven't done much level manipulation via script.

callimuc 08-27-2014 09:54 PM

Quote:

Originally Posted by samich (Post 1730613)
You can change level links via script? How would you go about doing that, if you don't mind me asking? I haven't done much level manipulation via script.

You have like a template level. You always load that one file as a text (using loadLines() or whatever you want to use) and have the script look for a certain warp you want to manipulate (lets say the format is 'LINK 30 30 some_level.nw' ; I'm not too sure didn't check it). After you've found that / them, you simply alter the Level name like:

PHP Code:

temp.newlevel "new_level.nw";
temp.line yourFoundLINKLocationInsideTheFile.tokenize();
//          LINK             x                y                levelname
temp.line temp.line[0SPC temp.line[1SPC temp.line[2SPC temp.newlevel 

and save those edited lines via saveLines() as a new level. Make sure to keep your level template unedited - it's a template ;)

TBH I've never really tried editing the links directly like that, but that's the way that I can think of right now. Probably would end up changing it all again

MysticalDragon 08-31-2014 11:41 PM

Quote:

Originally Posted by callimuc (Post 1730617)
You have like a template level. You always load that one file as a text (using loadLines() or whatever you want to use) and have the script look for a certain warp you want to manipulate (lets say the format is 'LINK 30 30 some_level.nw' ; I'm not too sure didn't check it). After you've found that / them, you simply alter the Level name like:

PHP Code:

temp.newlevel "new_level.nw";
temp.line yourFoundLINKLocationInsideTheFile.tokenize();
//          LINK             x                y                levelname
temp.line temp.line[0SPC temp.line[1SPC temp.line[2SPC temp.newlevel 

and save those edited lines via saveLines() as a new level. Make sure to keep your level template unedited - it's a template ;)

TBH I've never really tried editing the links directly like that, but that's the way that I can think of right now. Probably would end up changing it all again

Like Callimuc said, here is a piece that might help from Instance System from Novo. A tad was changed by me below.

We actually find the links using a identifiable name such as original. All our instance levels are levelname-original.nw.
to get the copy_id, we calculate each instance created (Ex: this.copy_counter.(@temp.id) ++;//temp.id would be the instance type)
PHP Code:

  temp.original_level levelname-original.nw;
  
temp.lines.loadlines("levels/instance/"temp.original_level);
  
temp.newlines = new[0];
  for (
temp.linetemp.lines) {
    
temp.original_pos temp.line.pos("original");
    while (
temp.original_pos != -1) {
      
temp.line temp.line.substring(0temp.original_pos) @ temp.copy_id temp.line.substring(temp.original_pos strlen("original") - 2);
      
temp.original_pos temp.line.pos("original");
    }
    
temp.newlines.add(temp.line);
  } 


And what this does is it copys the x and y coordinates of your original level, and renames the copied level as well as the links.


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

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