Author Topic: [Help] Leveling System, Code on Spawn, Schedules, Teleportation  (Read 5113 times)

You're also missing %damagePosition, %damageAmount, %damageType. Notice how %damageAmount is on there; this means that the original damage function will always be told they're taking <nothing> damage, which of course would mean you're not doing any damage to them.

Thanks, I'll try to fix my code.
In this case, the arguements for AIPlayer::Damage are given to me. How would I go about finding the arguements of something I got off of trace(1);?
Edit: It works! I'm able to kill bots.
Still though, the levelling system isn't working.
When I do /mystats, my level is nothing.
Edit 2: I modified it so it also tells me %player.pts, nothing as of now. Not a zero, just blank. I think it might have something to do with the general design of the code.
Edit 3: I think I'm on to something, I'm trying to access the %pts and %level of %sourceObject, which is coordinates, not the actual player.
« Last Edit: April 07, 2015, 06:56:03 PM by Johnny Blockhead »

The arguments will be in the trace. Look at them and guess what they mean. Package it with generic names and echo the .getClassName() of any arguments that look like object IDs. Mess around.

%client = %sourceObject;

You need to change this to

%client = %sourceObject.client;

%sourceObject will usually be a player or a projectile, both of which will have a client set.

Thanks Port!
I did as said, still doesn't work.

package Experience
{
    function AIplayer::damage(%this, %bot, %sourceObject, %damagePosition, %damageAmount, %damageType)
    {
        %client = %sourceObject.client;
        %client.pts += 1;
        if(%client.pts >= 2)
        {
            %client.level += 1;
            %client.pts -= 2;
        }
        parent::damage(%this, %bot, %sourceObject, %damagePosition, %damageAmount, %damageType);
    }

    function servercmdMyStats(%client)
    {
        messageClient(%client, '', "\c5Your Level:" SPC %client.level);
        messageClient(%client, '', "\c5Your EXP:" SPC %client.pts);
    }

    function servercmdSetLevel(%client, %amt)
    {
        %client.level = %amt;
    } 
};
activatePackage(Experience);

I have no idea what I'm doing wrong.
« Last Edit: April 07, 2015, 07:18:24 PM by Johnny Blockhead »

Echo the client in the damage function and make sure that it is indeed, an actual client.

I followed elm's advice, and did this:
talk(%sourceObject.client);
But, nothing happens. It doesn't even show in chat
Console:
Just silence.
I know my syntax is right though, because when I do talk(%sourceObject);, I get coordinates. This must mean the client isn't being represented properly. I'll fiddle with this.
Edit: Would %sourceobject.client.player work? Testing it out.
« Last Edit: April 07, 2015, 08:19:32 PM by Johnny Blockhead »

If an object doesn't exist, then you're not going to find any objects on a non-existant object.

Try Armor::Damage instead of AIPlayer::Damage
That's what I always see people use

I'm sure the object exists, but the problem is that .client isn't the correct way to get the client. Johnny, try using .dump(); on the %sourceObject and look at the methods/variables and see if there is a way to get the client/player object correctly.

I edited the script so it dumps every new %sourceObject it gets, and found something interesting. It says in the dump the client's id as a tagged field. To me it sounds like %sourceObject.client should work.
Edit: Yay, it works! I edited my %client = %sourceObject.player.client; code to just %client = %sourceObject.client. It's weird concidering that it used to be like the latter but I changed it as a troubleshoot thing. I'll leave this thread open if anyone wants to add on, or I have more questions.
« Last Edit: April 07, 2015, 11:47:54 PM by Johnny Blockhead »

Hey guys, I'm back but just for a tiny question.
I'm still not sure how I find out the arguments of a command, and Port's explanation really didn't help. I can't find anything to do with arguments in the trace.
By arguments I mean:
servercmdBlah(%this, %potato, %tomato){

For example, I'm making it so I can trigger my own code whenether a player uses his light:
    function useLight(%this, %client)
    {
        //eventually add a cooldown here
        if(%this = 1) //so it doesnt toggle twice
        {
            if(%client.spell $= "grow")
            {
                talk("GROW"); //placeholder
            }
            else if(%client.spell $= "jolt")
            {
                talk("JOLT"); //placeholder
            } 
        }

    }

(shh its packaged dont worry)
I've ran into the problem where I don't know how to refer to the client using the light, and as such %client doesn't work. I'm positive that the Light command has some argument that refers to the client, its just I have no way of figuring out what its arguments are.

So, can someone explain to me how to do that?
« Last Edit: April 08, 2015, 09:13:19 PM by Johnny Blockhead »

Did you read the Trace Tutorial I posted?

Did you read the Trace Tutorial I posted?
Yep, but on a re-read I can see what I missed. Thanks!

Also, for the statement if(%this = 1) you are simply setting %this to 1 everytime. The operator you are looking for is == instead.

I'll write up a list of Torquescript operators and provide info on how users can utilize them, sometime soon.
« Last Edit: April 08, 2015, 09:31:03 PM by elm »

Hey guys, I'm in another pickle.

    function gameConnection::spawnPlayer(%this, %player)
    {
        %this.bottomprint("\c2Money:\c6" SPC %this.exp @ "." SPC "\c2Superpower:\c6" SPC       %this.power @ ".");
        %client = %this;
        if(%this.power $= "Sprint")
        {
            %this.player.setmaxForwardSpeed(20);
            talk("Client.Player:" SPC %player);
        }
        parent::spawnPlayer(%this);
    }


This is my code, and basically what I'm trying to do is make it so if a client's superpower is sprint, their player's forward speed is set to 100 every time they spawn. gameConnection::spawnPlayer has the argument for %client. But for some reason, I can't do %client.player. Every time I do, it returns nothing. As seen in the code, I need it to set the maximum forward speed. Any ideas? I'm sure that my system for setting %client.power is correct, and it is indeed set to sprint.

Edit: I'm also wondering how I'd go about making a player faster while in midair-- air control, basically. You'd walk the normal speeds on ground, but really fast in the air. I have no idea how to approach this, and if the answer is really convoluted then just tell me so.

Edit 2: I was working and trying to set up a system so when you hold your light key, your maxForwardSpeed is increased. I couldn't figure out how to do that, since it was a dash between useLight which tells you when it is being pressed and isn't, and servercmdLight which allows you to access the client. So, I thought of the next best thing, schedules. Even through extensive searching, I'm still not quite sure how to format them. Here's my try at it:

    function servercmdLight(%client)
    {
        if(%client.power $= "Sprint")
        {
            talk("initial");
            %client.player.setmaxForwardSpeed(100);
            schedule(5000,0,%client);
            %client.player.setmaxForwardSpeed(20);
            talk("timed");
        }
    }


Basically, my goal is for the setmaxForwardSpeed(100) to be sent off first, and then five seconds later setmaxForwardSpeed(20); goes off. And yes, I know twenty is higher then usual.
Edit 3: I got the schedules working, here's my code. I'm not sure if it's the most efficient, but hell it works.

    //Light ultimates.
    function servercmdLight(%client)
    {
        if(%client.power $= "Sprint")
        {
            %client.player.setmaxForwardSpeed(100);
            schedule(5000, 0, evalSlowDown, %client);
        }
    }

    //Disables speedymode.
    function evalSlowDown(%client)
    {
        %client.player.setmaxForwardSpeed(20);
    }

Now to look into cooldowns...
« Last Edit: April 09, 2015, 01:30:59 AM by Johnny Blockhead »