BR_Gustavo

Sistema de Label

Sep 16th, 2018
112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     !!!     AVISO !!!
  3.     Coloque   S_LabelCriarDb(); em algum lugar do OnGameModeInit
  4.     !!!     AVISO !!!
  5.     Boa Sorte! :)
  6. */
  7. //==============================G_Label===========================================
  8. #define NumeroMaximoLabels (100)
  9. #define DIALOG_GLABEL      (8176)
  10. #define DIALOG_GLABEL1     (8177)
  11.  
  12. enum G_Label
  13. {
  14.     Label_ID,
  15.     Label_Cor,
  16.     Label_Texto[50],
  17.     Label_Cor2[50],
  18.     Label_Data[50],
  19.     Label_Criador[50],
  20.     Float:Label_X,
  21.     Float:Label_Y,
  22.     Float:Label_Z,
  23.     Text3D:Label_Label,
  24. };
  25. new
  26.     DB:LabelDB,
  27.     Sistem_Label_Info[NumeroMaximoLabels][G_Label],
  28.     Ultimo_Label_ID[2];
  29.  
  30. forward S_LabelCriarDb();
  31. public S_LabelCriarDb()
  32. {
  33.     LabelDB = db_open("labels.db");
  34.     db_query(LabelDB,"CREATE TABLE IF NOT EXISTS `labels` (`ID` NUMBERIC,`Texto` TEXT,`Criador` TEXT,`Data` TEXT,`X` TEXT,`Y` TEXT,`Z` TEXT,`Cor` TEXT)");
  35.     SetTimer("S_CarregarLabels",1500,false);
  36.     return 1;
  37. }
  38. forward S_CarregarLabels();
  39. public S_CarregarLabels()
  40. {
  41.     LabelDB = db_open("labels.db");
  42.     db_query(LabelDB,"CREATE TABLE IF NOT EXISTS `labels` (`ID` NUMBERIC,`Texto` TEXT,`Criador` TEXT,`Data` TEXT,`X` TEXT,`Y` TEXT,`Z` TEXT,`Cor` TEXT)");
  43.     new Pasta_Labels[100],DBResult:Resultado;
  44.     for(new i = 0; i < NumeroMaximoLabels; i++) {
  45.     format(Pasta_Labels, sizeof(Pasta_Labels),"SELECT * FROM labels WHERE ID = %d",i);
  46.     Resultado = db_query(LabelDB, Pasta_Labels);
  47.     if(db_num_rows(Resultado)) {
  48.     new Informacao_Label[8][50];
  49.     db_get_field_assoc(Resultado,"ID",Informacao_Label[0],50);
  50.     Sistem_Label_Info[i][Label_ID] = strval(Informacao_Label[0]);
  51.     new ID_Label = Sistem_Label_Info[i][Label_ID];
  52.     db_get_field_assoc(Resultado,"X",Informacao_Label[1], 50);
  53.     db_get_field_assoc(Resultado,"Y",Informacao_Label[2], 50);
  54.     db_get_field_assoc(Resultado,"Z",Informacao_Label[3], 50);
  55.     db_get_field_assoc(Resultado,"Data",Informacao_Label[4], 50);
  56.     db_get_field_assoc(Resultado,"Criador",Informacao_Label[5], 50);
  57.     db_get_field_assoc(Resultado,"Cor",Informacao_Label[6], 50);
  58.     db_get_field_assoc(Resultado,"Texto",Informacao_Label[7], 50);
  59.     Sistem_Label_Info[ID_Label][Label_Cor2] = Informacao_Label[6];
  60.     Sistem_Label_Info[ID_Label][Label_Texto] = Informacao_Label[7];
  61.     Sistem_Label_Info[ID_Label][Label_Data] = Informacao_Label[4];
  62.     Sistem_Label_Info[ID_Label][Label_Criador] = Informacao_Label[5];
  63.     Sistem_Label_Info[ID_Label][Label_Cor] = S_PegarCorTexto3d(Informacao_Label[6]);
  64.     Sistem_Label_Info[ID_Label][Label_X] = floatstr(Informacao_Label[1]);
  65.     Sistem_Label_Info[ID_Label][Label_Y] = floatstr(Informacao_Label[2]);
  66.     Sistem_Label_Info[ID_Label][Label_Z] = floatstr(Informacao_Label[3]);
  67.     Sistem_Label_Info[ID_Label][Label_Label] = CreateDynamic3DTextLabel(Informacao_Label[7],S_PegarCorTexto3d(Informacao_Label[6]),Sistem_Label_Info[ID_Label][Label_X],Sistem_Label_Info[ID_Label][Label_Y],Sistem_Label_Info[ID_Label][Label_Z],40, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, STREAMER_3D_TEXT_LABEL_SD);
  68.     Ultimo_Label_ID[0] = ID_Label;
  69.     Ultimo_Label_ID[1] = i;}}
  70.     db_free_result(Resultado);
  71.     printf(" Numero de Labels Carregados: %d",Ultimo_Label_ID[0]);
  72.     return 1;
  73. }
  74. stock S_PegarCorTexto3d(CorNome[])
  75. {
  76.     if(!strcmp(CorNome,"red",true)){ return 0xFF0000FF;}else
  77.     if(!strcmp(CorNome,"green",true)){ return 0x00FF00FF;}else
  78.     if(!strcmp(CorNome,"yellow",true)){ return 0xFFFF00FF;}else
  79.     if(!strcmp(CorNome,"darkgreen",true)){ return 0x008B00FF;}else
  80.     if(!strcmp(CorNome,"grey",true)){ return 0xCACACAAA;}else
  81.     if(!strcmp(CorNome,"cyan",true)){ return 0x00BFFFFF;}else
  82.     if(!strcmp(CorNome,"pink",true)){ return 0xFF66FFAA;} // O Ultimo não pode ter "else"
  83.     return -255;
  84. }
  85. stock S_PegarLabelJogaodor(playerid)
  86. {
  87.     new ID_ULTIMO_LABEL = Ultimo_Label_ID[1];
  88.     ID_ULTIMO_LABEL+=1;
  89.     for(new i=0; i<ID_ULTIMO_LABEL; i++){
  90.     new ID_Label = Sistem_Label_Info[i][Label_ID];
  91.     if(IsPlayerInRangeOfPoint(playerid,10.0,Sistem_Label_Info[ID_Label][Label_X],Sistem_Label_Info[ID_Label][Label_Y],Sistem_Label_Info[ID_Label][Label_Z])){
  92.     return ID_Label;}}
  93.     return -255;
  94. }
  95. forward S_CriarNovoLabel(playerid);
  96. public S_CriarNovoLabel(playerid)
  97. {
  98.     new Float:JogadorPosicao[3],InformacaoLabel[5][50],JogadorTempo[3];
  99.     GetPlayerPos(playerid,JogadorPosicao[0],JogadorPosicao[1],JogadorPosicao[2]);
  100.     GetPVarString(playerid,"Label_Texto",InformacaoLabel[0],50);
  101.     GetPVarString(playerid,"Label_Cor",InformacaoLabel[1],50);
  102.     Ultimo_Label_ID[0]++;
  103.     Ultimo_Label_ID[1]++;
  104.     Sistem_Label_Info[Ultimo_Label_ID[1]][Label_ID] = Ultimo_Label_ID[0];
  105.     new ID_Label = Sistem_Label_Info[Ultimo_Label_ID[1]][Label_ID];
  106.     Sistem_Label_Info[ID_Label][Label_X] = JogadorPosicao[0];
  107.     Sistem_Label_Info[ID_Label][Label_Y] = JogadorPosicao[1];
  108.     Sistem_Label_Info[ID_Label][Label_Z] = JogadorPosicao[2];
  109.     Sistem_Label_Info[ID_Label][Label_Cor2] = InformacaoLabel[1];
  110.     Sistem_Label_Info[ID_Label][Label_Cor] = S_PegarCorTexto3d(InformacaoLabel[1]);
  111.     Sistem_Label_Info[ID_Label][Label_Texto] = InformacaoLabel[0];
  112.     format(InformacaoLabel[2],50,"%s",pName(playerid));
  113.     Sistem_Label_Info[ID_Label][Label_Criador] = InformacaoLabel[2];
  114.     getdate(JogadorTempo[2],JogadorTempo[1],JogadorTempo[0]);
  115.     format(InformacaoLabel[3],50,"%d/%d/%d",JogadorTempo[0],JogadorTempo[1],JogadorTempo[2]);
  116.     Sistem_Label_Info[ID_Label][Label_Data] = InformacaoLabel[3];
  117.     new InserirDbLabel[350];
  118.     format(InserirDbLabel,sizeof(InserirDbLabel),"INSERT INTO `labels`(`ID`,`Texto`,`Criador`,`Data`,`X`,`Y`,`Z`,`Cor`) VALUES ('%d','%s','%s','%s','%f','%f','%f','%s')",ID_Label,InformacaoLabel[0],\
  119.     InformacaoLabel[2],InformacaoLabel[3],JogadorPosicao[0],JogadorPosicao[1],JogadorPosicao[2],InformacaoLabel[1]);
  120.     db_query(LabelDB,InserirDbLabel);
  121.     Sistem_Label_Info[ID_Label][Label_Label] = CreateDynamic3DTextLabel(InformacaoLabel[0],S_PegarCorTexto3d(InformacaoLabel[1]),Sistem_Label_Info[ID_Label][Label_X],Sistem_Label_Info[ID_Label][Label_Y],Sistem_Label_Info[ID_Label][Label_Z],40, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, STREAMER_3D_TEXT_LABEL_SD);
  122.     return 1;
  123. }
  124. //------------------------------------------------------------------------------
  125. CMD:label(playerid,params[])
  126. {
  127.     if(PlayerInfo[playerid][LoggedIn] == 0)return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
  128.     if(!IsPlayerAdmin(playerid) && PlayerInfo[playerid][Level] < 4)return SendClientMessage(playerid,red,"ERROR: You need to be RCON to use this command");{
  129.     ShowPlayerDialog(playerid,DIALOG_GLABEL,DIALOG_STYLE_INPUT,"{00BFFF}Label","{00BFFF}Please insert the text to be placed on the label (nothing with insults)","Next","Close");}
  130.     return 1;
  131. }
  132. //------------------------------------------------------------------------------
  133. CMD:removelabel(playerid,params[])
  134. {
  135.     new RemoverLabelDb[250],LabelRemoverInfo[50]="Null";
  136.     if(PlayerInfo[playerid][LoggedIn] == 0)return SendClientMessage(playerid,red,"ERROR: You must be logged in to use this commands");
  137.     if(!IsPlayerAdmin(playerid) && PlayerInfo[playerid][Level] < 4)return SendClientMessage(playerid,red,"ERROR: You need to be RCON to use this command");{
  138.     if(S_PegarLabelJogaodor(playerid) <=-1)return SendClientMessage(playerid,red,"ERROR: You are not near a label");
  139.     format(RemoverLabelDb,sizeof(RemoverLabelDb),"DELETE FROM `labels` WHERE `ID` = '%d'",S_PegarLabelJogaodor(playerid));
  140.     db_query(LabelDB,RemoverLabelDb);
  141.     new ID_Label = S_PegarLabelJogaodor(playerid);
  142.     DestroyDynamic3DTextLabel(Sistem_Label_Info[ID_Label][Label_Label]);
  143.     Sistem_Label_Info[ID_Label][Label_X] = 0.0;
  144.     Sistem_Label_Info[ID_Label][Label_Y] = 0.0;
  145.     Sistem_Label_Info[ID_Label][Label_Z] = 0.0;
  146.     Sistem_Label_Info[ID_Label][Label_Cor2] = LabelRemoverInfo;
  147.     Sistem_Label_Info[ID_Label][Label_Cor] = -1;
  148.     Sistem_Label_Info[ID_Label][Label_Texto] = LabelRemoverInfo;}
  149.     return 1;
  150. }
  151. //==============================G_Label===========================================
  152.  
  153.  
  154. //public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  155. //{
  156. //==============================G_Label===========================================
  157.     if(dialogid == DIALOG_GLABEL){
  158.     if(response){
  159.     if(strlen(inputtext) <=0){
  160.     SendClientMessage(playerid,red,"ERROR: You need to enter text to create the label");
  161.     ShowPlayerDialog(playerid,DIALOG_GLABEL,DIALOG_STYLE_INPUT,"{00BFFF}Label","{00BFFF}Please insert the text to be placed on the label (nothing with insults)","Next","Close");}else
  162.     if(strlen(inputtext) >=1){
  163.     SetPVarString(playerid,"Label_Texto",inputtext);
  164.     ShowPlayerDialog(playerid,DIALOG_GLABEL1,DIALOG_STYLE_LIST,"{00BFFF}Label","{FF0000}Red\n{FFFF00}Yellow\n{00FF00}Green\n{008B00}Dark Green\n{CACACA}Grey\n{00BFFF}Cyan\n{FF66FF}Pink","Next","Back");}}}
  165.     if(dialogid == DIALOG_GLABEL1){
  166.     if(!response){
  167.     SetPVarString(playerid,"Label_Texto"," ");
  168.     ShowPlayerDialog(playerid,DIALOG_GLABEL,DIALOG_STYLE_INPUT,"{00BFFF}Label","{00BFFF}Please insert the text to be placed on the label (nothing with insults)","Next","Close");}
  169.     if(response){
  170.     switch (listitem){
  171.     case 0: { SetPVarString(playerid,"Label_Cor","red"); S_CriarNovoLabel(playerid);}
  172.     case 1: { SetPVarString(playerid,"Label_Cor","yellow"); S_CriarNovoLabel(playerid);}
  173.     case 2: { SetPVarString(playerid,"Label_Cor","green"); S_CriarNovoLabel(playerid);}
  174.     case 3: { SetPVarString(playerid,"Label_Cor","darkgreen"); S_CriarNovoLabel(playerid);}
  175.     case 4: { SetPVarString(playerid,"Label_Cor","grey"); S_CriarNovoLabel(playerid);}
  176.     case 5: { SetPVarString(playerid,"Label_Cor","cyan"); S_CriarNovoLabel(playerid);}
  177.     case 6: { SetPVarString(playerid,"Label_Cor","pink"); S_CriarNovoLabel(playerid);}
  178.     }}}
  179.  
  180. //==============================G_Label===========================================
  181.  
  182. //  return 1;
  183. //}
RAW Paste Data