Author Topic: Event: onPlayerFirstSpawn not working  (Read 2521 times)

I'm attempting to expose a new event: onPlayerFirstSpawn. Although I'm a professional programmer, I have no prior experience with TorqueScript. To get started I read some tutorials on TorqueScript and looked through pre-existing events to see what I could find. I then copy/pasted some stuff together in the hopes that I could get it to magically work, but I'm not having much luck. Here's what I've got so far:

Code: [Select]
registerInputEvent(fxDTSBrick,onPlayerFirstSpawn,"Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "MiniGame Minigame");

package onPlayerFirstSpawn
{
function GameConnection::onClientEnterGame(%client) {
parent::onClientEnterGame(%client);
$InputTarget_["Client"] = %client;
%brick.processInputEvent(onPlayerFirstSpawn,%client);
}

};activatePackage(onPlayerFirstSpawn);

However, like I said before, this isn't working. What am I doing wrong and how can I fix it?

Wow, standards must be pretty low in the industry.
%brick is undefined.

wouldn't you have to like loop through every brick to get this to work?
you have to tell it which brick to process on

wouldn't you have to like loop through every brick to get this to work?

Nope. Just hook in to the addEvent/removeEvent or whatever methods, check if it's the event, and add the brick to a list, which the method above would loop through.

Hey BeibsFan, thanks for the "compliment". TorqueScript is pretty unfamiliar to me and I've actually never done anything remotely like it, so could you explain a little more? I guess you could call me a "noob".

Hey BeibsFan, thanks for the "compliment". TorqueScript is pretty unfamiliar to me and I've actually never done anything remotely like it, so could you explain a little more? I guess you could call me a "noob".

%brick isn't an implicit variable. So you can't just use it without declaring it.

BeibsFan: Naturally, that's common to most programming languages. However, how would I go about finding the value of %brick in this case?

how would I go about finding the value of %brick?
you can't use it without declaring it.
I think that explains itself.

More specifically, this is a bad idea, because it could be easily abused, as there is no implied target it would have to call EVERY SINGLE BRICK IN THE SERVER.

Unless there is a specific target, like I said, generally not a good idea to loop call a function to 59384 bricks at the same time. Especially if it's a busy server.

I think that explains itself.

More specifically, this is a bad idea, because it could be easily abused, as there is no implied target it would have to call EVERY SINGLE BRICK IN THE SERVER.

Unless there is a specific target, like I said, generally not a good idea to loop call a function to 59384 bricks at the same time. Especially if it's a busy server.

Nope. Just hook in to the addEvent/removeEvent or whatever methods, check if it's the event, and add the brick to a list, which the method above would loop through.

Ipquarx, what do you mean by no implied target? If I put an event on the brick, does the event know which brick is on? There's no "backlink", "super", "uber", or "parent" or anything like that for an instantiated event on a brick?

If that's not the case is there any way at all to tie an event to a client's first spawn? There must be, somewhere.

I recommend you don't do something like this. There's just too many possible abuses. I recommend a spawn point with a short fall then a plate below that does whatever you want onTouch, then teleports them to play area. It's not as visually pleasing, but it's a hell of a lot easier and less abuse prone.

try replacing
Code: [Select]
%brick.processInputEvent(onPlayerFirstSpawn,%client);
with
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
   for(%b = 0; %b < MainBrickGroup.getObject(%a).getCount(); %b++)
      MainBrickGroup.getObject(%a).getObject(%b).processInputEvent(onPlayerFirstSpawn, %client);

assuming that your processInputEvent(); is correct, which i have no idea about
but that code should get each brick in the server and call the function

try replacing
Code: [Select]
%brick.processInputEvent(onPlayerFirstSpawn,%client);
with
Code: [Select]
for(%a = 0; %a < MainBrickGroup.getCount(); %a++)
   for(%b = 0; %b < MainBrickGroup.getObject(%a).getCount(); %b++)
      MainBrickGroup.getObject(%a).getObject(%b).processInputEvent(onPlayerFirstSpawn, %client);

assuming that your processInputEvent(); is correct, which i have no idea about
but that code should get each brick in the server and call the function

No, with a lot of bricks that'll be disasterous. Just do what jookia said..

Stop suggesting that he should loop through every single brick in the server. Servers often have over a hundred thousand bricks.

Do what xXBeibsFan119Xx (Jookia) said and simply make a tab-delimited list of every brick containing the event, then loop through that list and call the event on each of the bricks in it.

Stop suggesting that he should loop through every single brick in the server.
So much this.