Bancos e cadeiras - Parte 1
Autor: SubHeaven | Publicado: 2008-07-08T08:24:00-07:00

Bom... Antes de fazer a integração do meu mapa inicial com o MySQL eu resolvi fazer mais alguns ajustes no mapa e criar bancos sentáveis para os jogadores.Comecei com as funções do Malese Kish, pois ja tinha testado o módulo e ele é cheio de ótimas idéias. Porém, os bancos só tinham espaço para uma pessoa sentar. Ficava estranho, e fui pesquisar uma maneira de resolver isso.Acabei encontrando e baixando as Sittable Chair do Pacha e dentro dele tinha um blueprint chamado SitBox. Eu então montei um grupo onde colocava um banco comum e tres SitBox dentro dele (O SitBox é invisível) e funcionou quase perfeitamente. O personagem sentava no ar e só depois era transportado para o banco. Nos scripts do Malese Kish isso não acontecia e, comparando os dois códigos, eu percebi que o Patcha usava os comandos ActionJumpToLocation e ActionPlayCustomAnimation enquanto que o Moloch usava apenas JumpToLocation e PlayCustomAnimation. Eu alterei as linhas e, como suspeitava, o problema foi resolvido. Alterei também o comando onde era calculado a direção pra onde o jogador ficaria depois de sentado, pois a versão do Patcha era bem estranho.O evento OnUse do SitBox ficou assim://:://///////////////////////////////////////////////:: OnUse: Sit//:: pat_sitted//::///////////////////////////////////////////////*    Simple script to make PCs sit on a placeable*///::////////////////////////////////////////////////:: Created By: Patcha//:: Created On: 2006-12-08//:: v1.76 By: Patcha//:: v1.73 On: 2007-06-15//:: dates: aaaa-mm-gg//::////////////////////////////////////////////////::Change: SubHeaven 07/05/2008 Changed the functions ActionJumpToLocation for //                               JumpToLocation and ActionPlayCustomAnimation//                               for PlayCustonAnimation to fix the where the //                               PC sit in the air before be transported for//                               the chair location.//::Change: SubHeaven 07/05/2008 Changed the funcion GetNormalizedDirection() for//                               only the GetFacing to fix bugs with the PC directions//                               after sitting.void ActionPlayCustomAnimation(object oObject, string sAnimationName, int nLooping, float fSpeed = 1.0f){    PlayCustomAnimation(oObject, sAnimationName, nLooping, fSpeed);}// float GetNormalizedDirection(float fDirection):// * This script returns a direction normalized to the range 0.0 - 360.0// * Copyright (c) 2002 Floodgate Entertainment// * Created By: Naomi Novik// * Created On: 11/08/2002float GetNormalizedDirection(float fDirection){    float fNewDir = fDirection;    while (fNewDir >= 360.0) {        fNewDir -= 360.0;    }    while (fNewDir <= 0.0) {        fNewDir += 360.0;    }    return fNewDir;}void main(){ object oChair = OBJECT_SELF; object oSitter = GetLastUsedBy();    object oLastSitter = GetLocalObject(oChair, "lastsitted");    string sChair = GetTag(oChair);    string sAutofit = GetLocalString(oChair, "autofit"); int iHeading  = GetLocalInt(oChair, "degree"); int iPC_size  = GetLocalInt(oChair, "size");    //Assign the heading degrees location lChair_o = GetLocation(oChair);  //Old code: Change #2    //location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetNormalizedDirection(GetFacingFromLocation(lChair_o) + iHeading)); //New code : Change #2 location lChair = Location(GetArea(oChair), GetPositionFromLocation(lChair_o), GetFacing(oChair)); //End Change #2     //Check if seat is free    if(GetDistanceBetween(oLastSitter, oChair) == 0.0f && GetArea(oLastSitter) == GetArea(oChair))    {        SetLocalInt(oChair, "taken", 1);        SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);    }    else //if seat is free...    {        SetLocalInt(oChair, "taken", 0);     //Check for Character Race with original Creature Size     switch (iPC_size)     {     case 0:      //Check for Character Race with original Creature Size      if( ((GetRacialType(oSitter) == RACIAL_TYPE_ELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetRacialType(oSitter) == RACIAL_TYPE_HALFELF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetRacialType(oSitter) == RACIAL_TYPE_HALFORC) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetRacialType(oSitter) == RACIAL_TYPE_HUMAN) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetSubRace(oSitter) == RACIAL_SUBTYPE_AASIMAR) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetSubRace(oSitter) == RACIAL_SUBTYPE_TIEFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)))      {       if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))       {     //Debug     //SendMessageToPC(GetFirstPC(), "Testando Sitting PC size 0");          //Old code: Change #1        //AssignCommand(oSitter, ActionJumpToLocation(lChair));        //AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));     //NewCode: Change #1     AssignCommand(oSitter, JumpToLocation(lChair));     PlayCustomAnimation(oSitter,"sitidle",1);     //End Change #1                    SetLocalObject(oChair, "lastsitted", oSitter);       }      }      else            {                if(sAutofit != "")                {                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));                    AssignCommand(oSitter, DestroyObject(oChair));                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_" + sAutofit, lChair_o, FALSE, sChair);                    if(!(GetIsObjectValid(oChair)))                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_low_stool01", lChair_o, FALSE, sChair);     //Old code: Change #1         //AssignCommand(oSitter, ActionJumpToLocation(lChair));        //AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1))     //NewCode: Change #1     AssignCommand(oSitter, JumpToLocation(lChair));     PlayCustomAnimation(oSitter,"sitidle",1);     //End Change #1;                    SetLocalString(oChair, "autofit", sAutofit);                 SetLocalInt(oChair, "degree", iHeading);                 SetLocalInt(oChair, "size", 1);                    SetLocalObject(oChair, "lastsitted", oSitter);                }                else          SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);            }      break;     case 1:      //Check for Character Race with original Creature Size      if( ((GetRacialType(oSitter) == RACIAL_TYPE_DWARF) && (GetCreatureSize(oSitter) == CREATURE_SIZE_MEDIUM)) ||       ((GetRacialType(oSitter) == RACIAL_TYPE_GNOME) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)) ||       ((GetRacialType(oSitter) == RACIAL_TYPE_HALFLING) && (GetCreatureSize(oSitter) == CREATURE_SIZE_SMALL)))      {       if(GetIsObjectValid(oChair) && GetIsObjectValid(oSitter))       {     //Old code: Change #1        //AssignCommand(oSitter, ActionJumpToLocation(lChair));     //AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1))     //NewCode: Change #1     AssignCommand(oSitter, JumpToLocation(lChair));     PlayCustomAnimation(oSitter,"sitidle",1);     //End Change #1;     AssignCommand(oSitter, ActionJumpToLocation(lChair));     PlayCustomAnimation(oSitter,"sitidle",1);                    SetLocalObject(oChair, "lastsitted", oSitter);       }      }      else            {                if(sAutofit != "")                {                    AssignCommand(oChair, SetIsDestroyable(TRUE, FALSE, FALSE));                    AssignCommand(oSitter, DestroyObject(oChair));                    oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_" + sAutofit, lChair_o, FALSE, sChair);                    if(!(GetIsObjectValid(oChair)))                        oChair = CreateObject(OBJECT_TYPE_PLACEABLE, "pat_mid_stool01", lChair_o, FALSE, sChair);        //Old code: Change #1     //AssignCommand(oSitter, ActionJumpToLocation(lChair));        //AssignCommand(oSitter, ActionPlayCustomAnimation(oSitter, "sitidle", 1));     //NewCode: Change #1     AssignCommand(oSitter, JumpToLocation(lChair));     PlayCustomAnimation(oSitter,"sitidle",1);     //End Change #1                    SetLocalString(oChair, "autofit", sAutofit);                 SetLocalInt(oChair, "degree", iHeading);                 SetLocalInt(oChair, "size", 0);                    SetLocalObject(oChair, "lastsitted", oSitter);                }                else          SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);            }      break;     default:      //Character with no original Race and/or Creature size         SpeakOneLinerConversation("", OBJECT_INVALID, TALKVOLUME_WHISPER);      break;     } }}Por fim, faltava apenas um problema. O personagem atravessava o banco e isso parecia meio estranho. Eu então apenas adicionei um CollisionBox, mudei seu tamanho para 1;0,02;1 e posicionei no encosto do banco.Se quiser, você pode baixar o Prefab aqui. Basta copiar o arquivo para a pasta Override e reiniciar o toolset. Ele aparecerá lá em BluePrints -> Prefabs.Você vai notar que ele esta sem nome. Na verdade, o que era pra ser o nome está em tag, e o nome ficou em branco. Ainda não consegui resolver esse bug.Agora uma ScreenShot de como ficou:Aqui um erf apenas com o SitBox do Patcha ja com a nova script.