[Tool/Web/Other] (Plugin) TextDrawImage
#1

Criei agora pela noite um plugin para meu servidor de zumbi. Como ficou algo meio fora do contexto daquele projeto, vou postar como um projeto independente !!



Este plugin й uma funзгo que carrega uma imagem e converte ela em TextDraw, podendo ser mostrada aos jogadores ..
PHP код:
TextDrawImage("/scriptfiles/imagem.bmp"QUALIDADEPOSICAO XPOSICAO Y
As qualidades sгo:
BOA
MEDIA
RUIM

As posiзхes sгo em qual parte da tela o textdraw deve ficar

Exemplo:
PHP код:
TextDrawImage("/scriptfiles/imagem.bmp"RUIM
Instalaзгo:
Salve o cуdigo da include abaixo em tdi.inc na pasta pawno/includes e no seu gamemode coloque "#include tdi"
Apуs isto baixe o plugin tdi.dll no link logo abaixo e passe para pasta "plugins" entao vб no arquivo server.cfg e coloque a linha "plugins tdi"

Include:
pawn Код:
// -----------------------------------------------------------------------------

enum {
    BOA = 1,
    MEDIA,
    RUIM
}

native ConstroyTextDrawImage(s[], qualidade = MEDIA, posInicialX = 0, posInicialY = 0);

#define TextDrawImage ConstroyTextDrawImage

forward gCall@TextDrawCreate(x, y, cor);
public gCall@TextDrawCreate(x, y, cor) {

    static Text:textID;

    textID = TextDrawCreate(float(x), float(y), ".");

    TextDrawColor(textID, cor);

    TextDrawShowForAll(textID);

    return true;
}

// -----------------------------------------------------------------------------
Download do Plugin:
-> http://www.solidfiles.com/d/3c78e86cd6/

Source do plugin:
pawn Код:
///////////////////////////////////////////////////////////////////////////////
//
//
//        #### ########   ######     ######## ########    ###    ##     ##
//         ##  ##     ## ##    ##       ##    ##         ## ##   ###   ###
//         ##  ##     ## ##             ##    ##        ##   ##  #### ####
//         ##  ########   ######        ##    ######   ##     ## ## ### ##
//         ##  ##              ##       ##    ##       ######### ##     ##
//         ##  ##        ##    ##       ##    ##       ##     ## ##     ##
//        #### ##         ######        ##    ######## ##     ## ##     ##
//
//
//                    Criado por Bruno da Silva (iPs DraKiNs)
//
//          Acesse meu blog sobre programaзгo http://www.brunodasilva.com.br
//
//              Seja membro da melhor equipe de programaзгo
//         http://ips-team.forumeiros.com/t2-inform...cao-na-ips
 
//                    [iPs]TeaM soluзхes de programaзгo em geral
//
//
//                       TextDrawImage - Imagem em TextDraw
//
//
/////////////////////////////////////////////////////////////////////////////////
#include "main.h"
#include "malloc.h"

logprintf_t logprintf;
void **ppPluginData;
extern void *pAMXFunctions;

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
    return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData)
{
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    logprintf = (logprintf_t)ppData[PLUGIN_DATA_LOGPRINTF];

    logprintf("Plugin TextDrawImage Carregado | Por Bruno da Silva", PLUGIN_VERSION);
    return true;
}
PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
    logprintf("Plugin TextDrawImage Descarregado | Por Bruno da Silva");
}
/********************************************************************************/

AMX * data;
int qualidade;
int  xs, ys  ;

void WINAPI processoAlternativo(void * file);
void WINAPI processoAlternativo(void * file) {
   
    AMX*  amx = data;
    HDC img;
    SIZE size;
   
    HDC hMemDC = CreateCompatibleDC(NULL);
    char *ss;

   
    amx_StrParam(amx, (cell)file, ss)

    HBITMAP hBitmap = (HBITMAP) LoadImage (NULL, ss, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );

    if(!hBitmap) {
        logprintf("[Erro] Imagem inexistente");
    }

    else {
        BITMAP bm = {0};

        GetObject( hBitmap, sizeof(bm), &bm );

        LONG cx = bm.bmWidth;
        LONG cy = bm.bmHeight;


        if (!cx || !cy) {
            logprintf("[Erro] Imagem com tamanhos invalidos");         
        }

        else {

            int
                idx,
                x,y;

            SelectObject(hMemDC, hBitmap);

            for(x = 0; x < cx; x+=qualidade) {
                for(y = 0; y < cy; y+=qualidade) {
                    if(!amx_FindPublic(amx, "gCall@TextDrawCreate", &idx))
                    {
                        COLORREF cor = GetPixel(hMemDC, x, y)
                       
                        BYTE
                            redValue,
                            greenValue,
                            blueValue;

                        redValue = GetRValue(cor);
                        greenValue = GetGValue(cor);
                        blueValue = GetBValue(cor);



                        amx_Push(amx,  ((redValue << 0x18)|(greenValue << 0x10)|(blueValue << 0x8)|(100)));
                        amx_Push(amx, y+ys);
                        amx_Push(amx, x+xs);               
                        amx_Exec(amx, NULL, idx);
                    }
                }
            }
        }
    }
}

static cell AMX_NATIVE_CALL n_ConstroyTextDrawImage(AMX *amx, cell *params)
{
        //char * file ;

        DWORD dwXuxaTHR;

        data = amx;        
        qualidade = params[2];
        xs = params[3];
        ys = params[4];

        HANDLE hThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)processoAlternativo, (void*)params[1], 0,&dwXuxaTHR);
        return 1;
}



AMX_NATIVE_INFO nvoNatives[] =
{
    { "ConstroyTextDrawImage", n_ConstroyTextDrawImage },
    { 0, 0 }
};

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad(AMX *amx)
{
    return amx_Register(amx, nvoNatives, -1);
}
PLUGIN_EXPORT int PLUGIN_CALL AmxUnload(AMX *amx)
{
    return AMX_ERR_NONE;
}
Observaзхes Importantes:
Quote:
Nota: A imagem й carregada e mostrada para todos jogadores online. Imagens com resoluзгo MUITO ALTA poderгo ocasionar em ser cortadas, devido ao limite da SA:MP. Portando use umas imagens que fiquem em torno de 150x150 pixels !! O sistema apenas lк imagens no formato BMP

Isto dб LAG AO SERVIDOR?
Definitivamente nгo, pode deixar por alguns segundos o computador lento. Mas nгo o servidor nгo sofrerб de lags, estou utilizando um processo alternativo (threads) para processar as imagens. Mas tambйm nгo coloque isto em um loop que pode ferrar mesmo com seu servidor, atй porque seria impossнvel o servidor aguentar mais que umas 3 imagens.

----------

Este plugin foi compilado na versгo Windows 7 Ultimate. Criado por Bruno da Silva]

Atualizado 14 07 2012 as 03 35

-----------

Espero que Gostem
Reply


Messages In This Thread
(Plugin) TextDrawImage - by ipsBruno - 14.07.2012, 05:52
Re: (Plugin) TextDrawImage - by Ades - 14.07.2012, 05:56
Re : (Plugin) TextDrawImage - by ipsBruno - 14.07.2012, 06:02
Re: (Plugin) TextDrawImage - by Ades - 14.07.2012, 06:09
Re : (Plugin) TextDrawImage - by ipsBruno - 14.07.2012, 06:11
Re: (Plugin) TextDrawImage - by maikonk - 14.07.2012, 06:19
Re : (Plugin) TextDrawImage - by ipsBruno - 14.07.2012, 06:22
Re: (Plugin) TextDrawImage - by Bruno Pereira - 14.07.2012, 06:29
Re : Re: (Plugin) TextDrawImage - by ipsBruno - 14.07.2012, 06:31
Re: (Plugin) TextDrawImage - by zSuYaNw - 14.07.2012, 06:59

Forum Jump:


Users browsing this thread: 1 Guest(s)