Quote:
Originally Posted by Liberated
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(xOffset, yOffset) {
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).