Author Topic: function useFirstSlot(%slot)  (Read 1393 times)

I understand that there are a set of functions like useFirstSlot() and useSecondSlot() etc that are called whenever a player presses a number key on their keyboard or chooses a brick slot on the brick menu on the bottom of the screen.

I'm trying to squeeze a little code in that will return the object of the player that calls the function in the first place. However, useNthSlot() only has one parameter and one return: the slot boolean in which its called. Is there some way that I can return the player that uses the function?

my optimal code is this:
Code: [Select]
function useFirstSlot(%f, %pl)
{
       parent::useFirstSlot(%f,%pl);
       announce(%pl.client.name);
}

I know that adding the parameter to the function would require me to directly edit the source code of the engine, which I clearly can't do. I was hoping there's some way to maybe commandToServer('sayPlayerName',1,%slot); that I can call as a workaround, but i still don't really know how to get the player object.

Does anyone have a solution or know some way to work around this issue?

A boolean is either 0 or 1. Yes or no. Therefore, you should say slot number instead. The most complex words aren't necessarily the most correct, just like cartoons teach.

I am going to pardon your filibuster, because everyone who doesn't know things on a subject ends up with one, and going angry over it every time has brought me nothing good.

The object of the player is, well, %pl. That is the player object.

The client is, like you put it there, %pl.client.

The code seems to be pretty much correct except for a thing I'll talk about later. Or, at least, assuming announce() exists. Many have used that so maybe it exists.

Works or not, here's how simple the situation can get. You didn't explicitly said if the function you gave works, but the rest of your wall implies it didn't.

So you have a variable %f and a variable %pl there, wherein %f is unknown and %pl is the player object.

But first, you've made a mistake: Overwritten the original function. In Torquescript, if you want stuff to happen when a function is called without overwritting the already-existing one, you make yourself a package.

Here it is:

Code: [Select]
package SlotPackage
{
function useFirstSlot(%f, %pl)
{
       parent::useFirstSlot(%f,%pl);
       announce(%pl.client.name);
}
}
activatePackage(SlotPackage);

The function is now inside a package. It will not overwrite the original function, and is executed instead of it. So doing calling the function on "parent" is now valid, since we don't overwrite it.

Packages are disabled by default, so we use the function activatePackage to activate the package.

I've typed this up on my phone, so I am going to edit now that I get on a computer. Refresh later after you read this so far.

Code: [Select]
package SlotPackage
{
function useFirstSlot(%f, %pl)
{
       parent::useFirstSlot(%f,%pl);
       announce(%pl.client.name);
}
}
activatePackage(SlotPackage);
Except this causes a syntax error. Packages need to be closed with a ;



You're mixing client sided and server sided code anyway. This will not work. You also can't just squeeze in extra arguments and expect whatever's calling it to not only put something in there but also know what to put in there. Hope this information helps.

You're mixing client sided and server sided code anyway. This will not work. You also can't just squeeze in extra arguments and expect whatever's calling it to not only put something in there but also know what to put in there. Hope this information helps.

Somehow I only found out he was doing wrong stuff from the beginning because you posted it - I didn't even notice he was trying to "squeeze in extra code".

Well, now that I understood the situation properly, are you sure you need to know when the player chooses slots?

-stuff-
lmao i've been coding in torquescript for over 5 years now. I already know all this stuff. And yes, %slot is a boolean. It returns true and false only. And announce() is a default function.

You're mixing client sided and server sided code anyway. This will not work. You also can't just squeeze in extra arguments and expect whatever's calling it to not only put something in there but also know what to put in there. Hope this information helps.
not really. useNthSlot() is a server-sided function, that should at least have a parameter for who exactly is calling the function. Instead, it's called serverwide whenever anyone presses their number key, which is really stupid.

If someone presses their number key, I want to know who exactly this person is, and that's why I want their object to be returned. That way I can do some magic and call a function on the player when they press a number key.

lmao i've been coding in torquescript for over 5 years now. I already know all this stuff. And yes, %slot is a boolean. It returns true and false only. And announce() is a default function.
not really. useNthSlot() is a server-sided function, that should at least have a parameter for who exactly is calling the function. Instead, it's called serverwide whenever anyone presses their number key, which is really stupid.

If someone presses their number key, I want to know who exactly this person is, and that's why I want their object to be returned. That way I can do some magic and call a function on the player when they press a number key.

I don't know, you sound a bit like someone new to the whole thing - believing coding is complicated and falling into 15-minute lectures.

But hold it - are you sure the function is server-sided? If you start your own server and try to do stuff yourself, both client-sided things and server-sided things will show, since you are both the server and client. The correct way to see if something indeed is server-sided is to have your function there (IN A PACKAGE, NOT LIKE YOU DID AT OP) and have another user do the action you want to check for server-sided code (Or dedicated, preferably)

Still seems a bit off how useNthSlot() is a server-sided function - You really sure it isn't something like serverCmdUseNthSlot()? Are you also sure that the function pointlessly returns a boolean?

I already ran a trace. It's called server sided whenever a client presses a number key that corresponds to the function name.

Ie if you press 2 on the keyboard it will call useSecondSlot(%slot) server side, with an untraceable source object.

not really. useNthSlot() is a server-sided function,
No it's not.

Go on someone else's server, trace(1); and press a number.

WAIT possible solution: i can try packaging Armor::onTrigger to see if this works, since it follows the same slot format. I might be able to get the source object by returning it when the trigger isn't 0-5

No it's not.

Go on someone else's server, trace(1); and press a number.
you're right. I'll test some more stuff later.

Armor:onTrigger only involves:
left click (fire)
[not used by default] (altTrigger)
shift (crouch)
space (jump)
right click (jet)

Alright here's the solution I found:

function serverCmdUseInventory(%cl,%inv) can return %cl, which is the client accessing the slot, and %inv, which is the slot number. This works for the brick menu only, not the inventory sidebar on the top right.

Alright here's the solution I found:

function serverCmdUseInventory(%cl,%inv) can return %cl, which is the client accessing the slot, and %inv, which is the slot number. This works for the brick menu only, not the inventory sidebar on the top right.
serverCmdUseTool(%client, %tool) is for the top right inventory. %tool is zero - indexed.