Author Topic: Need Help with script  (Read 531 times)

I need help. I'm making my M4 fire M203 rounds.

I get syntax errors

Code: [Select]
Loading Add-On: Weapon_M4ACOG
Executing Add-Ons/Weapon_M4ACOG/server.cs.
Executing Add-Ons/Weapon_M4ACOG/weapon_m4.cs.
Executing Add-Ons/Weapon_M4ACOG/weapon_m4sf.cs.
Add-Ons/Weapon_M4ACOG/weapon_m4203.cs Line: 527 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^^messageClient(%Client,'',"Changed M4-203 Fire mode to Grenade Fire!");

^else ##i##f(%m4firemode = 0)

^^%m4firemode = 1;

^^messageClient(%Client,'',"Changed M4-203 Fire mode to Automatic Fire!");
>>> Error report complete.

Executing Add-Ons/Weapon_M4ACOG/weapon_m4203.cs.
Add-Ons/Weapon_M4ACOG/weapon_m4203.cs Line: 527 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^^messageClient(%Client,'',"Changed M4-203 Fire mode to Grenade Fire!");

^else ##i##f(%m4firemode = 0)

^^%m4firemode = 1;

^^messageClient(%Client,'',"Changed M4-203 Fire mode to Automatic Fire!");
>>> Error report complete.

See? What's wrong with my script?

This is the script that is supposed to run:


Code: [Select]
function M4203Image::onMount(%this,%obj,%slot)
{
messageClient(%Client,'',"Type /ChangeM4FireMode to change fire modes.");
%m4firemode = 1;
}

function M4203Image::onMount(%this,%obj,%slot)
{
%m4firemode = 3;
}

function M4203Image::onFire(%this,%obj,%slot)
{
//Checks Firemode
if(%m4firemode = 1)
{
serverPlay3D(M4ACOGShot1Sound,%obj.getTransform());
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"0.0")));

%projectile = M4ACOGProjectile;
%spread = 0.0007;
%shellcount = 1;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
else
{
serverPlay3D(M4ACOGActivateSound,%obj.getTransform());
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"0.0")));

%projectile = M4203Projectile;
%spread = 0.0002;
%shellcount = 1;

for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);

%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
}

function serverCmdChangeM4FireMode(%client)
{
if(%m4firemode = 1)
%m4firemode = 0;
messageClient(%Client,'',"Changed M4-203 Fire mode to Grenade Fire!");
else if(%m4firemode = 0)
%m4firemode = 1;
messageClient(%Client,'',"Changed M4-203 Fire mode to Automatic Fire!");
else
messageClient(%Client,'',"M4-203 is not equipped!");
return;
}

Anything wrong? I need help. I just want it to change modes if I type /changeM4Firemode

Any help is appreciated.


Stop spamming in servers you need help  :cookieMonster:

You need brackets on if statements if there's more than one line under it. (see servercmdChangeM4FireMode).

Also, in all of your ifs you have single equals signs (=, used to assign values to variables) rather than double (==, used to compare values).