Level Auto-Update Script

This is a new script I wrote today to solve problems I’ve been having with levels not updating when the player re-enters them. The problem was that certain scripts would not run after the first time like seteffect or play filename unless the level was updated. It only updates if the player is coming from a different level (where this script also exists) and it only runs once per level.

// NPC made by Arcain
// Level-Auto Update Script
if (playerenters) {
    sleep .5;
    if (!(strequals(#L,#s(client.level)))){
    triggeraction 0,0,gr.updatelevel,;
    setstring client.level, #L;
  }
}

Edit: Added sleep .5; - Thanks Urza

Note: I intended this script for use with single-player levels such as dungeons. I have not tested this script with normal multi-player levels. It would probably be kind of annoying for other players if the level updated every time a new player entered, especially if it was a boss level… but most boss levels on my server are going to be single player until someone with the ability to design group/co-op dungeons comes along anyway.

Newbie tip: In order for it to work as intended, you must place it in every level or make a system npc.

EDIT: At first I tried just having the updatelevel triggeraction when playerenters without the flag check and I got an infinite update level loop… wasn’t pretty. Thus the level flag set/check to ensure it only updates once per level.

Nicely done :slight_smile: couldn’t have done better myself not that im that good… But yer none the less good job helping out the newbies :wink:

[QUOTE=Arcain;65933]

Newbie tip: In order for it to work as intended, you must place it in every level or make a system npc.
[/QUOTE]

It’s prolly better just to drop it in the levels, otherwise you’d have top add some case statements

I dont see what issues it would have as a weapon also arcain programs in another language? Because your using that not statment differently to graal :o
I generally would do it as:
if (!strequals()){} also just to make things more compact I would’ve preferably written it as:
if (playerenters && !strequals(#L,#s(client.level))){}
But i spose it just comes down to preferences and everyones individual idea of neat.

[QUOTE=tricxta;65952]I dont see what issues it would have as a weapon[/QUOTE]

O_o why would you want to update every level you enter?

Say i’m halfway through a push pull block level then you enter, thus updating the level. Would suck for me eh?

The point i was trying to make chances are you only want that to happen in a select few levels. Therefore it’d prolly be easier just to drop them in those levels rather than write out a long if statement, although if you’re only targeting singleplayer levels it’s not a bad idea to turn it into a weapon…

Yeah as I stated this is mainly being used for single player levels. I have encountered a problem with the script. Using Client v 2.22 when the client loads the level for the first time and simultaneously processes the level update script, the player is warped to the incorrect coordinates.

Example:
A link is set to place the player at (18, 14) in level_1.nw
This is the first time the client has been sent level_1.nw
The player enters, the level is updated, player is placed at (62,14) (a wall or black area).

After several trials I have learned this only happens when the client is loading the level for the first time. After that the link and update level scripts works as intended.

Newbie Tip: When I’m testing new levels I usually always test with a fresh client, (I unpack a fresh graal folder from the zip archive.) So that I can experience the world as a new player would who doesn’t have any of the Xoria content. This strategy has allowed me to catch a lot of bugs that I otherwise would have over-looked such as this one. Just an FYI. Anyway not sure whats causing this.

___Merged doublepost__________________

Update:
Added a sleep .5; as Urza suggested and the problems stopped. Thanks :smiley:

I’ll continue to test and report any further developments.

PS: I updated the script in the original post.

I thought you meant there would be an actual problem woth the script if it was a weapon. Also a think a goodway to detect singlePlayer would be:
Tokenize2 .,#L;
If (!strequals(#L,#t(0).#t(1)))triggeraction 0,0,gr.updatelevel,;

Of course this method works off a untested theory of mine sl chances are it wont work but meh… The ideas there lol

this is good