PDA

View Full Version : If (playerenters) and is second player to enter? [help]

Bleachlover551
07-25-2012, 11:17 PM
:blush:i'm kinda lost here..Okay so im making this event and i want to make where when the first player enters he goes to a pacific location.. like this script below..

if (playerenters){
playerx=x+.5;
playery=y;
}

but i have this script in like 10 different area. but i have no clue how to make a script where when the next player enter he goes to the other spot where this script was places.

Astram
07-27-2012, 02:27 PM
You can use variables to set if there is a player in there for instance you could try something such as this: (I am also coding this in GS2 not GS1 as it is outdated)

function onPlayerEnters() {
if (this.inside == false) {
this.inside = true;
player.x = 30; //Change This, this is the X of the 1st player that enters
player.y = 30; //Change This, this is the Y of the 1st player that enters
} else {
player.x = 15; //Change This, this is the X of the 2nd+ player(s) that enter
player.y = 15; //Change This, this is the Y of the 2nd+ player(s) that enter
}
if (player.chat == "/reset" && player.guild == "Events Team") {
this.inside = false;
}
}

Just plop this down as an NPC in the level and you're ready to go :)

Bleachlover551
07-27-2012, 08:01 PM
You can use variables to set if there is a player in there for instance you could try something such as this: (I am also coding this in GS2 not GS1 as it is outdated)

function onPlayerEnters() {
if (this.inside == false) {
this.inside = true;
player.x = 30; //Change This, this is the X of the 1st player that enters
player.y = 30; //Change This, this is the Y of the 1st player that enters
} else {
player.x = 15; //Change This, this is the X of the 2nd+ player(s) that enter
player.y = 15; //Change This, this is the Y of the 2nd+ player(s) that enter
}
if (player.chat == "/reset" && player.guild == "Events Team") {
this.inside = false;
}
}

Just plop this down as an NPC in the level and you're ready to go :)

so lets say i would have 7 slots open would i just keep adding else command?

ffcmike
07-27-2012, 08:48 PM
An easier more efficient approach would be to create a multi-dimensional array of warp coordinates:

function onCreated(){
//x, y
this.warplocations = {
{5, 10},
{5, 20},
{5, 30},
{5, 40},
{15, 10},
{15, 20},
{15, 30},
{15, 40},
};
this.warpamount = this.warplocations.size();
}

And then increment an array index variable each time a player enters:

function onPlayerEnters(){
player.x = this.warplocations[this.warpindex][0];
player.y = this.warplocations[this.warpindex][1];
//Use % to reset a value back to 0 if it overlaps specified value
this.warpindex = (this.warpindex + 1) % this.warpamount;
}

Bleachlover551
07-28-2012, 01:32 AM
An easier more efficient approach would be to create a multi-dimensional array of warp coordinates:

function onCreated(){
//x, y
this.warplocations = {
{5, 10},
{5, 20},
{5, 30},
{5, 40},
{15, 10},
{15, 20},
{15, 30},
{15, 40},
};
this.warpamount = this.warplocations.size();
}

And then increment an array index variable each time a player enters:

function onPlayerEnters(){
player.x = this.warplocations[this.warpindex][0];
player.y = this.warplocations[this.warpindex][1];
//Use % to reset a value back to 0 if it overlaps specified value
this.warpindex = (this.warpindex + 1) % this.warpamount;
}

Thanks So Much! This Will Help Me A Lot In My Event(s)! :) Also do u have a kickall script? if i may ask?

Tim_Rocks
07-28-2012, 01:43 AM
This should help.

function kick_all() {
for (temp.pl : players) {
if (temp.pl.account == player.account) {
continue; //This way you're not kicked.
}

if (temp.pl.guild in {"Events Team"}) {
continue; //Prevents other Events Team members from being kicked.
}

temp.pl.setlevel2("level.nw", 30, 30);
}
}

ffcmike
07-28-2012, 01:47 AM
Also do u have a kickall script? if i may ask?

Scripting isn't really a matter of "what is the script for ...?", it's more about "which way would I script ...?".

A simple method to kick all players would be to loop through the built-in 'players' array.

One way of looping through the array would be:

for(temp.pl : players){
if(temp.pl.guild != "Events"){
temp.pl.setlevel2("levelname.nw", x, y);
}
}

Note how temp.pl would be in reference to each player within the level (or each element within the 'players' array).

Another would be:

temp.playercount = players.size();
for(temp.i = 0; temp.i < temp.playercount; temp.i ++){
if(players[temp.i].guild != "Events"){
players[temp.i].setlevel2("levelname.nw", x, y);
}
}

Note how temp.i is being incremented up to the last index value of the players array, and then how the players array elements are being read from directly by specifying the index.

cbk1994
07-28-2012, 01:57 AM
if (temp.pl.account == player.account) {

Just compare the objects directly:

if (temp.pl == player) {

Bleachlover551
07-28-2012, 03:14 AM
Thanks So Much! Everyone. ^_^ um do you want to see my event? its fun...^^......but the last thing I'm having trouble with is removing the the players weapon once it leaves the event..or wait let me explain the much more clearly..

Example/My Situation:
I have this simple event. The event has 8 different positons/selections. like the script i was asking for in this thread to begin with. So they enter and my event starts they have daisines and i added inn the daisine script itself. once my player says /kickall it will destroy the daisine..but i had to add this to each individual daisine. but on one of the tracks, its like a trap(the track completely stops i didnt add any more npc tracks to this one specif track section), and once the player hits another npc i made it moves the player y+=1 with a sleep function to make the player actual move...up and hit the warp selection . once he/she hits the warp selection it warps them away to the unstick me level, but the player will steal have the daisine unlike the other plays which i said /lkickall to and removed the weapon, but how do i make it where once the player enters the unstick me level they get the diasine removed?

heres what i came up with..

if (playerenters&&hasweapon(Draisine)){
say2 Your Draisine Will Be Removed!;

cbk1994
07-28-2012, 10:52 AM
To remove a weapon from a player, use player.removeWeapon(weaponName).

Tricxta
07-28-2012, 11:28 AM
Oi tig, I could've benefited from what chris said unless it was out right abuse. Either way, i'm all curious as to what's wrong with the method
findweapon(weaponName).destroy()

cbk1994
07-28-2012, 11:42 AM
Oi tig, I could've benefited from what chris said unless it was out right abuse. Either way, i'm all curious as to what's wrong with the method
findweapon(weaponName).destroy()

Did you test it? This was my post:

Tricxta
07-28-2012, 01:49 PM
Did you test it? This was my post:

Cheers, I didn't think anyone would entrust such power to script functions readily available to anyone who has NC(whatever) access.

xXziroXx
07-28-2012, 02:18 PM
Cheers, I didn't think anyone would entrust such power to script functions readily available to anyone who has NC(whatever) access.

Limiting scripting functionality in fear of what abuse/poor scripting could cause is a horrible approach.

I'll probably pick up a negative rep or two for the following comment, but it'd be like not allowing immigrants from middle eastern countries in fear of letting in terrorists.

scriptless
07-28-2012, 11:46 PM
Limiting scripting functionality in fear of what abuse/poor scripting could cause is a horrible approach.

I'll probably pick up a negative rep or two for the following comment, but it'd be like not allowing immigrants from middle eastern countries in fear of letting in terrorists.

Actually I would rep+ if it let me. The engine executes only what it is told to, limiting it would only hold back its maximum potential. This is why only trusted person(s) should be allowed access.

Tricxta
07-29-2012, 03:46 AM
Limiting scripting functionality in fear of what abuse/poor scripting could cause is a horrible approach.

I'll probably pick up a negative rep or two for the following comment, but it'd be like not allowing immigrants from middle eastern countries in fear of letting in terrorists.
Fair call, i'll +rep.

edit: (when I can...)

cbk1994
07-29-2012, 10:11 AM
Limiting scripting functionality in fear of what abuse/poor scripting could cause is a horrible approach.

With that said, I wish it was possible to control things like this better. It bothers me that any random LAT can delete every weapon on the server, drop all my SQL tables, spawn money or items, etc.

xXziroXx
07-29-2012, 10:39 AM
With that said, I wish it was possible to control things like this better. It bothers me that any random LAT can delete every weapon on the server, drop all my SQL tables, spawn money or items, etc.

I agree, but I don't think limiting the language is the right approach.

MattKan
07-29-2012, 04:47 PM
I agree, but I don't think limiting the language is the right approach.

I didn't know this before, and I'll have to admit it makes me just a little bit nervous. Do you know how I could go about overriding that command, and if possible only for scripts starting with certain names?

cbk1994
07-29-2012, 10:29 PM
I didn't know this before, and I'll have to admit it makes me just a little bit nervous. Do you know how I could go about overriding that command, and if possible only for scripts starting with certain names?

public function destroy() {
echo("no");
}

A better solution is to simply make routine backups.

Skyld
07-29-2012, 10:55 PM

function destroy() {
echo("no");
}

A better solution is to simply make routine backups.
Maybe that wants to be a public function.

Bleachlover551
07-30-2012, 02:10 AM
Maybe that wants to be a public function.

its an honor to have you comment i admire u you (no homo) ^^

scriptless
07-30-2012, 03:04 AM

public function destroy() {
echo("no");
}

A better solution is to simply make routine backups.

I wasn't sure how to override functions. This could be useful:o

And yeah backups would definitely be best. As for the LAT thing, It would be rather simple to have lat's upload to a folder only they can, and then checked/moved by an admin. It could be simple to script a GS2 checker to see if it uses certain functions by scanning the level as a file first.

cbk1994
07-30-2012, 03:06 AM
It could be simple to script a GS2 checker to see if it uses certain functions by scanning the level as a file first.

It's a lot more difficult than you would think.

Bleachlover551
07-30-2012, 03:30 AM
Agreed ^,^

MattKan
07-30-2012, 07:26 AM
It's a lot more difficult than you would think.

That should be your next project- something that allows people to block certain functions unless they are coming from certain scripts.

cbk1994
07-30-2012, 08:53 AM
That should be your next project- something that allows people to block certain functions unless they are coming from certain scripts.

This is not possible. The best you can do is a scanner that looks for things that look unsafe in a level, and these are difficult to make. Time is better spent elsewhere.

xXziroXx
07-30-2012, 12:37 PM
Do regular backups and limit write rights off (npcserver). Problem solved.

scriptless
07-30-2012, 07:12 PM
This is not possible. The best you can do is a scanner that looks for things that look unsafe in a level, and these are difficult to make. Time is better spent elsewhere.

Actually I made a program back in 2007 using Delphi that scanned levels, it wasn't to hard to have it find certain text within and count the number of occurances.. However making it remove them is indeed difficult.. Think find position within a substring.. Was all I did tho.. But your right time is better spent elsewhere. I personally recommend the temp folder with admins checking to prevent abuse..

Crow
07-30-2012, 07:33 PM
Actually I made a program back in 2007 using Delphi that scanned levels, it wasn't to hard to have it find certain text within and count the number of occurances.. However making it remove them is indeed difficult.. Think find position within a substring..

Replacing occurrences of something in a string is rather easy, just use regular expressions. That's not the problem though. Programs/scripts like that are easily avoided. If you really want to cause harm, you'll be able to get past such protection. It's just impossible to efficiently check for malicious code.

Bleachlover551
07-30-2012, 08:56 PM

Reason: Got All Help I Needed And No Futher Questions At This Moment ^^

cbk1994
07-30-2012, 09:02 PM

Reason: Got All Help I Needed And No Futher Questions At This Moment ^^

You don't need to request for a thread to be locked. The thread belongs to the community now, not to you. People will stop posting in the thread without it being locked. Locking threads is a last resort by the moderators and is not routinely done.

Bleachlover551
07-30-2012, 09:09 PM
You don't need to request for a thread to be locked. The thread belongs to the community now, not to you. People will stop posting in the thread without it being locked. Locking threads is a last resort by the moderators and is not routinely done.

Sorry I didn't know that. Also how does the community own my thread?

Imperialistic
07-30-2012, 09:26 PM
Sorry I didn't know that. Also how does the community own my thread?

to prevent future upset; graal tends to take ownership for everything you post/create/develop.

cbk1994
07-31-2012, 04:31 AM
Sorry I didn't know that. Also how does the community own my thread?

There are 34 posts and only 8 of them are yours. Threads aren't the exclusive property of the OP, which is why you can't just delete posts in your threads that you don't like, or (generally) request for it to be locked. This is standard practice across most internet discussion boards.

Bleachlover551
08-02-2012, 08:34 PM
Oh i get it lol (the truth is obvisous lol) i spelt that wrong >.<