View Single Post
  #9  
Old 07-31-2017, 11:19 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
In GS2 the most efficient way to warp players out of a level is to have a serverside NPC with a setshape that extends to the whole level, like so:

Graal Script Code:
function onCreated() {
  
// Set the NPCs shape to 1024x1024, or 64x64*16
  
setShape(1,1024,1024);
  
// You can still set an NPC to not block and it will retain its shape and trigger onPlayerTouchsme
  // This is useful for instances like this, while also not making the entire level return true for any serverside onwall() checks
  
dontblock();
}

// The player will trigger onPlayerTouchsme() as soon as they enter the level, and again if their position changes at all
// See below for explanation
function onPlayerTouchsme() {
  
// Don't warp out your account
  
if (player.account == "maximus_asinus") return;
  
// Don't warp out players who are in server.warp
  
if (player.account in server.warp) return;
  
// Warp player to the designated unstickme level
  
player.chat "You're banned from this level";
  
player.setlevel2(serveroptions.unstickmelevel,serveroptions.unstickmex,serveroptions.unstickmey);

No timeouts needed, no need to trigger the server. You can do the same thing on clientside as well but instead make the NPC block for players who aren't allowed in, denying them the ability to walk around. You can also do something like rendering a black showpoly on the screen so they can't see anything in the level.

The benefit of this method is letting the server do all the heavy-lifting so even if they are lagging they will still get warped out as soon as they enter the level.

Also, onPlayerTouchsme works differently on serverside and clientside. On serverside it will be triggered whenever the players position changes, not just when the player invokes movement. It will also be triggered multiple times, unlike clientside. Clientside onPlayerTouchsme will only trigger when the player himself moves and touches an NPC and it will won't trigger until the player moves away and touches the NPC again(save some glitchy methods). This means when dealing with serverside onPlayerTouchsme() it's fairly good at detecting players entering the level and moving without needing to loop or rely on clientside methods.
Reply With Quote