Author Topic: Minigun Code  (Read 1158 times)

I'm trying to make the minigun only work in vehicles because people are using the mini gun to get to areas really fast like in the water.
So here is the code I used but it doesn't seem to work.
Code: [Select]
function minigunImage::onFire(%this,%obj,%slot)
{
if(%obj.isMounted())
return;
else if(!%obj.isMounted())
commandToClient(%client, 'CenterPrint', "<color:FFC29B>The minigun only works in vehicles<color:555555>.<br\><color:FF0000>Please go into a vehicle<color:555555>."
Parent::onFire(%this,%obj,%slot);
}

Put the Parent::... where the return; is now.

What you have it doing right now is telling them that they can't use it, and then letting them use it, or if they are on a vehicle, not letting them use it.

Also, it has a syntax error, as the commandToClient.. line ends at the " when it should end with ");

Additionally, you do not need the else if, because a plain else would work just as well, although this isn't really a problem, just adding unnessecary code and complexity.

This is probably what you want:
Code: [Select]
function minigunImage::onFire(%this,%obj,%slot)
{
    if(%obj.isMounted())
      Parent::onFire(%this,%obj,%slot);
    else
      commandToClient(%client, 'CenterPrint', "<color:FFC29B>The minigun only works in vehicles<color:555555>.<br\><color:FF0000>Please go into a vehicle<color:555555>.");
}


Wait what about the: else if(!%obj.isMounted())?

Well, since the original was if(%obj.isMounted()), the only time it will try the else is if %obj.isMounted() is false. !false is always true, so a regular else there would have the exact same result as else if(!%obj.isMounted()).


The message doesnt pop up.

Because %client doesn't exist.