-RoCS- Forum Index du Forum -RoCS- Forum
-Roxxor of Counter Strike-
 
 FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres   Groupes d'utilisateursGroupes d'utilisateurs 
 ProfilProfil   Vous n'avez pas de nouveaux messagesVous n'avez pas de nouveaux messages   Déconnexion [ sharkboy999 ]Déconnexion [ sharkboy999 ] 

3e personne (joolz)

 
Poster un nouveau sujet   Répondre au sujet    -RoCS- Forum Index du Forum -> Tutoriaux
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
@t0m!k
Bon cheateur


Inscrit le: 09 Avr 2004
Messages: 79
Localisation: -------> ici <-------

MessagePosté le: Ven Avr 09, 2004 7:55 pm    Sujet du message: 3e personne (joolz) Répondre en citant

Un tuto qui commencait a etre demandé par plusieurs personnes alors je me suis mis au travail, now c'est a vous

//===========================================================================================
//===========================================================================================
//====================================== Interpreter.h ===========================================
//===========================================================================================
//===========================================================================================

sous
Code:

   // execution
   void exec    (char*   cmdlist);
   void execFile(const char* filename);




ajouter
Code:

   void exec_one(const char* cmd);   

   bool verify(const char* cmdlist);
   bool verify_one(const char* cmd);




//===========================================================================================

remplacer
Code:

   void init( ClientCmdFunc a, CvarIntFunc b, CvarFloatFunc c)
   {
      fnClientCmd = a; fnCvarInt = b; fnCvarFloat = c;
   }




par
Code:

   void init()   {createRandomPrefix();}
   CommandInterpreter(){init();}

   // prefix used for commands that should bypass command blocking
   union{
      char          excludePrefixChar[5];
      unsigned long excludePrefixDword;   
   };




//===========================================================================================

remplacer
Code:

   void exec_one(char* cmd);
   void extractArguments(char* args);
   void logExec(const char* command);



par
Code:

   //void exec_one(char* cmd);
   void extractArguments(const char* args);
   void logExec(const char* command);
   void createRandomPrefix();



//===========================================================================================

remplacer
Code:

enum { CVAR_FLOAT, CVAR_INT, COMMAND, ALIAS };



par
Code:

enum { CVAR_FLOAT, CVAR_INT, COMMAND, ALIAS, HL_CVAR };



//===========================================================================================

remplacer
Code:

void extractArguments(char* args);


par
Code:

void extractArguments(const char* args);



//===========================================================================================
//===========================================================================================
//===================================== Interpreter.cpp ==========================================
//===========================================================================================
//===========================================================================================

insérer en haut
Code:

#include "cvar.h"

void HandleCvarInt(char* name, int* value);
void HandleCvarFloat(char* name, float* value);
void HlEngineCommand(const char* command);
bool isHlCvar(char* name);
void HandleHlCvar(char* name);




//===========================================================================================

mettre ces fonctinons avec les autres
Code:

bool CommandInterpreter::verify(const char* cmdlist)
{
   string my_copy = cmdlist;

   // find end:
   char* from = const_cast<char*>(my_copy.c_str());
   char* to   = from;   
   
   while(*from==' '||*from=='\t'){ ++from;++to; } // skip ws
   while(*to>=' ' && *to!= ';'){ // find end
      if(*to=='\"')
      {
         do{ ++to; }while(*to && *to!='\"');
      }
      else
      {
         ++to;
      }
   }
   
   do{
      // comments...
      if(from[0]=='/' && from[1]=='/') { return true; }

      // split up and exec
      if(from<to)
      {
         char oldch = *to;
         *to = 0;
         if(!verify_one(from))
            return false; // once we find one error, no need to continue
         *to = oldch;
      }
       
      // advance
      if(!*to) { break; }
      ++to;
      from = to;
      while(*from==' '||*from=='\t'){ ++from;++to; }  // skip ws
      while(*to>=' ' && *to!= ';') ++to;              // find end
   } while(1);
   return true;
}

bool CommandInterpreter::verify_one(const char* cur_cmd)
{
   if(*cur_cmd=='#' || *cur_cmd=='.')
   {
      return true; // not our problem if theres an error
   }

   // extract command
   char  command[32];
   char* commandPos = command;
   int   commandCharsLeft = 31;
   while(*cur_cmd>' ' && commandCharsLeft)
   {
      *commandPos = tolower(*cur_cmd);
      commandPos++;
      cur_cmd++;
      commandCharsLeft--;
   }
   *commandPos = 0;
   while(*cur_cmd>' ') cur_cmd++; // skip parts bigger than 31 chars.

   return names.find(command); // if not found then error, simple
}

void CommandInterpreter::createRandomPrefix()
{
   static char characterBox[] = "0123456789abcdefghijklmnopqrstuvwxyz"
                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ!$%&/()=?{}[]*#-.,<>~+_";
   static int len = sizeof(characterBox)-1;
   
   excludePrefixChar[0] = characterBox[rand()%len];
   excludePrefixChar[1] = characterBox[rand()%len];
   excludePrefixChar[2] = characterBox[rand()%len];
   excludePrefixChar[3] = characterBox[rand()%len];
   excludePrefixChar[4] = 0;
}




//===========================================================================================

remplacer
Code:

void CommandInterpreter::extractArguments(char* args)
{
   preExecArgs.clear();
   //ofs << args << endl;




par
Code:

void CommandInterpreter::extractArguments(const char* const_args)
{
   preExecArgs.clear();

   char* args = const_cast<char*>(const_args);




//===========================================================================================

a remplacer la fonction existante par celle ci
Code:

void CommandInterpreter::exec_one(const char* cur_cmd)
{
   if(*cur_cmd=='#' || *cur_cmd=='.')
   {
      if( false )
      {
         static string hlcommand;
         hlcommand.erase();
         hlcommand += excludePrefixChar;
         hlcommand += (cur_cmd+1);
         HlEngineCommand(hlcommand.c_str());
      }
      else
      {
         HlEngineCommand(cur_cmd+1);
      }
      return;
   }

   // extract command
   char  command[32];
   char* commandPos = command;
   int   commandCharsLeft = 31;
   while(*cur_cmd>' ' && commandCharsLeft)
   {
      *commandPos = tolower(*cur_cmd);
      commandPos++;
      cur_cmd++;
      commandCharsLeft--;
   }
   *commandPos = 0;
   while(*cur_cmd>' ') cur_cmd++; // skip parts bigger than 31 chars.

   if(names.find(command))
   {
      Entry& entry = entries[names.num];

      switch(entry.type)
      {
      case Entry::ALIAS:{
         string& content = *(string*)(entry.data);
         if(cvar.info==5)OGCmessage("ALIAS %s EXPANSION: %s\n",command, content.c_str());
         exec(const_cast<char*>(content.c_str()));
                    }break;
      case Entry::COMMAND:{
         typedef void (*CmdFunc)();
         CmdFunc function = (CmdFunc)(entry.data);
         
         extractArguments(cur_cmd);

         if(cvar.info==5)logExec(command);
         function();
                     }break;
      case Entry::CVAR_INT:
         extractArguments(cur_cmd);
         HandleCvarInt( command,   (int*)entry.data );
         break;
      case Entry::CVAR_FLOAT:
         extractArguments(cur_cmd);
         HandleCvarFloat( command, (float*)entry.data );
         break;
      case Entry::HL_CVAR:
         extractArguments(cur_cmd);
         HandleHlCvar(command);
         break;
      }
   } else {
      if(!isHlCvar(command))
      {
         OGCmessage("Unknown command: [ %s ]",command);
      }
      else
      {
         Add(command,Entry::HL_CVAR,NULL);
         extractArguments(cur_cmd);
         HandleHlCvar(command);
      }
   }
}




//===========================================================================================
//===========================================================================================
//======================================== Client.cpp ============================================
//===========================================================================================
//===========================================================================================

sous
Code:

void HandleCvarInt(char* name, int* value)
{
OGC_TRY
   char* arg1 = cmd.argC(1);
   if (!strcmp(arg1,"change"))
   {
      if (*value) *value=0; else *value=1;
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s changed to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
   if (!strcmp(arg1,"up"))     
   {
      *value += cmd.argI(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s increased to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
    if (!strcmp(arg1,"down"))   
   {
      *value -= cmd.argI(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s decreased to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
   if (!*arg1)
   {
      OGCmessage( "CVAR %s = %i\n",name,*value);
      return;
   }
   *value = cmd.argI(1);
   if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s: %d", name, *value );gHudTimer.countdown(3);}
OGC_CATCH(;)
}




mettre
Code:

void HlEngineCommand(const char* command)
{
   if(!gEngfuncs.pfnClientCmd) { return; }
   gEngfuncs.pfnClientCmd( const_cast<char*>(command) );
}

bool isHlCvar(char* name)
{
   if(!gEngfuncs.pfnGetCvarPointer) { return false; }
   
   cvar_s* test = gEngfuncs.pfnGetCvarPointer(name);
   return (test!=NULL);
}

void HandleHlCvar(char* name)
{
   if(!gEngfuncs.pfnGetCvarPointer) { return; }

   cvar_s* ptr = gEngfuncs.pfnGetCvarPointer(name);
   if(!ptr) return;

   HandleCvarFloat(name,&ptr->value);
}





//===========================================================================================

remplacer les fonctions existantes par celles ci
Code:

void HandleCvarFloat(char* name, float* value)
{

   char* arg1 = cmd.argC(1); 
   if (!strcmp(arg1,"change"))
   {
      if (*value) *value=0; else *value=1;
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s changed to %f", name, *value );gHudTimer.countdown(3); }
      return;
   }
   if (!strcmp(arg1,"up"))     
   {
      *value += cmd.argF(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s increased to %f", name, *value );gHudTimer.countdown(3);}
      return;
   }
    if (!strcmp(arg1,"down"))   
   {
      *value -= cmd.argF(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s decreased to %f", name, *value );gHudTimer.countdown(3);}
      return;
   }
   if (!strcmp(arg1,"hide"))
    {
        *value = cmd.argF(2);
        return;
    }
   if (!*arg1)
   {
      OGCmessage( "[CVAR] %s = %f\n",name,*value);
      return;
   }
    *value = cmd.argF(1);
   if(cvar.info==3||curMenu){sprintf(gHudMessage,"[ %s ]: %f", name, *value );gHudTimer.countdown(3);}

}

void HandleCvarInt(char* name, int* value)
{

   char* arg1 = cmd.argC(1);
   if (!strcmp(arg1,"change"))
   {
      if (*value) *value=0; else *value=1;
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s changed to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
   if (!strcmp(arg1,"up"))     
   {
      *value += cmd.argI(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s increased to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
    if (!strcmp(arg1,"down"))   
   {
      *value -= cmd.argI(2);
      if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s decreased to %d", name, *value );gHudTimer.countdown(3);}
      return;
   }
   if (!strcmp(arg1,"hide"))
    {
        *value = cmd.argI(2);
        return;
    }
   if (!*arg1)
   {
      OGCmessage( "[CVAR] %s = %i\n",name,*value);
      return;
   }
   *value = cmd.argI(1);
   if(cvar.info==3||curMenu){ sprintf(gHudMessage,"%s: %d", name, *value );gHudTimer.countdown(3);}
}




//===========================================================================================

dans initialize

Code:

cmd.init();


à la place de celui qui est déjà
Code:

cmd.init(gEngfuncs.pfnClientCmd,HandleCvarInt,HandleCvarFloat);



//===========================================================================================

sous
Code:

      if( gScriptMessageTimer.running() )
      {
         int x = 20;
         int y = displayCenterY*2-180-16;

         // int drawLen = DrawLen(gScriptMessage);
                  // backgroundAreaSub(x-2,y-2,drawLen+4,17,colorList.get(17));

         ColorEntry* clr=colorList.get(13);
         DrawHudString(x,y,clr->r,clr->g,clr->b,gScriptMessage );
      }




mettre
Code:

      if(cvar.chase_cam)
      {   
         cmd.exec("chase_active hide 1;r_drawviewmodel hide 0");
         cvar.chaseofs = -100;
      } else {
         cmd.exec("chase_active hide 0;r_drawviewmodel hide 1");
         cvar.chaseofs = 0.0;
      }




//===========================================================================================

sous
Code:

   if( pparams->nextView == 0 )
   {
      // Primary Screen, below all other Viewports Sent
      // update vectors for CalcScreen
      VectorCopy(pparams->viewangles,mainViewAngles);
      VectorCopy(pparams->vieworg,mainViewOrigin);
   }



mettre
Code:

      if(cvar.chaseofs)
      {
         vec3_t vecEnd, up, right, forward, EntViewOrg;
         gEngfuncs.pfnAngleVectors (mainViewAngles, forward, right, up);
         mainViewOrigin[0] += cvar.chaseofs*forward[0];
         mainViewOrigin[1] += cvar.chaseofs*forward[1];
         mainViewOrigin[2] -= cvar.chaseofs*forward[2];
      }



//===========================================================================================

et rajouter ces cvars : chaseofs et chase_cam
Code:

   cmd.AddCvarInt("chase_cam",&cvar.chase_cam);
   cmd.AddCvarFloat("chaseofs",&cvar.chaseofs);



et dans cvar.h
Code:

   int chase_cam;
   float chaseofs;





//===========================================================================================


Okay maintenant avec

chase_cam 1 vous etes en 3e personne sous joolz

Tuto testé et approuvé par Monsieur AsTroBoY

Voilà les gays, me suis bien fait chier pour celui là looool

Kiffez bien !!!

++

© DavVv 2003
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé Envoyer l'e-mail Visiter le site web du posteur MSN Messenger  
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    -RoCS- Forum Index du Forum -> Tutoriaux Toutes les heures sont au format GMT + 2 Heures
Page 1 sur 1
Surveiller les réponses de ce sujet
 
Sauter vers:  
Vous pouvez poster de nouveaux sujets dans ce forum
Vous pouvez répondre aux sujets dans ce forum
Vous pouvez éditer vos messages dans ce forum
Vous pouvez supprimer vos messages dans ce forum
Vous pouvez voter dans les sondages de ce forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
Traduction par : phpBB-fr.com