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].