Author Topic: Dumb question...  (Read 1390 times)

I code only a tiny bit, but can someone explain what a parent and child's are?

The only dumb question is the one you don't ask!

Anyways, parent/child is from the packaging system. Basically, if you package an exsisting function, you can overwrite it. But in order to retain the original functionality of the function, you can call the original function using parent::functionname(%arguments, %go, %here);

So let's say you wanted to add some functionality to the kick command. Every time someone tries to use it, it will echo "Someone tried to kick!" into the console.

First you create a package (and remember to add in an activatePackage statement at the bottom)

Code: [Select]
package ourPackage
{

};
activatePackage(ourPackage);

Then we add in the function itself. But, we don't add in all the original code for the kick function, because we don't have it.

Code: [Select]
package ourPackage
{
function serverCmdKick(%client, %victim)
{

}
};
activatePackage(ourPackage);

Now we add in what we want to happen, an echo.

Code: [Select]
package ourPackage
{
function serverCmdKick(%client, %victim)
{
echo("Someone tried to kick!");
}
};
activatePackage(ourPackage);

And after that, we put in parent::serverCmdKick(%client, %victim);. This calls the original function, so that it will do what it normally does.

Code: [Select]
package ourPackage
{
function serverCmdKick(%client, %victim)
{
echo("Someone tried to kick!");

parent::serverCmdKick(%client, %victim);
}
};
activatePackage(ourPackage);

And there you go, now any time you try to kick someone, it will echo into the console and still be able to kick people.

So, what i'm getting is that, the function serverCmdKick already exists, so if you don't add the parent it will overwrite the function?

So, what i'm getting is that, the function serverCmdKick already exists, so if you don't add the parent it will overwrite the function?
yes


datablock parenting also exists

Code: [Select]
datablock type(Parent)
{
     data = 1;
     test = 2;
};

datablock type(Child : Parent)
{
    test = 1;
};

Child will have test set to 1 and data set to 1, because Child overwrote the Parent's test variable, but did nothing with the data variable
Parent will have test set to 2 and data set to 1

i find it quite heartwarming at times how friendly people can be here. ty based ipquarx and swollow and everyone else

ot: datablock parenting will result in an extra datablock being created, and is more for ease of creating duplicates of datablocks with minor differences between them. you are also not required to parent the function in a package, allowing you to completely overwrite some default functions

in addition, packages are also neat if you want to have multiple versions of a function and toggle them on or off. you can deactivatePackage("name"); and your packaged version of the function will stop being used
« Last Edit: July 25, 2016, 11:21:36 PM by Conan »

ot: datablock parenting will result in an extra datablock being created, and is more for ease of creating duplicates of datablocks with minor differences between them.
this is the whole concept of parenting

in addition, packages are also neat if you want to have multiple versions of a function and toggle them on or off. you can deactivatePackage("name"); and your packaged version of the function will stop being used
this is a bad idea if for some strange reason you need a function to preform separate tasks depending on a toggle then use a variable but do not enable or disable packages to switch it

you are also not required to parent the function in a package, allowing you to completely overwrite some default functions
yes!

Okay, new question.
Since i've only really been testing with console and chat, how would i make a simple gun work?
As well as how to change blender files to .dts?

take a look at how the default gun is coded. the easiest way to learn how things work is to look at existing addons that sorta do what you want yours to do.

as for blender to dts, use ports exporter or get blender 2.49b and the exporter for that. there's a number of things to remember to do using ports exporter:
1) scale and position your gun relative to this model - get the obj version and import it into your .blend file.
2) after positioning and scaling/rotating it, select your gun model and apply location/rotation/scale with ctrl-a.
3) if you want to do any animations, do them now
4) remove the obj then add two empties named muzzlePoint and ejectPoint (if you want your gun to have a shell eject position). you dont need mountpoint since that's automatically placed at the origin (and you've already positioned your model to be where you want it to be ingame)
5) put these two empties under another empty named Detail32, then put Detail32 empty underneath another empty called Shape. make sure all the empties are created at the origin, or just select them all and apply location to them after parenting them.
6) position the muzzlepoint/ejectpoint/etc where you want it to be. dont need to rotate them or anything
7) export by hitting file > export > dts. to install port's dts exporter, refer to posts in his topic.
« Last Edit: July 30, 2016, 10:52:29 PM by Conan »

there's a number of things to remember to do using ports exporter:
5) put these two empties under another empty named Detail32, then put Detail32 empty underneath another empty called Shape

i am pretty sure that you do not need to do any of this

i am pretty sure that you do not need to do any of this
dont blame me i was told by trogtor to do it i had no choice

i am pretty sure that you do not need to do any of this
yeah you're right