Battle Maker

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Suporte para criação de Jogos


    [Online] Global Switches e Variaveis para RMX-OS

    jiraya
    jiraya
    Administrador
    Administrador


    Mensagens : 1299
    Credibilidade : 54

     [Online] Global Switches e Variaveis para RMX-OS Empty [Online] Global Switches e Variaveis para RMX-OS

    Mensagem por jiraya Sáb Jan 29, 2011 11:03 am

    [Autor: Cayoda]


    Switches e Variaveis NetGlobal para RMX-OS


    Rpg Maker XP Online System


    Introdução
    Permite que uma Switch ou uma variavel modificada por um jogador seja modificada para todos os jogadores ao ativa-la ou mudar o valor da variavel


    Script
    Crie um script acima do Main e coloque o código.
    Código:

    #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    # Global Switches and Variables for RMX-OS by Blizzard
    # Version: 1.01
    # Type: RMX-OS Add-on
    # Date: 7.1.2010
    # Date: 22.2.2010
    #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    #
    #  This script is to be distributed under the same terms and conditions like
    #  the script it was created for: RMX-OS.
    #
    #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    #
    # Information:
    #
    #  This script must be placed below RMX-OS and requires RMX-OS v1.09 or
    #  higher to work properly. This script will allow to have global switches and
    #  variables on your server.


    # If you find any bugs, please report them here:
    # [url=http://forum.chaos-project.com]http://forum.chaos-project.com[/url]
    #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
    if !defined?(RMXOS) || RMXOS::VERSION < 1.09
      raise 'ERROR: The "Global Switches and Variables" requires RMX-OS 1.09 or higher.'
    end
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    # START Configuration
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    GLOBAL_SWITCHES = [1, 2] # make sure this matches the extension configuration
    GLOBAL_VARIABLES = [1, 2] # make sure this matches the extension configuration
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    # END Configuration
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #==============================================================================
    # Game_Temp
    #==============================================================================
    class Game_Temp
     
      attr_accessor :disable_global
     
    end
     
    #==============================================================================
    # Game_Switches
    #==============================================================================
    class Game_Switches
     
      alias set_gswivar_later []=
      def []=(id, value)
        if !$game_temp.disable_global && GLOBAL_SWITCHES.include?(id)
          $network.send_switch(id, value)
        else
          set_gswivar_later(id, value)
        end
      end
     
    end
     
    #==============================================================================
    # Game_Switches
    #==============================================================================
    class Game_Variables
     
      alias set_gswivar_later []=
      def []=(id, value)
        if !$game_temp.disable_global && GLOBAL_VARIABLES.include?(id)
          $network.send_variable(id, value)
        else
          set_gswivar_later(id, value)
        end
      end
     
    end
     
    #==============================================================================
    # RMXOS::Network
    #==============================================================================
    class RMXOS::Network
     
      alias check_game_gswivar_later check_game
      def check_game(message)
        case message
        when /\AGSW(.+)\t(.+)/
          $game_temp.disable_global = true
          $game_switches[$1.to_i] = ($2 != '0')
          $game_temp.disable_global = false
          $game_map.need_refresh = true
          return true
        when /\AGVA(.+)\t(.+)/
          $game_temp.disable_global = true
          $game_variables[$1.to_i] = $2.to_i
          $game_temp.disable_global = false
          $game_map.need_refresh = true
          return true
        end
        return check_game_gswivar_later(message)
      end
     
      alias check_loading_gswivar_later check_loading
      def check_loading(message)
        result = check_loading_gswivar_later(message)
        if result
          if @messages.include?(RMXOS::LOADING_END)
            @messages.delete(RMXOS::LOADING_END)
            self.send('LGD')
          end
        else
          case message
          when /\ALGS(.+)/ # load global switches
            hash = eval($1)
            $game_temp.disable_global = true
            hash.each_key {|id| $game_switches[id] = hash[id]}
            $game_temp.disable_global = false
            return true
          when /\ALGV(.+)/ # load global variables
            hash = eval($1)
            $game_temp.disable_global = true
            hash.each_key {|id| $game_variables[id] = hash[id]}
            $game_temp.disable_global = false
            $game_map.need_refresh = true
            @messages.push(RMXOS::LOADING_END)
            return true
          end
        end
        return result
      end
     
      def send_switch(id, value)
        self.send("GSW#{id}\t#{value ? 1 : 0}")
      end
     
      def send_variable(id, value)
        self.send("GVA#{id}\t#{value}")
      end
     
    end
    Alem Disto va na pasta Extensions do seu RMX-OS Server e crie um Arquivo com extensão .rb e abra-o com algum Editor ou com Bloco de Notas e coloque o código abaixo.
    Código:

    module RMXOS
     
      def self.load_current_extension
        return GlobalSwitchesVariables
      end
     
      module Data
        GlobalSwitchChange    = 'Client 'CLIENT' changed switch 'ID' to 'STATE'.'
        GlobalVariableChange  = 'Client 'CLIENT' changed variable 'ID' to 'STATE'.'
      end
     
    end
    #======================================================================
    # module GlobalSwitchesVariables
    #======================================================================
    module GlobalSwitchesVariables
     
      VERSION = 1.01
      RMXOS_VERSION = 1.09
      SERVER_THREAD = false
     
      # START Configuration
      GLOBAL_SWITCHES = [1, 2] # make sure this matches the configuration in the client
      GLOBAL_VARIABLES = [1, 2] # make sure this matches the configuration in the client
      SWITCHES_FILENAME = './gswitches.dat' # filename for global switch saving
      VARIABLES_FILENAME = './gvariables.dat' # filename for global variable saving
      SERVER_DISPLAY = true # show log in command prompt screen
      LOG_FILENAME = './logs/gswivar.log' # leave empty if no log file should be created
      DELETE_LOG_ON_START = false
      # END Configuration
     
      def self.initialize
        @switches = {}
        GLOBAL_SWITCHES.each {|id| @switches[id] = false}
        if FileTest.exist?(SWITCHES_FILENAME)
          file = File.open(SWITCHES_FILENAME, 'r')
          ids = Marshal.load(file)
          file.close
          (ids & GLOBAL_SWITCHES).each {|id| @switches[id] = true}
        end
        @variables = {}
        GLOBAL_VARIABLES.each {|id| @variables[id] = 0}
        if FileTest.exist?(VARIABLES_FILENAME)
          file = File.open(VARIABLES_FILENAME, 'r')
          hash = Marshal.load(file)
          file.close
          (hash.keys & GLOBAL_VARIABLES).each {|id| @variables[id] = hash[id]}
        end
        File.delete(LOG_FILENAME) if LOG_FILENAME != '' && DELETE_LOG_ON_START && FileTest.exist?(LOG_FILENAME)
      end
     
      def self.main
        while RMXOS.server.running
          self.server_update
          sleep(0.1)
        end
      end
     
      def self.server_update
      end
     
      def self.client_update(client)
        case client.message
        when /\ALGD\Z/ # load global data
          client.send("[email=LGS#{@switches.inspect.sub(']LGS#{@switches.inspect.sub('[/email] ') {''}}")
          client.send("[email=LGV#{@variables.inspect.sub(']LGV#{@variables.inspect.sub('[/email] ') {''}}")
          return true
        when /\AGSW(.+)\t(.+)/ # global switch change
          id = $1.to_i
          value = ($2 != '0')
          Thread.exclusive {
            @switches[id] = value
            self.save_switches
            client.sender.send_to_all(client.message, true)
          }
          message = RMXOS::Data::GlobalSwitchChange.sub('CLIENT', client.player.username).sub('ID', id.to_s).sub('STATE', value.to_s)
          self.log(message)
          return true
        when /\AGVA(.+)\t(.+)/ # global variable change
          id = $1.to_i
          value = $2.to_i
          Thread.exclusive {
            @variables[id] = value
            self.save_variables
            client.sender.send_to_all(client.message, true)
          }
          message = RMXOS::Data::GlobalVariableChange.sub('CLIENT', client.player.username).sub('ID', id.to_s).sub('STATE', value.to_s)
          self.log(message)
          return true
        end
        return false
      end
     
      def self.save_switches
        ids = @switches.keys.find_all {|id| @switches[id]}
        file = File.open(SWITCHES_FILENAME, 'w')
        Marshal.dump(ids, file)
        file.close
      end
     
      def self.save_variables
        hash = {}
        @variables.each_key {|id| hash[id] = @variables[id] if @variables[id] != 0}
        file = File.open(VARIABLES_FILENAME, 'w')
        Marshal.dump(hash, file)
        file.close
      end
     
      def self.log(message)
        puts message if SERVER_DISPLAY
        if LOG_FILENAME != ''
          file = File.open(LOG_FILENAME, 'a')
          file.write(message + "\n")
          file.close
        end
      end
     
    end
    Agora Nomeio com o nome globalswitch e va no arquivo cfg.ini na pasta RMX-OS Server e na linha EXTENSIONS = [] digite entre os colchetes "globalswitch" com as aspas, se você ja tiver adicionado alguma extensão antes desta, coloque depois da virgula.


    Instruções de Uso
    Procure pela linha
    Código:
    GLOBAL_SWITCHES = [1, 2] # make sure this matches the extension configuration
    GLOBAL_VARIABLES = [1, 2] # make sure this matches the extension configuration
    qualquer numero digitado entre os colchetes será as switches e variaveis que serão ativadas para todos os jogadores, se tu não colocar alguma switch ou variavel nestes colchetes ela será ativada apenas para um jogador

      Data/hora atual: Qui maio 16, 2024 11:36 pm