Author Topic: Coding Help - Everything is brokez.  (Read 6174 times)

Code: [Select]
function ServerCmdSelf Delete(%client)
{
if($Self Delete == 0) // Off
{
return;
}
else
{
parent::ServerCmdSelf Delete(%client);
}
}

What is wrong with my logic here?
EDIT: Self Delete will become disabled, but then wont allow you to kill yourself even if it is enabled.



Also, if you could give the name and directory of the main script (Like in Vanilla, all the main commands where stored in directory/scripts/sever/scripts/main.cs or something like that).

Thanks.
« Last Edit: September 09, 2007, 05:05:10 PM by IbanX »

1) you have to put that in a package so it can overwrite the old one
Code: [Select]
package Self Deleteoverright{
//code har
};
activatepackage(Self Deleteoverright);
2) the main file is dsoed(encrypted(unreadable))

I don't understand your syntax. But I'm going to assume it goes like

Code: [Select]
//package Self Deleteoverright
//{
// Moar codes?
//};

function ServerCmdSelf Delete(%client)
{
if($Self Delete == 0) // Off
{
messageClient(%client,"","\c6 Sorry, Self Delete has been \c0DISABLED.");
return;
}
else
{
echo("Activating Self Delete");
activatepackage(Self Deleteoverright);
}
}

I don't know what to put in the package, though. The above code functions properly.
« Last Edit: September 09, 2007, 12:25:02 AM by IbanX »

Code: [Select]
package Self Deleteoverright{
function ServerCmdSelf Delete(%client)
{
if($Self Delete == 0) // Off
{
messageClient(%client,"","\c6 Sorry, Self Delete has been \c0DISABLED.");
return;
}
else
{
parent::servercmdSelf Delete(%client);
}
}
};
activatepackage(Self Deleteoverright);

Works like a charm, I really appreciate it.

However, can you explain to me WHY that package makes any difference?

sure thing, the original function cant be edited directly since the files are dsoed, so you can activate packages to overwrite functions. Its a part of torque for things like this.
In example, you have a command called WTFBBQ
and everytime someone uses it the next guy who does will get a different effect, you can activate/deactivate packages that override it.

It's a programming concept called encapsulation.

The main game code encapsulates packages, thus becoming the 'Parent'.

<main game code>
{
     <package>
     {
          <methods>
          {
          }
     }
}

That makes sense, thanks.

I'd hate to make another topic, just for this, but is there a Try Catch for torque? I'm tired of restarting Blockland every 10 seconds.

EDIT: Also, I'm trying to make more restriction packages but I guess I need to /guess/ the commands? For instance, I want a one to restrict speech and another to restrict weapon fire. How on earth would I go about setting packages up for these?
« Last Edit: September 09, 2007, 04:12:31 AM by IbanX »

Unfortunately the only way of finding syntax errors is to go through the code or try exec'ing it and have syntax errors. If you are uncertain about the syntax of a particular line of code, paste it into the console (uninitialised variables turn up as "" and it probably won't affect anything without them set) and see whether it accepts it or throws a Syntax Error in Input.

I've always wondered why eval(); (Console) doesn't crash you yet exec(); does, but shows an error report.

Speech: servercmdMessageSent();
Fire: WeaponImage::onFire();, works for most weapons except "inaccurate"/"multi" ones i.e. shotgun, dual guns.

parent::WeaponImage::OnFire(%Client) crashes the game.

parent::OnFire(%Client) Throws an error on each fire.
Code: [Select]
base/server/scripts/allGameScripts.cs (7809): Unable to find object: '' attempting to call function 'getEyeTransform'
base/server/scripts/allGameScripts.cs (7811): Unable to find object: '' attempting to call function 'getMuzzleVector'
base/server/scripts/allGameScripts.cs (7825): Unable to find object: '' attempting to call function 'getVelocity'
« Last Edit: September 09, 2007, 06:34:17 AM by IbanX »

Ones which use :: like WeaponImage::onFire go to Parent::onFire not Parent::WeaponImage::onFire. I don't know why they didn't keep it the same for Class::Function and Functions either...

/cmd A B C = commandtoserver('cmd',"A","B","C"); not commandtoserver('cmd',"A B C");.

Yes, I figured that out. Why is it throwing an error, though?

You haven't passed it all the parameters. The WeaponImage::onFire method doesn't use %client in its parameters, it uses %this,%obj,%slot where %this refers to the weapon image, %obj is the client's player and %slot is the mount slot or something.

You'll need to do:
Code: [Select]
parent::OnFire(%this,%obj,slot)in the parenting bit, and use
Code: [Select]
function WeaponImage::onFire(%this,%obj,%slot)for the method.

So all together:
Code: [Select]
package fireprevent{
function WeaponImage::onFire(%this,%obj,%slot)
{
if($fireprevent == 1) // Off
{
messageClient(%client,"","\c6 Sorry, Firing has been \c0DISABLED.");
return;
}
else
{
parent::onFire(%this,%obj,%slot);
}
}
};
activatepackage(fireprevent);

That'll do it.


Now I just need the parameters for MessageSent so I can say something now.

EDIT:

Still throwing the same errors. I forgot to mention this is spewed underneath the 'cant find muzzlevelocity..'

Quote
Projectile::Addon: mSourceObjectID is invalid
« Last Edit: September 09, 2007, 03:52:08 PM by IbanX »