Author Topic: Trouble with GameConnection::playerSpawn  (Read 1125 times)

I am making it so that whenever  player spawns, it reads a file to reset their name color.
Code: [Select]
function gameconnection::spawnplayer(%a)
{
%file = new fileobject();
%file.openforread("config/server/serverupgrade/colornames/"@%a.name@".txt");
%a.player.setshapenamecolor(%file.readline());
%file.close();
%file.delete();
}
But now the spawning system is all screwed up (whenever I die I can't respawn)
So how do you make it so that it doesn't screw up?


If Port's link didn't help, here's another explanation I guess... (I was in the middle of typing so might as well post it)
It also has exactly what you need at the bottom if you wanted to compare or something

Whenever you overwrite an already existing function, you can use something called a package if you want the original function to still be called.

Code: [Select]
//Packages
package MyPackage
{
//Some functions in here
}; //Note the semicolon after the package
//Package Functions
ActivatePackage(MyPackage);
DeActivatePackage(MyPackage);

MyPackage is your new page, where you can put the functions you're writing.
You use activatePackage and deactivatePackage to basically turn it on and off.
This still doesn't solve your problem. We put the function in a package but it's still overwriting, so now you need to call the parent (the function you overwrote). You can do this anywhere in your newly defined function by this:

Code: [Select]
Parent::FunctionName(FunctionParameters);
So for your example, since we're calling functions on the player, we'd rather let the original script take care of all of it's things first (so it actually spawns the player for us to use)

Code: [Select]
package mySpawnPlayerPackage
{
function gameconnection::spawnplayer(%a)
{
Parent::spawnplayer(%a);
%file = new fileobject();
%file.openforread("config/server/serverupgrade/colornames/"@%a.name@".txt");
%a.player.setshapenamecolor(%file.readline());
%file.close();
%file.delete();
}
};
ActivatePackage(mySpawnPlayerPackage);

Wow, I'm so dumb. I haven't worked with these for awhile so I'm a bit rusty.