Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-09-2012, 06:28 AM
Fatel Fatel is offline
Worlds Connected Dev
Join Date: Jun 2012
Posts: 18
Fatel is an unknown quantity at this point
GS2 Flamethrower

could never find a gs2 flamethrower, so i made my own and decided to post it


PHP Code:
//Scripted by Fatel
//#CLIENTSIDE

function getCoordinates(xOffsetyOffset)
{
  if (
player.dir == 0)
  {
    
this.player.0.5;
    
this.player.yOffset;
  }
  elseif (
player.dir == 1)
  {
    
this.playerx xOffset;
    
this.player.0.5;
  }
  elseif (
player.dir == 2)
  {
    
this.player.0.5;
    
this.player.yOffset;
  }
  elseif (
player.dir == 3)
  {
    
this.player.xOffset;
    
this.player.0.5;
  }
}
function 
onWeaponFired()
{
  
setani("shoot",NULL);
  
getCoordinates(77)
  if(
player.dir == 3){

  
putexplosion 0.8,player.x+3,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+4,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+5,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+6,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+7,player.y+1;
  
sleep 0.01;
  
putexplosion  0.5,player.x+8,player.y+1;
  
sleep 0.01;
  
putexplosion  0.5,player.x+9,player.y+1;
  
sleep 0.01;
  
putexplosion  0.5,player.x+10,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+11,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x+12,player.y+1;


 }
if(
player.dir == 1){
 
putexplosion 0.5,player.x-2,player.y+1;
 
sleep 0.01;
  
putexplosion 0.5,player.x-4,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-5,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-6,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-7,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-8,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-9,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-10,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-11,player.y+1;
  
sleep 0.01;
  
putexplosion 0.5,player.x-12,player.y+1;


}
if(
player.dir == 2){
 
putexplosion 0.5,player.x+0.8,player.y+3;
 
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+4;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+5;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+6;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+7;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+8;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+9;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+10;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+11;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.8,player.y+12;


}
if(
player.dir == 0){
 
putexplosion 0.5,player.x+0.6,player.y-2;
 
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-4;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-5;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-6;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-7;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-8;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-9;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-10;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-11;
  
sleep 0.01;
  
putexplosion 0.5,player.x+0.6,player.y-12;
}


Last edited by Fatel; 07-09-2012 at 11:21 AM..
Reply With Quote
  #2  
Old 07-09-2012, 06:31 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Awesome code dude.
Reply With Quote
  #3  
Old 07-09-2012, 06:43 AM
Fatel Fatel is offline
Worlds Connected Dev
Join Date: Jun 2012
Posts: 18
Fatel is an unknown quantity at this point
Lol its nothing much i thought there should be an ONLINE flamethrower in the code gallery.
Reply With Quote
  #4  
Old 07-09-2012, 09:02 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Pardon me if i'm wrong but doesn't graal only run at 20 fps making sleeping for 0.01 seconds impossible?

Also you say this is GS2 but why aren't there any brackets around your sleep or putexplosion statements.

Annnd of what use does get coordinates even serve?

love,
tricxta
Reply With Quote
  #5  
Old 07-09-2012, 09:47 AM
Fatel Fatel is offline
Worlds Connected Dev
Join Date: Jun 2012
Posts: 18
Fatel is an unknown quantity at this point
by "gs2" i mean its usable online, there IS gs1 commands, however the entire point of me posting this is to give players an online flamethrower, whether its 100% perfect or not. i understand theres some
non used commands, but if it works, no matter right?
Reply With Quote
  #6  
Old 07-09-2012, 10:52 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
We really appreciate that you're posting in the code gallery and that you're intersted in helping other scripters. At this point, though, the script has some errors in it that make it unsuitable to be posted here. There's lots of scripters here who are happy to give you feedback on scripts; a good idea would be to post your threads in one of the other subforums (e.g. the GS2 subforum) before posting it here to get feedback. Generally we try to keep the Code Gallery free of erroneous scripts so that it can be used as a learning resource.

The most important thing to do when posting your scripts is to make sure they're properly styled/indented. There's a tool that will do it for you, but eventually you'll want to get good at indenting your code as you write it. This makes it a lot easier to read and to spot problems in the code.

PHP Code:
//Scripted by Fatel
//#CLIENTSIDE
function getCoordinates(xOffsetyOffset) {
  if (
player.dir == 0) {
    
this.player.0.5;
    
this.player.yOffset;
  }
  elseif(
player.dir == 1) {
    
this.playerx xOffset;
    
this.player.0.5;
  }
  elseif(
player.dir == 2) {
    
this.player.0.5;
    
this.player.yOffset;
  }
  elseif(
player.dir == 3) {
    
this.player.xOffset;
    
this.player.0.5;
  }
}

function 
onWeaponFired() {
  
setani("shoot"NULL);
  
getCoordinates(77)
  if (
player.dir == 3) {
    
putexplosion 0.8player.3player.1;
    
sleep 0.01;
    
putexplosion 0.5player.4player.1;
    
sleep 0.01;
    
putexplosion 0.5player.5player.1;
    
sleep 0.01;
    
putexplosion 0.5player.6player.1;
    
sleep 0.01;
    
putexplosion 0.5player.7player.1;
    
sleep 0.01;
    
putexplosion 0.5player.8player.1;
    
sleep 0.01;
    
putexplosion 0.5player.9player.1;
    
sleep 0.01;
    
putexplosion 0.5player.10player.1;
    
sleep 0.01;
    
putexplosion 0.5player.11player.1;
    
sleep 0.01;
    
putexplosion 0.5player.12player.1;
  }
  if (
player.dir == 1) {
    
putexplosion 0.5player.2player.1;
    
sleep 0.01;
    
putexplosion 0.5player.4player.1;
    
sleep 0.01;
    
putexplosion 0.5player.5player.1;
    
sleep 0.01;
    
putexplosion 0.5player.6player.1;
    
sleep 0.01;
    
putexplosion 0.5player.7player.1;
    
sleep 0.01;
    
putexplosion 0.5player.8player.1;
    
sleep 0.01;
    
putexplosion 0.5player.9player.1;
    
sleep 0.01;
    
putexplosion 0.5player.10player.1;
    
sleep 0.01;
    
putexplosion 0.5player.11player.1;
    
sleep 0.01;
    
putexplosion 0.5player.12player.1;
  }
  if (
player.dir == 2) {
    
putexplosion 0.5player.0.8player.3;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.4;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.5;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.6;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.7;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.8;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.9;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.10;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.11;
    
sleep 0.01;
    
putexplosion 0.5player.0.8player.12;
  }
  if (
player.dir == 0) {
    
putexplosion 0.5player.0.6player.2;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.4;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.5;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.6;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.7;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.8;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.9;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.10;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.11;
    
sleep 0.01;
    
putexplosion 0.5player.0.6player.12;
  }

I originally rewrote the getCoordinates function, but after glancing at the script, it turns out it's not actually being used for anything; the positions it calculates are never used in the script, so we can just cut it out.

The first main problem that stands out is that you're using GS1 syntax for the putexplosion and sleep commands. The proper way to write these commands is to surround the parameters with parentheses, like this:

PHP Code:
    putexplosion(0.8player.3player.1);
    
sleep(0.01);
    
putexplosion(0.5player.4player.1);
    
sleep(0.01); 
The next problem is that, as Tricxta pointed out, the Graal client runs at 20 FPS; as such, the most you can sleep for is one frame (1/20th of a second = 0.05 seconds).

PHP Code:
    putexplosion(0.8player.3player.1);
    
sleep(0.05);
    
putexplosion(0.5player.4player.1);
    
sleep(0.05); 
The script right now calls the same commands over and over in a predictable way; we can use loops to avoid having to write every single explosion out. The pattern is that the explosions move 1 tile farther in the direction of the player with every iteration (there's 10 of them). There are a few inconsistencies (likely mistakes), but we can ignore them and do something like this:

PHP Code:
  if (player.dir == 3) {
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.temp.iplayer.1);
      
sleep(0.05);
    }
  } 
in place of:

PHP Code:
  if (player.dir == 3) {
    
putexplosion 0.8player.3player.1;
    
sleep 0.01;
    
putexplosion 0.5player.4player.1;
    
sleep 0.01;
    
putexplosion 0.5player.5player.1;
    
sleep 0.01;
    
putexplosion 0.5player.6player.1;
    
sleep 0.01;
    
putexplosion 0.5player.7player.1;
    
sleep 0.01;
    
putexplosion 0.5player.8player.1;
    
sleep 0.01;
    
putexplosion 0.5player.9player.1;
    
sleep 0.01;
    
putexplosion 0.5player.10player.1;
    
sleep 0.01;
    
putexplosion 0.5player.11player.1;
    
sleep 0.01;
    
putexplosion 0.5player.12player.1;
  } 
If we do this for every direction, the script gets a lot cleaner:

PHP Code:
//Scripted by Fatel
//#CLIENTSIDE
function onWeaponFired() {
  
setani("shoot"NULL);
  
  if (
player.dir == 3) {
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.temp.iplayer.1);
      
sleep(0.05);
    }
  } else if (
player.dir == 1) {
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.temp.iplayer.1);
      
sleep(0.05);
    }
  } else if (
player.dir == 2) {
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.0.8player.temp.i);
      
sleep(0.05);
    }
  } else if (
player.dir == 0) {
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.0.6player.temp.i);
      
sleep(0.05);
    }
  }

Note that I'm also using else-if, as it makes it easier for the scripter (and the interpreter) to follow the execution of the code. There are some other ways to make this script cleaner, such as using the vector position functions, that you may want to look at if you're interested in learning.

Quote:
Originally Posted by Fatel View Post
by "gs2" i mean its usable online, there IS gs1 commands, however the entire point of me posting this is to give players an online flamethrower, whether its 100% perfect or not. i understand theres some
non used commands, but if it works, no matter right?
The main purpose of the scripting forums, including the Code Gallery, is to help others learn, not to provide ready-made scripts to be used on servers (this is the secondary purpose). When you post incomplete or erroneous code, it introduces the possibility that a new scripter will look at it and learn the wrong way to do things.

Generally we'd prefer it if you would avoid posting code like this in the Code Gallery, and instead post it in the GS2 subforum first for feedback.
__________________
Reply With Quote
  #7  
Old 07-09-2012, 11:11 AM
Fatel Fatel is offline
Worlds Connected Dev
Join Date: Jun 2012
Posts: 18
Fatel is an unknown quantity at this point
I understand what your saying, duly noted. ill be sure not to post ready to use scripts in the future.

Last edited by Fatel; 07-09-2012 at 11:23 AM..
Reply With Quote
  #8  
Old 07-09-2012, 11:33 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Fatel View Post
I understand what your saying, duly noted. ill be sure not to post ready to use scripts in the future.
There's nothing wrong with posting scripts that can be used, just be sure that they don't have errors in them that could confuse new scripters. You can always post a thread asking for feedback on your scripts before posting in the Code Gallery .
__________________
Reply With Quote
  #9  
Old 07-09-2012, 11:42 AM
Fatel Fatel is offline
Worlds Connected Dev
Join Date: Jun 2012
Posts: 18
Fatel is an unknown quantity at this point
lol, got it.
Reply With Quote
  #10  
Old 07-09-2012, 12:07 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Let's simplify it even further!!
PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
  
temp.offSets = {{0.6,-2},{-2,1},{0.8,3},{3,1}};
  
setani("shoot"NULL);
  
  for (
temp.0;temp.4;temp.d++){
    for (
temp.0temp.10temp.++) {
      
putexplosion(0.5player.temp.offSets[temp.d][0] + vecx(temp.d)*temp.iplayer.temp.offSets[temp.d][1] + vecy(temp.d)*temp.i);
      
sleep(0.05);
    }
  } 

Oh damn, we're going all out!
Reply With Quote
  #11  
Old 07-09-2012, 03:01 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Tricxta, you're lacking the conditions for the direction of the player, so your code would always fire in all four directions. Also, you can save a loop there.
Reply With Quote
  #12  
Old 07-10-2012, 07:46 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Soz, I got excited
PHP Code:
//#CLIENTSIDE
function onWeaponFired() {
  
temp.offSets = {{0.6,-2},{-2,1},{0.8,3},{3,1}};
  
setani("shoot"NULL);
  
  for (
temp.0temp.10temp.++) {
    
putexplosion(0.5player.temp.offSets[player.dir][0] + vecx(player.dir)*temp.iplayer.temp.offSets[player.dir][1] + vecy(player.dir)*temp.i);
    
sleep(0.05);
  } 

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:05 PM.


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