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

Okay, so I am making a leveling add-on that I plan to release fairly soon, but I cannot seem to get it so that when you kill a player, you gain EXP.
Mostly because I don't want to overwrite the default GameConnection::OnDeath(); command.
I need a script so that when someone kills someone else, they gain 5 EXP. Here are the namespaces:
%client.level - The current level that the client has
%client.exp - how much exp the client has
%client.expmax - Max EXP the player has. If %client.exp equals or goes over this set limit, the client will receive a level up.
So, how do I do this?
Please reply sensibly.
« Last Edit: February 05, 2015, 01:50:35 PM by RTBARCHIVE »

Use Player::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) to reference %sourceObject then you can use %sourceObject.client to get the client of the player who caused the damage.

Then it's just a matter of

Code: [Select]
%sourceObject.client.exp += 5;
if(%sourceObject.client.exp > %sourceObject.client.expmax) {
    %sourceObject.client.level++;
    %sourceObject.client.exp -= %sourceObject.client.expmax;
}

Use Player::damage(%this, %obj, %sourceObject, %position, %damage, %damageType) to reference %sourceObject then you can use %sourceObject.client to get the client of the player who caused the damage.

Then it's just a matter of

Code: [Select]
%sourceObject.client.exp += 5;
if(%sourceObject.client.exp > %sourceObject.client.expmax) {
    %sourceObject.client.level++;
    %sourceObject.client.exp -= %sourceObject.client.expmax;
}
Example, please

Example, please

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);

Edit: Forgot to check if player was dead before adding xp.
« Last Edit: January 31, 2015, 07:58:37 PM by $trinick »

Here are the namespaces:
Just a sidenote, these aren't namespaces
Torque calls them tagged fields, but most people just say "variables" or "fields"

I'm not sure Torque even has anything that I would call namespaces


I'm not sure Torque even has anything that I would call namespaces

The TorqueScript tokenizer actually has support for "namespace" and "do" keywords, but they're completely ignored in the parser (and thus act like syntax errors as if they don't exist).

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);

Edit: Forgot to check if player was dead before adding xp.
So, does this add EXP to the killer after the player [not the killer] dies?

So, does this add EXP to the killer after the player [not the killer] dies?
Yes.

Spoon feeding is bad Trinick.

One more question:
If players are to enter the server, how can I make their level  and exp set to 1?

You would package GameConnection::AutoAdminCheck(%client), set %client's level and exp and then return the parent.

You would package GameConnection::AutoAdminCheck(%client), set %client's level and exp and then return the parent.
Why package it? Does this make it so it doesn't override the default command?

Why package it? Does this make it so it doesn't override the default command?
That is correct yes, otherwise things will be seriously screwed up

Thanks everyone. I appreciate the help!

When you package GameConnection::autoAdminCheck, be sure to return the parent!