Author Topic: onFirstSpawn  (Read 963 times)

Can someone create an event called onFirstSpawn? Basically, when the player spawns and is new to the server, the input event onFirstSpawn will be triggered. But if a player has already been to the server before, it will not trigger. It will also be minigame only.

« Last Edit: May 09, 2015, 02:04:30 PM by Hawt »

I'm assuming minigame only that it should work.


Should work.

Code: server.cs (101 lines)
function fxDTSBrick::onMinigameInitSpawn(%obj, %client)
{
   if(!isObject(%client))
       return;
   $InputTarget_["Self"]   = %obj;
   $InputTarget_["Player"] = %client.getControlObject();
   $InputTarget_["Client"] = %client;
   $InputTarget_["MiniGame"] = getMiniGameFromObject(%obj);
   %obj.processInputEvent("onMinigameInitSpawn", %client);
}
registerInputEvent("fxDTSBrick", "onMinigameInitSpawn", "Self fxDTSBrick" TAB "Player Player" TAB "Client GameConnection" TAB "MiniGame MiniGame", 1, 1);

$Server::onMinigameInitSpawnList = inputEvent_GetInputEventIdx("onMinigameInitSpawn");

package onMinigameInitSpawn
{
    function GameConnection::SpawnPlayer(%this)
    {
       Parent::SpawnPlayer(%this);
       if(isObject(%this.player) && isObject(%this.minigame) && !$ClientInitSpawn[%this.getBLID()])
        {
           $ClientInitSpawn[%this.getBLID()] = true;
           for(%i=0;%i<getWordCount($Server::onMinigameInitSpawnEvents);%i++)
            {
               %brick = getWord($Server::onMinigameInitSpawnEvents, %i);
               if(isObject(%brick))
                {
                   $inputTarget_Self = %brick;
                   $inputTarget_Player = %this.player;
                   $inputTarget_Client = %this;
                   $inputTarget_Minigame = %this.minigame;
                   %brick.processInputEvent("onMinigameInitSpawn", %this);
                }
            }
        }
    }

    function serverCmdAddEvent(%client,%delay,%input,%target,%a,%b,%output,%para1,%para2,%para3,%para4)
    {
       if(%input == $Server::onMinigameInitSpawnList)
           $Server::onMinigameInitSpawnEvents = addItemToList($Server::onMinigameInitSpawnEvents,%client.wrenchBrick);
       return Parent::serverCmdAddEvent(%client,%delay,%input,%target,%a,%b,%output,%para1,%para2,%para3,%para4);
    }

    function serverCmdClearEvents(%client)
    {
       if(hasItemOnList($Server::onMinigameInitSpawnEvents,%client.wrenchBrick))
        {
           $Server::onMinigameInitSpawnEvents = removeItemFromList($Server::onMinigameInitSpawnEvents,%client.wrenchBrick);
        }
       Parent::serverCmdClearEvents(%client);
    }

    function fxDtsBrick::onDeath(%brick)
    {
       if(hasItemOnList($Server::onMinigameInitSpawnEvents,%brick))
        {
           $Server::onMinigameInitSpawnEvents = removeItemFromList($Server::onMinigameInitSpawnEvents,%brick);
        }
       Parent::onDeath(%brick);
    }
};
activatepackage(onMinigameInitSpawn);

function addItemToList(%string,%item)
{
   if(hasItemOnList(%string,%item))
       return %string;

   if(%string $= "")
       return %item;
   else
        return
%string SPC %item;
}
function hasItemOnList(%string,%item)
{
   for(%i=0;%i<getWordCount(%string);%i++)
    {
       if(getWord(%string,%i) $= %item)
           return 1;
    }
   return 0;
}
function removeItemFromList(%string,%item)
{
   if(!hasItemOnList(%string,%item))
       return %string;

   for(%i=0;%i<getWordCount(%string);%i++)
    {
       if(getWord(%string,%i) $= %item)
        {
           if(%i $= 0)
               return getWords(%string,1,getWordCount(%string));
           else if(%i $= getWordCount(%string)-1)
               return getWords(%string,0,%i-1);
           else
                return getWords
(%string,0,%i-1) SPC getWords(%string,%i+1,getWordCount(%string));
        }
    }
}



there's already an onMinigameJoin tho

there's already an onMinigameJoin tho
yes but i want to use pathcam events to tour the player if he/she is new around the map just once

yes but i want to use pathcam events to tour the player if he/she is new around the map just once
that's already a separate add-on too! or wait, i think it only does a stationary view? i don't remember, i've never actually used it

it only does stationary

there's already an onMinigameJoin tho
Yes, but he says

Basically, when the player spawns and is new to the server, the input event onFirstSpawn will be triggered. But if a player has already been to the server before, it will not trigger.
Which is what this does. The onMinigameJoin will always trigger when the join the minigame everytime.

I'll be honest, I don't know how to make code work. Sorry if this is something pretty easy to do, but I would love to have this as an addon, so could someone turn that code into a functioning one for me? (That I could just drag into my addons folder)

make a folder in add-ons called event_firstspawn
then add a description.txt to the folder with two lines, title: bleh, and author: bleh
then make a server.cs file and copy the code into it

alternatively you could probably make a server.cs file, put the code into it, and drag it into an addon you don't use (which only has a description.txt and server.cs in it) and use that instead
it'll break the old addon but change it to this