Author Topic: Code Check - Page 3  (Read 3101 times)

Code: [Select]
package playerLeveling {
    function Player::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) {
        %ret = parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
        if(%obj.>>>>>>>getState()<<<<<< !$= "Dead")
            return %ret;
        if(!isObject(%obj.client) || !isObject(%sourceObject.client))
            return %ret;
        %killer = %sourceObject.client;
        %killer.exp += 5;
        if(%killer.exp >= %killer.expmax) {
            %killer.level++;
            %killer.exp -= %killer.expmax;
        }
        return %ret;
    }
};
activatePackage(playerLeveling);
Okay, wait. trinick, getState is an unknown command according to the console. And if this isnt the error here, then i'll also mention that i'm not getting any exp added to the client variable %client.exp;
Here is the current script in my server.cs:
Code: [Select]
package playerLeveling {
function Player::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) {
%ret = parent::damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
if(%obj.getState() !$= "Dead")
return %ret;
if(!isObject(%obj.client) || !isObject(%sourceObject.client))
return %ret;
%killer = %sourceObject.client;
%killer.exp += 5;
messageclient(%killer,'',"\c6Got 5 EXP.");
if(%killer.exp >= %killer.expmax) {
newlevelscript(%killer.name);
%killer.exp -= %killer.expmax;
}
return %ret;
}
function GameConnection::AutoAdminCheck(%client)
{
%ret = parent::AutoAdminCheck(%client);
if(isFile("config/server/levelsystem/" @ %client.bl_id @ ".txt") == 1)
{
load(findclientbyname(%client));
}
else
{
messageclient(%client,'',"\c6Save file not found. Delivering default level.");
%client.exp = 0;
%client.expmax = 100;
%client.level = 1;
save(findclientbyname(%client));
}
return %ret;
}
};
« Last Edit: February 01, 2015, 05:31:47 PM by RTBARCHIVE »

1. There's no activatepackage
2. Does it says unable to find object as well, or just no function? If the latter, type in console: find client by name("your name").player.dump();
And look through the results for something similar to getstate, and replace with that

1. There's no activatepackage
2. Does it says unable to find object as well, or just no function? If the latter, type in console: find client by name("your name").player.dump();
And look through the results for something similar to getstate, and replace with that
1. No, it's there. (the getstate)
2. There was an activatepackage off of the script I had shown.
3. Still not getting any exp. It says unknown function.
« Last Edit: February 01, 2015, 06:31:55 PM by RTBARCHIVE »

::getState is valid on a player. Try putting this in there to see what it echos:

echo(%obj.getClassName());

::getState is valid on a player. Try putting this in there to see what it echos:

echo(%obj.getClassName());
didnt echo anything

Replace the getstate line with the echo.

Replace the getstate line with the echo.
Code: [Select]
Call to echo in Damage uses result of void function call

That's not an error, it's just a warning
It means you're trying to echo the result of a function that doesn't return anything. It'll still echo something if there's a constant or other function call in the echo

Also, why not just use this function?

GameConnection::onDeath(%this,%obj,%killer,%type,%area)

Also, why not just use this function?

GameConnection::onDeath(%this,%obj,%killer,%type,%area)

Also, why not just use this function?

GameConnection::onDeath(%this,%obj,%killer,%type,%area)

Honestly I forgot the argument list for this function. It really doesn't matter much though.

http://docs.garagegames.com/tge/official/content/documentation/Reference/Introduction/Namespaces.html
I missed this somehow

I'm aware the Torque has something that it calls namespaces.
But you'll notice that I said
that I would call
because the way they work (providing a hierarchy of inherited methods) is more similar to classes; hell, even that document continuously refers to the className field


Whereas classes provide (among other things) a way to group related methods, namespaces provide a way to group together related classes, to provide organization and prevent name collisions.
For example, if you've ever learned C++, one of the first things you learn to use is cout, which is part of the std namespace. If you want to use it, you either have to fully qualify it by typing std::cout, or use a using namespace std; directive.
Torque does support double-colons for variable names (Everyone's used $Pref::Server::*), but you're just typing it as part of the name, not declaring a Pref namespace, a nested Server namespace, and then declaring variables nested inside that. And that's just variables, for functions there's nothing; people use <prefix>_<FunctionName> as a replacement

Don't worry. I got it figured out, and fixed the exp get. A lot of work!

Another question (since I don't want to spam this board; i've already got this thread.)
So, for /votekick, i've got it so that the /yes and /no commands up the respective vote variables, and also set %client.voted = 1;. How, at the end of the vote, do I set it back to 0 for everyone on the server?

Loop through client group
%count=clientgroup.getcount();
for(%i=0;%i<%count;%i++)
{
    %client = clientgroup.getobject(%i);
    //do things to %client
}

Loop through client group
%count=clientgroup.getcount();
for(%i=0;%i<%count;%i++)
{
    %client = clientgroup.getobject(%i);
    //do things to %client
}
Do I make this a function? Package? Etc.