Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-11-2009, 04:41 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #2  
Old 08-11-2009, 10:14 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Liberated View Post
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).
Reply With Quote
  #3  
Old 08-12-2009, 05:15 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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?
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #4  
Old 08-12-2009, 05:37 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Liberated View Post
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);
Reply With Quote
  #5  
Old 08-12-2009, 06:02 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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.
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #6  
Old 08-12-2009, 10:05 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
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.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #7  
Old 08-13-2009, 08:22 AM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
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?
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.

Last edited by Liberated; 08-13-2009 at 08:32 AM..
Reply With Quote
  #8  
Old 08-13-2009, 12:28 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Liberated View Post
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 View Post
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.
Reply With Quote
  #9  
Old 08-13-2009, 07:16 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Liberated View Post
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
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 
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
Reply


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 02:42 PM.


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