Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Some more scripts+help on sword/gun script. (https://forums.graalonline.com/forums/showthread.php?t=87366)

Liberated 08-11-2009 04:41 PM

Some more scripts+help on sword/gun script.
 
Okay, so i have made some more scripts, with the help of a friend aswell, and now i want to make a sword or gun script, and i have found some scripts on testbed to analize, and the help people gave on gultex his script in the code gallery, but im not understanding what to do, i understand the stuff with the playerdirections and with the shoot command, but i don't understand how to make the sword, or bullet hit the player.

anyways here are the scripts i made.
I'd like to know if i did anything wrong, or could've done anything better.

Bombscript that puts an explosion +-7 yards from the player:
PHP Code:

//#CLIENTSIDE

if (playerdir=0)
{
  
this.x=playerx+0.5;
  
this.y=playery-7;
}
if (
playerdir=1)
{
  
this.x=playerx-7;
  
this.y=playery+0.5;
}
if (
playerdir=2)
{
  
this.x=playerx+0.5;
  
this.y=playery+7;
}
if (
playerdir=3)
{
  
this.x=playerx+7;
  
this.y=playery+0.5;
}
function 
onWeaponFired()
{
  
setani("lift"Null);
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!";


i added the freezeplayer because otherwise i ran into my own explosino and hurt myself.

Rotating script, i need some help on this one too, because i failed to make a loop, and i want to make it so that the player keeps rotating on his own when i fire once.
PHP Code:

//#CLIENTSIDE
function onWeaponFired()
{
  for(
playerdir>0)
  { 
    
playerdir+=1;
  }
  for (
playerdir==3)
  {
    
playerdir-=3;
  }


Friend told me to try and make an explosion at a mouseclick, and at the location of my mouse:
PHP Code:

//#CLIENTSIDE
function onMouseDown()
{
  
setani("lift"Null);
  
putexplosion2(1,2,mousex,mousey);
  
player.chat "Kaboom!";


Now i figured out how i could use my mouse, i decided to make a mousewarper, which was unbelievably easy.
PHP Code:

//#CLIENTSIDE
function onMouseDown()
{
  
player.mousex;
  
player.mousey;


decided to make something fun
PHP Code:

//#CLIENTSIDE
function onMouseDown()
{
  
player.mousex;
  
player.mousey;
  
setani("lift"Null);
  
putexplosion2(1,2,mousex+2.5,mousey+2.5);
  
putexplosion2(1,2,mousex-1,mousey+2.5);
  
putexplosion2(1,2,mousex+2.5,mousey-1);
  
putexplosion2(1,2,mousex-1,mousey-1);
  
putexplosion2(1,2,mousex+7,mousey+0.5);
  
putexplosion2(1,2,mousex-7,mousey+0.5);
  
putexplosion2(1,2,mousex+.5,mousey-7);
  
putexplosion2(1,2,mousex+.5,mousey+7);
  
player.chat "Kaboom!";
  
freezeplayer(.71);


edit:
sorry thought i was in the GS2 forum, should've been posted there.

Codein 08-11-2009 10:14 PM

Quote:

Originally Posted by Liberated (Post 1514174)
Scripts.


PHP Code:

//#CLIENTSIDE

if (playerdir=0)
{
  
this.x=playerx+0.5;
  
this.y=playery-7;
}
if (
playerdir=1)
{
  
this.x=playerx-7;
  
this.y=playery+0.5;
}
if (
playerdir=2)
{
  
this.x=playerx+0.5;
  
this.y=playery+7;
}
if (
playerdir=3)
{
  
this.x=playerx+7;
  
this.y=playery+0.5;
}
function 
onWeaponFired()
{
  
setani("lift"Null);
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!";


First thing that really stood out to me was the fact you're using the assignment operator for equal comparisons. You should be using this operator:

'=='

Also, you have the if statements, which are meant to be checking conditions and a comparison , should be made inside a block of code. To further improve improve the script in a couple of areas, you should separate the explosion block and the direction comparisons block. These areas include:
  • Readability
  • Extension - Using it elsewhere in a script (could also separate into a class for serverwide accessibility).
  • Allows you to add parameters (which I'll show below).

To add parameters to a function, you simply do this (should be idented, no access to RC at the moment though):

PHP Code:

function getCoordinates(xOffsetyOffset) {
if (
playerdir==0)
{
  
this.x=player.x+0.5;
  
this.y=player.y-yOffset;
}
elseif (
playerdir==1)
{
  
this.x=playerx-xOffset;
  
this.y=player.y+0.5;
}
elseif (
playerdir==2)
{
  
this.x=player.x+0.5;
  
this.y=player.y+yOffset;
}
elseif (
playerdir==3)
{
  
this.x=player.x+7;
  
this.y=player.y+xOffset;
}


PHP Code:

//#CLIENTSIDE
function onWeaponFired()
{
  for(
playerdir>0)
  { 
    
playerdir+=1;
  }
  for (
playerdir==3)
  {
    
playerdir-=3;
  }


You would want to use a timeout loop that compares each dir with less or equal to 0 or more or equal to 3 and then either decreases or increases.

Also, you've used deprecated in-built variables a few times. For example, 'playerx', 'playery' and 'playerdir'. 'player' is an object in GScript and has properties which give the same results as 'playerx' and 'playery' such as 'player.x', 'player.y', 'player.dir', 'player.nick', 'player.account' (example of a read-only variable).

Liberated 08-12-2009 05:15 PM

Thank you, i've got a few questions tho, what do the Xoffset and the Yoffset do? do they do exactly the same as what i wrote, or do you put them in a database npc and then put somewhere in the weaponscript xoffset=-5 or something?
And what do you mean with indented? Indented in a script?

Codein 08-12-2009 05:37 PM

Quote:

Originally Posted by Liberated (Post 1514334)
Thank you, i've got a few questions tho, what do the Xoffset and the Yoffset do? do they do exactly the same as what i wrote, or do you put them in a database npc and then put somewhere in the weaponscript xoffset=-5 or something?
And what do you mean with indented? Indented in a script?

No no no.

xOffset and yOffset are function parameters. When you call the function (like you would sleep(0.1)), you have the ability to pass variables to the function.

In the script, you just put in this into onWeaponFired() :

PHP Code:

getCoordinates(77); 

above putexplosion2(1,2,this.x,this.y);

Liberated 08-12-2009 06:02 PM

so this?
PHP Code:

function getCoordinates(xOffsetyOffset) {
if (
playerdir==0)
{
  
this.x=player.x+0.5;
  
this.y=player.y-yOffset;
}
elseif (
playerdir==1)
{
  
this.x=playerx-xOffset;
  
this.y=player.y+0.5;
}
elseif (
playerdir==2)
{
  
this.x=player.x+0.5;
  
this.y=player.y+yOffset;
}
elseif (
playerdir==3)
{
  
this.x=player.x+xOffset;
  
this.y=player.y+0.5;
}
}
function 
onWeaponFired()
{
  
setani("lift"Null);
  
getCoordinates(77)
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!"


you put xOffset in this.y at playerdir == 3 tho :P, but everyone makes error specialy me.

Deas_Voice 08-12-2009 10:05 PM

playerdir is GS1, to make it GS2 u put a dot in-between player and dir.
also if u could use the RC styling command, it would get a lot easier to read for many of us.
Edit: with that i mean there should be some more spaces in the script, for example "player.y+=2;" should be "player.y += 2;", it both looks cleaner and gets a lot easier to read.

PHP Code:

BAD:
  
player.x-=10;

GOOD:
  
player.-= 10

hope u won't take this the wrong way.

Liberated 08-13-2009 08:22 AM

no, no not at all!
thanks for the help! Im only trying to improve and get my scripts good and clean looking, so any C&C is appreciated!
And i really want to stay away from GS1 so im glad you mentioned that.
PHP Code:

//#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("lift"Null);
  
getCoordinates(77)
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!"


i just edited the previous script on the forum, so nothing on the RC or something. I hope this is okay? Or did i do too much by also putting spaced around the = between this.x and player.x?

And can/should getcoordinates be serverside?

Codein 08-13-2009 12:28 PM

Quote:

Originally Posted by Liberated (Post 1514337)
so this?
PHP Code:

function getCoordinates(xOffsetyOffset) {
if (
playerdir==0)
{
  
this.x=player.x+0.5;
  
this.y=player.y-yOffset;
}
elseif (
playerdir==1)
{
  
this.x=playerx-xOffset;
  
this.y=player.y+0.5;
}
elseif (
playerdir==2)
{
  
this.x=player.x+0.5;
  
this.y=player.y+yOffset;
}
elseif (
playerdir==3)
{
  
this.x=player.x+xOffset;
  
this.y=player.y+0.5;
}
}
function 
onWeaponFired()
{
  
setani("lift"Null);
  
getCoordinates(77)
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!"


you put xOffset in this.y at playerdir == 3 tho :P, but everyone makes error specialy me.

Whoops, well spotted :)

Quote:

Originally Posted by Liberated (Post 1514451)
no, no not at all!
thanks for the help! Im only trying to improve and get my scripts good and clean looking, so any C&C is appreciated!
And i really want to stay away from GS1 so im glad you mentioned that.
PHP Code:

//#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("lift"Null);
  
getCoordinates(77)
  
putexplosion2(1,2,this.x,this.y);
  
freezeplayer(0.5);
  
player.chat "Kaboom!"


i just edited the previous script on the forum, so nothing on the RC or something. I hope this is okay? Or did i do too much by also putting spaced around the = between this.x and player.x?

And can/should getcoordinates be serverside?

getCoordinates should be clientside. Also, that's the spacing style I use, so no worries there :)

http://wiki.graal.us/Index

This may also come in handy.

Deas_Voice 08-13-2009 07:16 PM

Quote:

Originally Posted by Liberated (Post 1514451)
no, no not at all!
thanks for the help! Im only trying to improve and get my scripts good and clean looking, so any C&C is appreciated!
And i really want to stay away from GS1 so im glad you mentioned that.
PHP Code:

Script :

i just edited the previous script on the forum, so nothing on the RC or something. I hope this is okay? Or did i do too much by also putting spaced around the = between this.x and player.x?

you'd great with the spaces, could use some more on events with "()" but that isn't necessary as it is you as a scripter that chooses that (personal styling).
i sported some errors, like missing a dot or just the ";"
i'll spell it out for you :D
PHP Code:

function getCoordinates:
if 
dir is 1 :
    
this.playerx xOffset// playerx = player.x :)

function onWeaponFired:
  
getCoordinates(77// you missed a ";" at the end ;O 



All times are GMT +2. The time now is 11:17 AM.

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