Help me weed out bad practices.
So I was scripting in an online editor and was annoyed by the people popping into the level to see what I was working on. So I scripted a system to remove players froma level in the offline editor in GS1. As part of my practice learning GS2 I want input on mistakes I made, how to make the script more efficient, design security for the NPC, and finally convert the script into GS2. Any advice is appreciated.
PHP Code:
PHP Code:
Also I think I read that variables can now be assigned text values in GS2 like how strings work in GS1. Can you manipulate those variables in the same way as I am doing it in my script? If so, how? |
Quote:
I would create a database and when you create it place it in your level. PHP Code:
|
Quote:
Quote:
Thanks for replying. |
sleep(1) is more like waitfor(this, "none", 1) in GS2 the benefit of this it doesn't stop the execution of the script, that's my preferred method If its viable. scheduleevent can call a function on a timer basis. Basically It wont trigger the function immediately but when it hits the timer. Its better then timeout since it can be called once. Although I seen some people set there setTimer(0) (not sure if that even works, never tried it), which is ugly in my opinion. Reason I used this is because like your join classes, It's good to have one centralized place for repetitive code. instead of adding this.chat = "" after ever function its only in one place. Format just organized your code in a readability type way. Instead of doing things like,
PHP Code:
PHP Code:
PHP Code:
|
Okay I'm having issues with the basics.
PHP Code:
|
Accident, I meant to do
if(player.chat.starts("/add")) { and if(player.chat.starts("/remove")) { |
Okay so I made an attempt at scripting the same system in GS2 using Carlito's example as my base, but I couldn't get format to work with player.chat. Also tried to do something like this.chat = temp.list "message" but I couldn't get it to work either. Does anyone know why?
Eventually I want to display the people on the blacklist. I know I could do something simple like this.chat = this.deniedList, but the output looks pretty ugly. Is there a better method of displaying the contents of the array? PHP Code:
|
So I'm trying to think of a method to warp other players but I can't think of anything. The closest I can come up with is using triggeraction passing on temp.list, and then doing something like:
PHP Code:
PHP Code:
|
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:
PHP Code:
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. |
Quote:
Can you give the same rundown for onPlayerEnters()? Is it different clientside and serverside? Alsowhat is the benefit of making the server do heavy lifting? I would assume everyone uses a supercomputer these days so making as much stuff clientside would be the smart thing to do. For 2k1's server, it doesn't seem to be allocated very much memory and I had to cut the amount of birds flying in half to stop server lag. |
Quote:
And I still think it would be better to remove the player once I executed the command. Otherwise you could just stay still to prevent being warped. But maybe this is a limitation of not making it a weapon. |
Quote:
What I mean about letting the server do the heavy lifting is that you don't need to worry about their computer, connection issues/lag, or things like that. The server will know they entered the level and they will trigger onPlayerTouchsme() and get warped out before their PC even gets the data. It's just faster and more efficient than detecting it clientside and then waiting for the data to get to the server and then sending it. And if they're lagging it may not happen for a while or at all. An event like onPlayerTouchsme() won't do much, while scripts like birds that are always running loops will be much more intensive. By the way, NPCs running loops will continue to run loops even if a player is not in a level. I don't think the loop is stopped until the level is pulled from memory and cleaned up... and I think that's like 5-10 minutes. It's best to break any loops serverside(such as a timeout loop) when players.size() <= 0. Something like this: PHP Code:
Quote:
And yes, it works like this: PHP Code:
Anyways about the onPlayerTouchsme(). You don't need to worry about players entering the level and not moving. Like I said on serverside this gets called whenever the player position changes--that includes when they change position by entering the level. As soon as they enter the level it will trigger onPlayerTouchsme(). The good thing about this over onPlayerEnters() is that if for whatever reason it may fail, if they move at all they will trigger it again. And again, if you're that worried you can put a polygon on the clientside so they can't see anything anyways. Like so: PHP Code:
|
thank you Dusty, that is very helpful to know.
|
Quote:
|
Quote:
|
All times are GMT +2. The time now is 05:48 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.