Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 

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 06:53 PM.


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