Author Topic: Gun script supposedly not working  (Read 541 times)

I was changing around Blockombat's M9A1 script so every time it shoots; it plays a random distant gunshot sound 2D to the whole server.
I'm obviously a noob or something because I cant even get this to work.
This is what I am putting, Any ideas?
Code: [Select]
function BerettaM9A1Image::OnFire(%this, %obj, %slot)
{
Parent::onFire(%this, %obj, %slot);
%random = getRandom(1,3);
switch(%random)
{
case 1:
serverplay2d(M9A1Distant1);
case 2:
serverplay2d(M9A1Distant2);
case 3:
serverplay2d(M9A1Distant3);
default:
echo("Error on M9A1");
}
}

Also, If I edit this script it has a problem with this. If I don't edit the script it works just fine.
Code: [Select]
function servercmdDropTool(%client,%slot)
{
if(%client.player.getMountedImage(0) $= BerettaM9ADSImage.getID())
{
%client.player.unmountImage(0);
%client.setControlCameraFov(90);
if($BKT::CH)
{
crossHair.setBitmap("base/client/ui/crosshair.png");
}
}
##r##eturn Parent::servercmdDropTool(%client,%slot);
}
};
« Last Edit: August 31, 2012, 01:04:01 AM by Arekan »

does onfire return anything?
if it does use %value = parent::stuffs...;
and return %value at the end

and how does the first one not work? does it break anything? or does it just not play a sound?

does onfire return anything?
if it does use %value = parent::stuffs...;
and return %value at the end

and how does the first one not work? does it break anything? or does it just not play a sound?

It does not play the sound.
I remember I got it to work slightly before but it fired no projectiles.

does serverplay2d(M9A1Distant1); work in the console?
the rest looks fine (for the top [code][/code])

It works in console but still wont play ingame

I was changing around Blockombat's M9A1 script so every time it shoots; it plays a random distant gunshot sound 2D to the whole server.
I'm obviously a noob or something because I cant even get this to work.
This is what I am putting, Any ideas?
Code: [Select]
%random = getRandom(1,3);
switch(%random)
{
case 1:
serverplay2d(M9A1Distant1);
case 2:
serverplay2d(M9A1Distant2);
case 3:
serverplay2d(M9A1Distant3);
default:
echo("Error on M9A1");
}
This is not the problem but the default case is not needed because the number can't be anything but 1-3.

This is not the problem but the default case is not needed because the number can't be anything but 1-3.
Hence the "Error on M9A1" echo, lol. I have echos like this in some of my code that logically will never be called but are there just for lulz or in the case that I forgeted something up and it does get called.

Make sure the weapon's image datablock actually calls "OnFire" instead of something else.

Make sure the weapon's image datablock actually calls "OnFire" instead of something else.
This, some developers might do weird things with the state system.
Just put an echo at the beginning of the function, and check your console when you fire
Also, since all the sound names are the same with the exception of the number at the end, you could skip that entire switch for a nicely compacted, single line

Code: [Select]
function BerettaM9A1Image::OnFire(%this, %obj, %slot)
{
Parent::onFire(%this, %obj, %slot);
echo("onFire");
serverPlay2d(M9A1Distant1 @ getRandom(1,3));
}




As for the second problem, is sounds like what happens if you modify an add-on in a .zip and try to exec without reloading the file database (correct me on whatever it's called)

Also note with the second issue that it will only affect the host's crosshair, provided the server is not dedicated.