Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   General Graal Discussion (https://www.graalians.com/forums/forumdisplay.php?f=2)
-   -   Script Help (https://www.graalians.com/forums/showthread.php?t=7064)

The Doctor 06-02-2012 12:26 AM

Script Help
 
I have a simple drag script and was wondering how to freeze the player being dragged through the air with freezeplayer2();. Any suggestions?

Twinny 06-02-2012 03:24 AM

You could do it in a few ways. Set a variable like client.isfrozen which can be read client side and checked in a time out. If true, freeze otherwise don't. This variable could be used in other scripts as well. You would have to make sure you unset the variable when player logins in case they disconnect whilst being dragged.

Another option is to trigger the player when they need to be frozen. This could be part of a weapon e.g. 'Movement' or 'System' or even in a class the player object has joined I.e. player.freezeplayer(int) which will trigger client side and then freeze the player. You would then have another option to unfreeze them. This way means no timeouts so less CPU time.

The Doctor 06-02-2012 03:31 AM

Thank you (+rep). Also, I've removed opening a player's profile so I can add some player options to them. I want a drop down GUI to pop up next to the player when I right click them. Is there an if() statement to detect if someone right clicked their mouse on the player?

Twinny 06-02-2012 03:47 AM

Nothing like that. Instead, you can use findnearestplayer(float x, float y) in a function onMouseDown e.g.

PHP Code:

Function onMouseDown(mode) {
  If (
mode == "left") {
    
Temp.pl findnearestplayer(mousexmousey);
     
Player.chat format("%s was clicked"temp.pl.communityname);
    }
  } 

You could also use findnearestplayers which returns an array of close players.

Note: there won't be a limit on range. If you only want players within 5 tiles, you will either need to test distance using the returned obj(s) or custom function e.g.

PHP Code:

For (temp.pl players) {
  If (
temp.pl.x in |mousex-2.5mousex+2.5|) {
    If (
temp.pl.y in |mousey-2.5mousey+2.5) {
      
//woo
    
}
  }


Depends how you want to go

The Doctor 06-02-2012 03:52 AM

That's all! Thank you.

The Doctor 06-05-2012 01:06 AM

New question. I have a small bar with NPCs in it. I only want staff to go through the npc door that warps you to the other level. So far, I have the tag Owner to be able to warp. It works, but I want it to work for all the staff specified in the server options. Here's what I have so far. I'm thinking it was an if() statement in there somewhere.

PHP Code:

if (player.guild == "Owner") {
//warp script here



Twinny 06-05-2012 01:13 AM

Quote:

Posted by Shawn (Post 133873)
New question. I have a small bar with NPCs in it. I only want staff to go through the npc door that warps you to the other level. So far, I have the tag Owner to be able to warp. It works, but I want it to work for all the staff specified in the server options. Here's what I have so far. I'm thinking it was an if() statement in there somewhere.

PHP Code:

if (player.guild == "Owner") {
//warp script here



I think you should be able to use serveroptions.staff serverside sooo

PHP Code:

if (player.guild in serveroptions.staff) {
  
doStuff();


That said, I'm not sure if it is serveroptions. or something. Test and see what you get.

The Doctor 06-05-2012 02:27 AM

You've been a great help :)
I'll test it right away

I tested it, didn't work. I think it's because instead of player.guild, it should be the player's community name/graal ID.

Tricxta 06-05-2012 02:44 AM

Quote:

Posted by Shawn (Post 133913)
You've been a great help :)
I'll test it right away

I tested it, didn't work. I think it's because instead of player.guild, it should be the player's community name/graal ID.

Nah, I understand where twinny is comming from. You're basically checking if the players guild is a staff guild defined in serveroptions, your alternate way also works(using player.account) and has a better chance of working since not everyone bothers defining staff guilds though. Gl with whatever abuse it is that you're creating.

The Doctor 06-05-2012 02:45 AM

It's a door? What abuse am I creating with a staff room?

Thanks anyway.

Tricxta 06-05-2012 02:46 AM

Quote:

Posted by Shawn (Post 133922)
It's a door? What abuse am I creating with a staff room?

Thanks anyway.

You'd be suprised what you can make a door do in graal.

The Doctor 06-05-2012 02:47 AM

"You must spread some reputation before giving it to Tricxta again"

Quote:

Posted by Tricxta (Post 133923)
You'd be suprised what you can make a door do in graal.

Ban players when they walk into it? Nah, haha.

Tricxta 06-05-2012 02:49 AM

Quote:

Posted by Shawn (Post 133924)
"You must spread some reputation before giving it to Tricxta again"



Ban players when they walk into it? Nah, haha.

I was actually thinking of a door that attacks people if they're not staff and try use it. Your idea works to :smile:

The Doctor 06-05-2012 02:51 AM

PHP Code:

function onPlayerTouchsMe(){
if (
player.guild in serveroptions.staff) {
setlevel2("futustia-bar.nw"10.544.5);
player.dir 2;
}
else {
player.chat "I need an admin tag!";
}


Here's my ifelse so far. What did I do wrong? I was wearing my owner tag specified in the server options.

BboyEatsbacon 06-05-2012 03:07 AM

Quote:

Posted by Shawn (Post 133928)
PHP Code:

function onPlayerTouchsMe(){
if (
player.guild in serveroptions.staff) {
setlevel2("futustia-bar.nw"10.544.5);
player.dir 2;
}
else {
player.chat "I need an admin tag!";
}


Here's my ifelse so far. What did I do wrong? I was wearing my owner tag specified in the server options.

Should be
PHP Code:

function onPlayerTouchsMe(){
  if (
player.guild in serveroptions.staffguilds) {
    
setlevel2("futustia-bar.nw"10.544.5);
    
player.dir 2;
  }
  else {
    
player.chat "I need an admin tag!";
  }


PHP Code:

serveroptions.staff 

is a string that all of the server staff are stored in.

PHP Code:

serveroptions.staffguilds 

is a string that all of the server staff guilds are stored in.

The Doctor 06-05-2012 03:23 AM

I have summed this up by doing this:
PHP Code:

function onPlayerTouchsMe(){
if (
player.account in serveroptions.staff) {
setlevel2("futustia-bar.nw"10.544.5);
player.dir 2;
}
else {
player.chat "I am not staff. I cannot be in this bar.";
}


I have learned alot being around you guys <3

Twinny 06-05-2012 10:10 AM

Lol whoops. My bad on that one :-)

The Doctor 06-06-2012 02:17 AM

Amazing what you can do with scripts. I made an NPC in a small staff room guarded by that staff only script. The NPC inside gives whoever touches it the default staff weapons.

Twinny 06-06-2012 09:31 AM

Quote:

Posted by Shawn (Post 134498)
Amazing what you can do with scripts. I made an NPC in a small staff room guarded by that staff only script. The NPC inside gives whoever touches it the default staff weapons.

O_o thats not a good method. Players can memory edit level links to warp them anywhere. You should only add staff weapons via RC

The Doctor 06-06-2012 11:27 AM

I though't I'd be easier. I can always make the Control NPC add weapons to staff when they log in.

Emera 06-06-2012 12:01 PM

Quote:

Posted by Shawn (Post 134815)
I though't I'd be easier. I can always make the Control NPC add weapons to staff when they log in.

That'd be your best bet. Just list them in an array and add them to the staff members as they login.
PHP Code:

for (wep this.staff_weps) {
  if (
player.clientr.isStaffplayer.addweapon(wep);


Obviously, you'll have to set up giving staff the clientr.isStaff flag so it knowns if to add weapons or not. You could always read from serveroptions.staff and check if their account is inside the list.

PHP Code:

temp.staff serveroptions.staff.tokenize(",");
if (
player.account in temp.staff || player.communityname in temp.staff) {
  
player.clientr.isStaff true;


And I don't want to be the one to nag, but you really need to learn how to style your code. You can read into decent styling techniques in this official forums thread by Skyld, and you can also use FP4's GS2 beautifier. Obviously, styling code is pretty much personal preference, but it makes it easier to read if you adapt to using a clean and readable style so other coders can look through it with ease. Other than that, good job. You're making progress.

The Doctor 06-06-2012 10:31 PM

I don't like indenting my code. Tried it in PHP, didn't make a difference to me. But I'll try from now on :)

xXziroXx 06-07-2012 12:10 AM

Quote:

Posted by Emera (Post 134830)
PHP Code:

for (wep this.staff_weps) {
  if (
player.clientr.isStaffplayer.addweapon(wep);



Don't ever do that. It's -really- important to assign wep as a temporary variable, right now it's not. It's also very important to name your variables logically instead of taking shortcuts in order to get the names as short as possible. You'll thank me for that last piece of advice in a year or two when you go back and look at your old code.

There's little to no reason to keep the weapon list stored in a permanent array, so I'd change that too to a temporary one.

I also hate that styling, but then again it comes down to personal preference in this case.

Correct way, with my personal touch to it:

PHP Code:

temp.listOfStaffWeapons = {
  
"Weapon1",
  
"Weapon2",
  
"Weapon3"
}

for (
temp.weaponNametemp.listOfStaffWeapons) {
  if (
player.clientr.isStaff)
    
player.addWeapon(temp.weaponName);




Quote:

Posted by Shawn (Post 135127)
I don't like indenting my code. Tried it in PHP, didn't make a difference to me. But I'll try from now on :)

Good luck getting anywhere on Graal as a programmer without using proper indenting and styling.

The Doctor 06-07-2012 02:14 AM

What difference does it make, other than making it pretty?

BboyEatsbacon 06-07-2012 02:31 AM

Quote:

Posted by Shawn (Post 135283)
What difference does it make, other than making it pretty?

  • Easier to refer back to
  • Can read without being easily thought scattered
  • Looks Neat
  • Programmers will hate you if you don't

The Doctor 06-07-2012 02:35 AM

Quote:

Posted by BboyEatsbacon (Post 135301)
  • Programmers will hate you if you don't

I could imagine Skyld raging at me or something O.o

xXziroXx 06-07-2012 02:37 AM

Quote:

Posted by Shawn (Post 135307)
I could imagine Skyld raging at me or something O.o

Skyld wouldn't accept a script like that to be uploaded to begin with.

The Doctor 06-07-2012 02:40 AM

It's because I'm beginner and he expects something that comes from a pro.

Skyld 06-08-2012 02:17 AM

Quote:

Posted by Shawn
It's because I'm beginner and he expects something that comes from a pro.

Actually it's because I'm not going to waste my time trying to make heads or tails of terribly formatted code, not because you are a beginner, but because it's just hard to read. If you format your code properly, it makes it easier for other people to understand, and as a result, we will be more willing to help you.

xXziroXx 06-08-2012 02:30 AM

Quote:

Posted by Skyld (Post 136085)
Actually it's because I'm not going to waste my time trying to make heads or tails of terribly formatted code, not because you are a beginner, but because it's just hard to read. If you format your code properly, it makes it easier for other people to understand, and as a result, we will be more willing to help you.

Oh wow, it has an account here! I am surprised.

Twinny 06-08-2012 02:47 AM

Quote:

Posted by xXziroXx (Post 136088)
Oh wow, it has an account here! I am surprised.

What the... GET A BROOM! *thwacks Skyld with a broom* SHOO

On a more serious note, everything Skyld said is true. Proper indenting allows us to quickly follow the flow of a script. Without it, it's frustrating and I know I give up in 2 seconds.

The Doctor 06-08-2012 02:55 AM

Well, I will format it then.

PHP Code:

function*onPlayerTouchsMe() {
  if* (
player.accountin *serveroptions.staff)* {
    
setlevel2("futustia-bar_side.nw", *10.5, *44.5);
    
player.dir* = *2;
  } else* {
    
player.chat* = *"I*am*not*staff.*I*cannot*be*in*this*bar.";
  }
}* 

fp4's script added a lot of asterisks 0.o

Skyld 06-08-2012 03:08 AM

Quote:

Posted by xXziroXx (Post 136088)
Oh wow, it has an account here! I am surprised.

"It" has had an account here longer than you have!
Quote:

Posted by Twinny
What the... GET A BROOM! *thwacks Skyld with a broom* SHOO

I cry.
Quote:

Posted by Shawn
fp4's script added a lot of asterisks 0.o

They should not be there.

xXziroXx 06-08-2012 03:12 AM

Quote:

Posted by Skyld (Post 136106)
"It" has had an account here longer than you have!

Older != Better :rolleyes:

I'm with Twinny on this one, broom time! Skyld begone, SUPER SKYLD COME FOURTH!!!

P.s. how was your marriage with Elk?

callimuc 06-08-2012 01:47 PM

Quote:

Posted by xXziroXx (Post 136107)
P.s. how was your marriage with Elk?

o,O what did I miss?

Skyld 06-08-2012 01:56 PM

Quote:

Posted by xXziroXx (Post 136107)
P.s. how was your marriage with Elk?

Kind of hilarious actually. I am still getting PMs even now from players congratulating me... on a virtual marriage...

callimuc 06-08-2012 01:56 PM

Quote:

Posted by Skyld (Post 136365)
Kind of hilarious actually. I am still getting PMs even now from players congratulating me... on a virtual marriage...

Congratulations

Skyld 06-08-2012 01:57 PM

Quote:

Posted by callimuc (Post 136366)
Congratulations

OH MY GOD THANK YOU

callimuc 06-08-2012 01:58 PM

Quote:

Posted by Skyld (Post 136367)
OH MY GOD THANK YOU

U B ALWAIS WELCOM :blush:

xXziroXx 06-09-2012 03:07 AM

Quote:

Posted by callimuc (Post 136368)
U B ALWAIS WELCOM :blush:

WITH ELK HE'S GUNNA BE WELCUM, LOL

callimuc 06-09-2012 01:07 PM

Quote:

Posted by xXziroXx (Post 136661)
WITH ELK HE'S GUNNA BE WELCUM, LOL

YA 24/7 WIL ALWIS HAV A CUP OF TEA 4 HIM!!1!

The Doctor 06-09-2012 03:29 PM

Did I make a party?

callimuc 06-09-2012 09:40 PM

Quote:

Posted by Shawn (Post 136935)
Did I make a party?

YAMAN!


All times are GMT. The time now is 03:16 AM.

Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.