Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   My First Code in the Gallery -spar (https://forums.graalonline.com/forums/showthread.php?t=74552)

theHAWKER 06-12-2007 04:57 PM

My First Code in the Gallery -spar
 
Umkay, this is a spar script and you would place the npc in the center of ur spar

commands:
Focus = to turn on focus
Focus off = to turn off focus
Start = to start count down
/In = to enter spar
/out = to leave spar
End = to stop the count down

PHP Code:

//#CLIENTSIDE
function onPlayerChats(){
  if (
player.chat=="focus"){
    
setfocus(30.5,25);//the center of ur spar
  
}
  if (
player.chat=="focus off"){
    
resetfocus();
  }
  if(
playerx>12 && playerx<52){//first x is the top left corner of ur spar quare and the second is the botem right
    
if(playery>13 && playery<41){//same for here accept its y
      
if (player.chat=="start"){//place this npc in the middle of ur spar
        
this.chat "You have 5 seconds untill start!";
        
sleep(2);
        
this.chat "3";
        
sleep(1);
        
this.chat "2";
        
sleep(1);
        
this.chat "1";
        
sleep(1);
        
this.chat "Spar!";
        
sleep(1);
        
this.chat "Spar";
        
sleep(.1);
        
this.chat "pa";
        
sleep(.1);
        
this.chat "";
      }
      if (
player.chat=="end"){
        
this.chat "";
      }
    }
  }
  if (
player.chat=="/in"){
    
enableweapons();
    
disablepause();
    
player.30.5;//middle of ur spar
    
player.25.5;//middle of ur spar
  
}
  if (
player.chat=="/out"){
    
enablepause();
    
disableweapons();
    
player.30.5;//the out side of ur spar
    
player.46;//the out side of ur spar
  
}
  if (
player.chat=="heal"){
    
player.hearts player.fullhearts;
  }
}
function 
onPlayerDies(){
  
player.30.5;//the out side of ur spar
  
player.46;//the out side of ur spar
}
function 
onPlayerEnters(){
  
enablepause();
  
disableweapons();
}
function 
onPlayerLeaves(){
enablepause();
enableweapons();



u just have to replace the x and y coordinates

Chompy 06-12-2007 05:38 PM

A good start :)
I would just do something about that you can say /heal when you're inside the fighting area though :)

Grey 06-12-2007 07:10 PM

Not a bad start. There is a bracket missing at the very end of the code, but I suspect maybe you accidently cut that off when you pasted the code?

In terms of improving scripting style/optimizing the script I'd suggest looking into switch statements maybe to avoid using so many if statements for checking the chat.

ie.

PHP Code:

if (player.chat == cmd) {
  switch (
cmd) {
    case 
"start": {
    
//stuff that happens when the player says start here.
    
break;
    }
    case 
"/in": {
    
//stuff for 'in' here
    
break;
    }
  }


And also when you check the player's x and y for starting the spar the way you have done it is okay, but it would be better to have done:

PHP Code:

if (player.x in |12,52| && player.y in |13,41|) { 
//stuff here



xAndrewx 06-12-2007 07:53 PM

Why is it clientside?

theHAWKER 06-13-2007 03:53 AM

Quote:

Originally Posted by Chompy (Post 1317385)
A good start :)
I would just do something about that you can say /heal when you're inside the fighting area though :)

I just use a trust system xD

Quote:

Originally Posted by xAndrewx (Post 1317418)
Why is it clientside?

i dont think it works server side...

xAndrewx 06-13-2007 08:33 AM

You're aware that you can't edit your hearts clientside and once you say start, only YOU can see the message?

theHAWKER 06-13-2007 04:58 PM

Quote:

Originally Posted by xAndrewx (Post 1317613)
You're aware that you can't edit your hearts clientside and once you say start, only YOU can see the message?

it works fine for me :(

Twinny 06-14-2007 09:40 AM

Did you test it out with anyone? You may have seen the message but since it is clientside, the other person wouldn't see anything.

As Andrew said, hearts cannot be set clientside no matter what. Triggers are needed as only serverside can right to the variable.

theHAWKER 06-15-2007 02:40 AM

Quote:

Originally Posted by Twinny (Post 1317878)
Did you test it out with anyone? You may have seen the message but since it is clientside, the other person wouldn't see anything.

well good for my first almost working script (in GS2) xD

ff7chocoboknight 07-12-2007 12:47 AM

the first enablepause() should be disablepause()

I've noticed that this is a script from graal.net converted into GS2


All times are GMT +2. The time now is 08:21 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.