Is this. serverside?

I cannot remember… I was scripting for psewolf and although this seems correct I still get the feeling it’ll have weird behaviors with multiple players.

What I’m wondering is if the this. variables will be there for players who entered the level after the npc has been interacted with. Also… will the variables in created be there for every player who enter the room?

Thanks everyone.

if(created){
  this.maxplayers = 8;  //the max number of players you want to get through the door
  setstring this.newlevel,yourlevel.nw; //change "yourlevel" to your level with the nw extension
  this.newlevelcoordsx = 32; // where to warp (x)
  this.newlevelcoordsy = 32; // where to warp (y)
}

if(playerenters&&this.warping){
  setimg no-shield.png;
} else if (playerenters) {
  setimg door.png;
}

if (actionleftmouse&&!this.warping) {
  setimg no-shield.png; //<-just a transparent image so the players can
  this.warping = true;  //still touch the npc while there's no door
  this.playersentered = 0;
}

/* remove the slash stars and this comment
   to add the functionality
   of reclicking the door to close it without
   having all players through
if(actionleftmouse&&this.warping){
  setimg door.png;
  this.warping = false;
}
*/

if(playertouchsme&&this.warping&&this.playersentered<this.maxplayers){
  setlevel2 #s(this.newlevel),this.newlevelcoordsx,this.newlevelcoordsy;
  this.playersentered++;
}else if(playertouchsme&&this.warping){
  setlevel2 #s(this.newlevel),this.newlevelcoordsx,this.newlevelcoordsy;
  setimg door.png;
  this.warping = false;
}

EDIT:
Since it took me a while to figure out I had to force lag, I’ll post the system I made here.

Here’s the script for the doors:

//NPC made by 2ndwolf
/*
   this.warping = npcs[-1].save[0];
   this.maxplayers = npcs[-1].save[1];
   this.playersentered = npcs[-1].save[2];
   shouldupdate = npcs[-1].save[3];
   forcelag = npcs[-1].save[4];
*/

if(playerenters){
  setstring this.newlevel, era_eventshouse_race.nw;  //change yourlevel.nw to your level
  this.newlevelcoordsx = 25; // where to warp (x)
  this.newlevelcoordsy = 40; // where to warp (y)
  setshape 1,48,64;

  if (npcs[-1].save[0]==1)imopen();
  else imidle();

  npcs[-1].save[3] = 1;
}

//clicking the door
if(actionleftmouse&&npcs[-1].save[0]==0&&strequals(#s(client.staffguild),Admin)) {
  hideme();
  npcs[-1].save[0] = 1;
  npcs[-1].save[1] = storedmax;
  npcs[-1].save[2] = 0;
  storedmax = 0;
  npcs[-1].save[3] = 1;
} else if(actionleftmouse&&npcs[-1].save[0]==1&&strequals(#s(client.staffguild),Admin)){
  showme();
  npcs[-1].save[0] = 0;
  npcs[-1].save[3] = 1;
}

//warping the players
if(playertouchsme&&npcs[-1].save[0]==1&&npcs[-1].save[2]<npcs[-1].save[1]-1&&this.shouldshoot!=1){
  npcs[-1].save[2]+= 1;
  npcs[-1].save[4] = 1;
  npcs[-1].save[3] = 1;
  this.shouldshoot = 1;
}else if(playertouchsme&&npcs[-1].save[0]==1&&!(npcs[-1].save[1]-npcs[-1].save[2]==0)){
  showme();
  npcs[-1].save[0] = 0;
  npcs[-1].save[1] = 0;
  npcs[-1].save[2] = 0;
  npcs[-1].save[4] = 1;
  npcs[-1].save[3] = 1;
  this.shouldshoot = 1;
}

function showme(){
setcharani armanno_blastdoorani_rev,;
}

function imidle(){
setcharani armanno_blastdoorstill,;
}

function hideme(){
setcharani armanno_blastdoorani,;
}

function imopen(){
setcharani armanno_blastdooropen,;
}

function shoot(){
  setshootparams newlevel,#a,#s(this.newlevel),#v(this.newlevelcoordsx),#v(this.newlevelcoordsy);
  shoot -10,-10,0.05,0.05,0.05,0.05,,,,,;
}

if(update){
  if(npcs[-1].save[3]==1){
    if(npcs[-1].save[0] == 1){
      if(npcs[-1].save[1]-npcs[-1].save[2] != 0){
        message Players left: #v(npcs[-1].save[1]-npcs[-1].save[2]);
      } else message ;
    } else message ;
    if(this.shouldshoot == 1 && npcs[-1].save[4]!=1){
      this.shouldshoot = 0;
      shoot();
    }
    if(npcs[-1].save[4]!=1){
      npcs[-1].save[3] = 0;
    }
  }
}

And the system that manages updating the doors:

// NPC made by 2ndwolf

/**************************
    Door system npc
 Forces lag to ensure npcs
         update
**************************/

if (playerenters) {
  timereverywhere;
  timeout = 0.05;
}

if(playerchats&&strequals(#s(client.staffguild),Admin)&&startswith(max:,#c)){
  storedmax = strtofloat(#e(4,-1,#c));
}

if(timeout) {
  for(this.i=0;this.i<npcscount;this.i++){
    if(npcs[this.i].save[4]==1&&this.forcelag==5){
      npcs[this.i].save[4] = 0;
      this.forcelag = 0;
    }
    if(npcs[this.i].save[4]==1){ //if force lag is set
      if(this.forcelag = 0){
        callnpc this.i,update;
      }
      this.forcelag++;
    }
    if(npcs[this.i].save[3]==1&&npcs[this.i].save[4]!=1){
      callnpc this.i,update;
    }
  }
  timereverywhere;
  timeout = 0.05;
}

The shoot probably isn’t required… but I was trying it out to see if npcs update before shooting. They don’t. It seems the variables to change are stored in the client so they change only when the player goes back to the level (if he’s warped immediately), even if they’re npcs[index].save[0].

The “this” prefix means it’s local to the NPC and not shared among all NPCs in the level, or with weapons the player has. They’re local to the player. Thus they aren’t communicated to the server or with other players.

So an npc with this.warping set to true will still have this.warping set to true in itself when a new player enters the level, right?

What happens if everyone leaves(thus the level is unloaded) while this.warping is set to true? Will it stay?

I’m not sure I grasp the concept of an npc having variables set to itself… it’s modifying itself but does not communicate the changes to the players… therefore it’s not clientside, but it’s not serverside either…?

EDIT:
But what you mean is that my code wouldn’t break, right?

Just a note that all of what I described and am describing is for the pre-NPC server clients. If that’s not what you’re talking about, let me know.

Only if the code that sets the “this” variable is in a spot where it’ll be executed when the player enters the level. Or if it had been set when the player was previously in the level and they haven’t reconnected to the server yet.

Any clients that haven’t reconnected to the server will still have it present as far as I recall. If a player is in a level when it’s updated via updatelevel, RC, or being reuploaded, I think that also resets it.

I don’t see anything in this quote that excludes the actions from being a clientside activity. NPCs can certainly modify themselves clientside only.

It’d be better if you described what the intended behavior of the script is first.

It’s meant to let players enter the door once it’s clicked.

I’m concerned players that enter the level once the door was already clicked will see broken code.

I’ll assuming you’re referring to non-NPC server code, since you didn’t comment on that. You’re using nothing that’s synchronized between players. Of course the result isn’t going to be what you described.

Just a note on this, both npc attributes and save variables in a npc are serverside. I prefer to use save where I can, this being because other npcs can access another’s save variables through the ‘npcs’ array

npcs[index].save[save index]

while an npc’s own attributes can be accessed through an index of -1

if (playerenters){
  showcharacter;
  setcharprop #P1,hat0.png;
  message I'm an npc and I'm wearing a hat with a filename of #P1(-1);
}

tricxta is nicer than me. I don’t like to give answers directly.

I wouldn’t have guessed… I’ve just spent the evening trying to guess how a fucking library worked… I’ve just succeeded displaying an image after falling, by luck, on a post on their forum that mentionned I was working with the wrong object of two that are used to load an image in the game. It’s discouraging.

Plus tricxta’s answer isn’t so direct… he’s just mentionning what I need. Thanks anyhow, your explanations were still insightful, codr.

What library is it you’re working with, unless it’s something super obscure I’m surprised you couldn’t find a working example to use as a template of sorts.

Here’s an overview of what I wanted:
The ability to say a command like a number. Then click on a NPC to hide it and allow X number of players to pass through it while showing how many more players can go through. After X number of players have passed through the door, it blocks they players again.

You can store that number in a serverstring or in a npc attribute like tricxta recommended.

It’s that most people don’t use the atlas as an atlas… they all load the images one by one, it’s not what I wanted.

Some of these commands are poorly documented.

hide;
hidelocal;
show;
showlocal;
dontblock;
dontblocklocal;
blockagain;
blockagainlocal;

Well I didn’t want it to hide itself because it still had work to do when players touch it.

But it’s done now, everything’s working; it even has a cool gani, thanks everyone. Especially tricxta, tricxta rules.

It won’t warp anyone yet.

Well I told you what variable to change I think… or it’s in the script.
I’ll be there tonight anyway.

I had a dream about Gscript last night. It was horrible.

Well at least it’s well documented.

Sarcasm?