Jump to content

Anderl

Members
  • Posts

    2,266
  • Joined

  • Last visited

Everything posted by Anderl

  1. JavaSDK has no function to create windows, as far as I know. I think you're trying to say Java and.. start learning Java before try to do big things...
  2. A função guiCreateLabel e guiCreateMemo são totalmente diferentes. Mas, guiSetProperty funciona com todos os elementos da CEGUI. Você pode ver todas as propriedades no GUIEditor.
  3. This isn't even a part of OOP. Where did you create a method? Where are objects? You just created a table and created a function inside it. Also, the title says "Object Behavior from OOP" not "Object Behavior".
  4. Also, change in server-side "setElementPostition" to "setElementPosition".
  5. Create colshape for each player and play the voice chat only for players inside the colshape.
  6. Hi guys. I have a hosting company where I host MTA servers but.. these times Game-Monitor showed servers as offline so I searched and I found that Game-Monitor was not working properly ( it was having troubles with database ). Now, I saw that servers appear as online in Game-Monitor but they continue appearing as offline in GameCP. Is that a problem of a Game-Monitor yet?
  7. Update do sistema de classes, alguns bugs na criação da classe ( chaves __type e __name não estavam funcionando corretamente ): --[[ Classlib ver.4-20494b Written by Anderl ]]-- Class = { } local registered = { } --register new class local function register( c ) if ( registered[c.__name] ) then return false; end registered[c.__name] = true; return true; end --unregister class if exists local function unregister( c ) if ( not registered[c.__name] ) then return false; end registered[c.__name] = nil; return true; end --check if class exists local function isregistered( c ) if ( type( c ) ~= 'table' ) then return false; end if ( registered[c.__name] ) then return true; else return false; end end --create new class function class( init ) if ( not init ) then assert ( false, 'Attempt to create class [no init]' ); end loadstring( init .. ' = { }; c = '.. init )( ); c.__type = "class"; c.__name = t.init; setmetatable ( c, Class ); register( c ); end --check if is class, return string or false function isclass( c ) return type( c ) == 'table' and c.__type == 'class' or false; end --return boolean, check if class exists function class_exists( c ) return isregistered( c ); end --remove class, return false if class doesn't exists function class_remove( c ) if ( type( c ) ~= 'table' ) then return false; end if ( isregistered( c ) ) then unregister( c ) c = nil; return true; else return false; end end
  8. Então, basicamente uma classe é uma estrutura com vários membros, neste caso funções, que estão "inter-ligadas" entre si. Você pode chamar outras funções da mesma classe usando a "variável" self, igual em C++ this. Como LUA é orientada a funções e não a objetos, existem as metatabelas, que basicamente fazem o mesmo trabalho. Uma classe define o "comportamente" de seus membros ( objectos da classe ) através de métodos, Aqui um exemplo de um método: myClass = { } myClass.__index = myClass; function myClass:init( ) --> método -- instruçoes end Aqui um exemplo de um sistema de banco, parecido com o do site da linguagem LUA: account = { } -- cria uma tabela que sera nossa classe -- declara o metodo 'new' que retorna uma instance da nossa conta function account:new( balance ) -- se nenhum balanço for passado cria uma nova tabela com balanço 0 b = balance or { balance = 0 } -- define a metatabela da nossa conta para account setmetatable(b,account); -- retorna a nossa conta return b; end -- declara o metodo 'withdraw' que retorna o balanço da conta se nenhum balanço for passado function account:withdraw( self, balance ) -- se nenhum balanço for passado if( not balance ) then -- retorna o balanço da conta return self.balance; end -- se a conta tiver grana suficiente if( self.balance >= balance ) then -- retira a grana da conta self.balance = self.balance - balance; end -- retorna o balanço da conta se nada for retornado, eu poderia ter usado 'else' tambem para o statement acima return self.balance; end Agora: acc = account:new( ) -- return object of ur acc acc:withdraw( 20 ); -- retorna o balanço da conta account.withdraw( acc, 20 ) -- isto faz o mesmo mas sem objecto Aí, tava sem nada pra fazer, então fiz um sistema de classes que torna tudo mais fácil em códigos muito grandes: class 'account'; function account:new( balance ) b = balance or { balance = 0 } setmetatable(b,account); return b; end function account:withdraw( self, balance ) if( not balance ) then return self.balance; end if( self.balance >= balance ) then self.balance = self.balance - balance; end return self.balance; end if( class_exists( account ) ) then acc = account:new( 500 ); acc:withdraw( 20 ); -- retorna o balanço da conta account.withdraw( acc, 20 ) -- isto faz o mesmo mas sem objecto end class_remove( account ); print( class_exists( account ) and 'true' or 'false' ); -- false; E o código fica muito melhor. Não sei se é isto que você pretende, se não for, avise
  9. Se você precisar de ajudar só falar..
  10. 192.168.1.146:21892 Hum....... Internal IP? Nice! I'm gonna join right now -.-
  11. Se ele não entender alguma coisa, ele pode perguntar aqui que eu posso ajudar, ou até você, se puder
  12. Eu botei uma explicação da Wikipedia no post.. http://pt.wikipedia.org/wiki/Classe_(pr ... %A7%C3%A3o)
  13. Cara, mas se ele não consegue entender e nós não mostrarmos a ele como faz, como você acha que ele vai aprender? ._.
  14. Add timer only after the player hit the marker or... Why do you even need a timer for that?
  15. This code will give you error cuz "player" argument is nil.
  16. Anderl

    Scripter

    i will scripting for free i will accept every job for fair price. WTF?!
  17. Desculpem pelo double post.. Mas, aqui o código totalmente corrigido e re-escrito: Client-side: class 'core'; addEventHandler( 'onClientResourceStart', resourceRoot, function( ) -- if class not created if( not core ) then return; end -- load gui core.loadWindows(); -- stuff addEventHandler( 'onClientGUIClick', root, core.fnOnClick ); addCommandHandler( 'wantedstats', core.openWindow ); -- settings core.__width = 800; -- mude aqui para a largura da sua tela ( que voce usou para criar a GUI ) core.__height = 600; -- mude aqui para a altura da sua tela ( que voce usou para criar a GUI ) end ) function core.loadWindows( ) -- declare screen size variables local iSX, iSY = guiGetScreenSize( ); -- create first gui core._windowA[1] = guiCreateWindow( ( 80 / core.__width ) * iSX, ( 80 / core.__height ) * iSY, ( 250 / core.__width ) * iSX, ( 250 / core.__height ) * iSY, '', false ); guiWindowSetSizable( core._windowA[1], false ); guiSetVisible( core._windowA[1], false ); core._labelA[1] = guiCreateLabel( ( 20 / core.__width ) * iSX, ( 20 / core.__height ) * iSY, ( 250 / core.__width ) * iSX, ( 60 / core.__height ) * iSY, 'Janela de Alteração de Nivel de Procurado', false, core._windowA[1] ); core._labelA[2] = guiCreateLabel( ( 10 / core.__width ) * iSX, ( 55 / core.__height ) * iSY, ( 250 / core.__width ) * iSX, ( 60 / core.__height ) * iSY, 'Nome do Jogador:', false, core._windowA[1] ); core._labelA[3] = guiCreateLabel( ( 30 / core.__width ) * iSX, ( 90 / core.__height ) * iSY, ( 250 / core.__width ) * iSX, ( 60 / core.__height ) * iSY, 'Nivel de Procurado:', false, core._windowA[1] ); core._editA[1] = guiCreateEdit( ( 120 / core.__width ) * iSX, ( 50 / core.__height ) * iSY, ( 120 / core.__width ) * iSX, ( 25 / core.__height ) * iSY, '', false, core._windowA[1] ); core._editA[2] = guiCreateEdit( ( 160 / core.__width ) * iSX, ( 85 / core.__height ) * iSY, ( 80 / core.__width ) * iSX, ( 25 / core.__height ) * iSY, '', false, core._windowA[1] ); core._memoA[1] = guiCreateMemo(( ( 10 / core.__width ) * iSX, ( 120 / core.__height ) * iSY, ( 230 / core.__width ) * iSX, ( 80 / core.__height ) * iSY, 'Identifique o jogador e selecione o nivel de procurado paa alterar. Os niveis são 0-6!', false, core._windowA[1] ); core._buttonA[1] = guiCreateButton( ( 0 / core.__width ) * iSX, ( 210 / core.__height ) * iSY, ( 120 / core.__width ) * iSX, ( 30 / core.__height ) * iSY, 'Alterar nivel', false, core._windowA[1] ); core._buttonA[2] = guiCreateButton( ( 130 / core.__width ) * iSX, ( 210 / core.__height ) * iSY, ( 120 / core.__width ) * iSX, ( 30 / core.__height ) * iSY, 'Fechar', false, core._windowA[1] ); -- create second gui core._windowB[1] = guiCreateWindow( ( 200 / core.__width ) * iSX, ( 150 / core.__height ) * iSY, ( 200 / core.__width ) * iSX, ( 120 / core.__height ) * iSY, '', false ); guiWindowSetSizable( core._windowB[1], false ); guiSetVisible( core._windowB[1], false ); core._labelB[2] = guiCreateLabel( ( 10 / core.__width ) * iSX, ( 20 / core.__height ) * iSY, ( 200 / core.__width ) * iSX, ( 200 / core.__height ) * iSY, ' Você deseja realmente\nalterar o nível de procurado deste\njogador?', false, core._windowB[1] ); core._buttonB[1] = guiCreateButton( ( 0 / core.__width ) * iSX, ( 20 / core.__height ) * iSY, ( 90 / core.__width ) * iSX, ( 100 / core.__height ) * iSY, 'Confirmar', false, core._windowB[1] ); core._buttonB[2] = guiCreateButton( ( 100 / core.__width ) * iSX, ( 80 / core.__height ) * iSY, ( 90 / core.__width ) * iSX, ( 100 / core.__height ) * iSY, 'Cancelar', false, core._windowB[1] ); end function core.fnOnClick( ) -- if( source == core._buttonA[2] ) then guiSetVisible( core._windowA[1], false ); showCursor( guiGetVisible( core._windowA[1] ) ); guiSetInputEnabled( false ); -- elseif( source == core._buttonA[1] ) then guiSetVisible( core._windowB[1], true ); showCursor( guiGetVisible( core._windowB[1] ) ); guiSetInputEnabled( true ); -- elseif( source == core._buttonB[1] ) then triggerServerEvent( 'onStupidStar', localPlayer, guiGetText( core._editA[2] ), getPlayerFromPart( guiGetText( core._editA[1] ) ) or nil ); guiSetVisible( core._windowA[1], false ); showCursor( guiGetVisible( core._windowA[1] ) ); guiSetInputEnabled( false ); -- elseif( source == core._buttonB[2] ) then guiSetVisible( core._windowB[1], true ); showCursor( guiGetVisible( core._windowB[1] ) ); guiSetInputEnabled( true ); end end function core.openWindow( ) guiSetVisible( core._windowA[1], true ); showCursor( guiGetVisible( core._windowA[1] ) ); guiSetInputEnabled( true ); end -- function getPlayerFromPart( s ) -- if parameter is string if( type( s ) == 'string' ) then -- declare matches table local matches = { } -- loop all players and check their names for i,v in ipairs( getElementsByType 'player' ) do if( string.find( getPlayerName( v ), tostring( s ), 0 ) ) then -- insert element in table table.insert( matches, v ); end end -- if only one player found if ( #matches == 1 ) return matches[1]; end end return false; end Server-side: addEvent( 'onStupidStar', true ); addEventHandler( 'onStupidStar', root, function( nivel, player ); setElementData( player, 'Level', tonumber( nivel ) ); setPlayerWantedLevel( player, tonumber( nivel ) ); outputChatBox( 'O seu nível de procurado foi alterado!', player, 255, 255, 0 ); end ) Veja os comentários e use meu sistema de classes para que o código funcione: viewtopic.php?f=152&t=44583
  18. Hello Eu fiz eu sistema de classes à um tempo atraz e decidi publicar ele aqui para vocês. Aqui tem uma explicação do que é uma classe: http://pt.wikipedia.org/wiki/Classe_(pr ... %A7%C3%A3o) As funções do sistema de classes são as seguintes: -- Funções locais ( não edite nem remova elas, e também não as use se não souber o que está fazendo ): bool register ( class c ); bool unregister ( class c ); bool isRegistered ( class c ); -- Funções públicas: void class ( init ); bool isclass ( class c ); bool class_exists ( class c ); bool class_remove ( class c ); Exemplo: class 'core'; function core:load( ) self.print( 'Oi Oi Oi' ); end function core.print( s ) if( type( s ) == 'string' ) then _G['print']( s ); end end print( isclass( core ) ); -- true; print( class_exists( core ) ); -- true; class_remove( core ); -- true; core:load(); -- Attempt to index global 'core' (a nil value) core.print(); -- Attempt to index global 'core' (a nil value) print( isclass( core ) ); -- false; print( class_exists( core ) ); -- false; Então, o código está aqui: --[[ Classlib ver.3-20494b Written by Anderl ]]-- Class = { } local registered = { } --register new class local function register( c ) if ( registered[c.__name] ) then return false; end registered[c.__name] = true; return true; end --unregister class if exists local function unregister( c ) if ( not registered[c.__name] ) then return false; end registered[c.__name] = nil; return true; end --check if class exists local function isRegistered( c ) if ( type( c ) ~= 'table' ) then return false; end if ( registered[c.__name] ) then return true; else return false; end end --create new class function class( init ) if ( not init ) then assert ( false, 'Attempt to create class [no init]' ); end loadstring( init .. ' = { __type = "class", __name = init }; c = '..init )( ); setmetatable ( c, Class ); register( c ); end --check if is class, return string or false function isclass( c ) return type( c ) == 'table' and c.__type and c.__type == 'class' or false; end --return boolean, check if class exists function class_exists( c ) return isRegistered( c ); end --remove class, return false if class doesn't exists function class_remove( c ) if ( type( c ) ~= 'table' ) then return false; end if ( isRegistered( c ) ) then unregister( c ) c = nil; return true; else return false; end end Aproveite e organize seu código com isso. P.S. - Só para não vir falar "Qem é esse Anderl?", "Você esqueceu de roubar os créditos no ficheiro :lol:".. Eu sou o Anderl, tendeu?
  19. Source in those events is the marker, not the player element.
  20. 3) Na linha 70, você tem: "who = getPlayerName(localPlayer)". Logo abaixo, você tem a condição: "if (who) then". Só que "who" não é um valor booleano, "who" é uma string. Ou seja, essa condição também nunca é chamada. Você também precisa prestar atenção no retorno de cada função. Qualquer valor diferente de FALSE ou NIL é TRUE. Então, essa condição é TRUE, e é chamada. No entanto, é inútil a usar pois localPlayer sempre vai ser um elemento PLAYER e sempre vai retornar o nome do jogador.
  21. Não, está errado. Ele quer retornar o dado 'Level' do jogador com o nome do EditBox. Ele apenas está botando a função fora do evento 'onClientGUIClick', o que está errado.
  22. client is source, as far as I know. Source in those events is the marker, not the player element.
  23. The module is made by MTA Team too.
×
×
  • Create New...