[XP]Simple script problem

Started by maximusmaxy, August 19, 2011, 03:17:17 am

Previous topic - Next topic

maximusmaxy

I'm trying to create a simple class that shows an exclamation over your head when you stand in a certain place and direction. This is what i got so far

class Exclamation
  def initialize(player_x,player_y,direction)
    if player_x == $game_player.x && player_y == $game_player.y && direction == $game_player.direction
      $game_player.animation_id = 98
    end
  end
end


I put a script call in a parallel process like Exclamation.new(2,7,8) but when the character is in position the animation plays continuously instead of just once. I put in a switch to try and counter this problem but nothing changes.

class Exclamation
  def initialize(player_x,player_y,direction)
    if player_x == $game_player.x && player_y == $game_player.y &&
       direction == $game_player.direction && !@check
      $game_player.animation_id = 98
      @check = true
    else
      @check = false
    end
  end
end


If there is a completely different/better way to do this that would be very helpful

Apidcloud

I lol'd xD
Well, you said you're using the call script on a parallel process right? that's why it does the animation over and over again :P
Basically it's initializing the class all the time.

You can use local switches, so that won't happen...

Also, there's a good script for that kind of stuff.
#===============================================================================
#
#Por: santa.society | grungeisnotdead
#Versão: 1.0
#Data: 29/09/2007
#Colaborações: LBMaker | ColaOssos
#
#===============================================================================

#• Atrib_Emoticon
# Guarda o nome do emoticon e a quantidade de frames
class Atrib_Emoticon
  attr_accessor       :id
  attr_accessor       :frames
 
  def initialize(id, frames)
    @id = id
    @frames = frames
  end
end

#• Emoticon
class Emoticon
  # Acessar variaveis da Classe Atrib_Emoticon
  attr_accessor       :id
  attr_accessor       :frames
  # Iniciando
  def initialize(emoticon, position)
    # Aqui é aonde se cria cada emoticon,
    # adicione dentro da hash o seguinte:
    # @emoticon = {
    # "key1"  => Atrib_Emoticon.new("nome_da_imagem1", frames_da_imagem1),
    # "key2"  => Atrib_Emoticon.new("nome_da_imagem2", frames_da_imagem2),
    #            }
    # onde keyX é o nome de como vc vai chamar o sript posteriormente
    #(Emoticon.new("keyX",0), "nome_da_imagem" é o nome da imagem propriamente
    # dita, e "frames_da_imagem" é o numero de frames que a imagem possui
    @emoticon = {
                  "ok"  => Atrib_Emoticon.new("ok", 16),
                  "!"   => Atrib_Emoticon.new("!", 11),
                  "dot" => Atrib_Emoticon.new("dot", 20),
                  "$"   => Atrib_Emoticon.new("$", 12),
                  "Continuar" => Atrib_Emoticon.new("Continuar", 9)
                }
    # Se a posição for igual a zero
    if position == 0 # pq é q aki se usa position e nao @position
      # setar o emoticon para o player
      @position = $game_player #pq é q aki se usa @position
    # Se for maior que zero
    elsif position > 0
      # setar o emoticon para o evento indicado na posição
      @position = $game_map.events[position]#[ ] numero do evento
    end
    # Iniciando variaveis de contagem
    @cont = 0
    @cont_q = 0
    @count = 0
    # Número de quadrados que a animação tem
    @quad = @emoticon[emoticon].frames
    # Criando a Imagem
    @anima_emoticons = Sprite.new
    @anima_emoticons.x = @position.screen_x - 25
    @anima_emoticons.y = @position.screen_y - 60
    @anima_emoticons.z = 999
    @anima_emoticons.bitmap = RPG::Cache.picture(@emoticon[emoticon].id)# ?
    # Largura da Imagem
    @larg = @anima_emoticons.bitmap.width / @quad
    # Rect da Imagem
    @anima_emoticons.src_rect = Rect.new(@cont * @larg, 0, @larg, @anima_emoticons.bitmap.height)
    # Enquanto countagem for menor que o numero ude quadros
    while @count <= @quad
      # Atualiza os graficos
      Graphics.update
      # Se delay for 2
      if delay(2)
        # Adiciona contagens
        @count += 1
        @cont +=1
        # x = contagem vezes a largura da imagem
        x = @cont * @larg
        # Recriando a Rect da Imagem
        @anima_emoticons.src_rect = Rect.new(x, 0, @larg, @anima_emoticons.bitmap.height)
      end
    end
  end
  # Delay
  def delay(quadros)
    # Se Contagem de frames dos graficos for maior ou igual ao numero indicado
    # de quadros
    if (Graphics.frame_count - @cont_q >= quadros)
      # contagem é igual ao numero de Contagem de frames dos graficos
      @cont_q = Graphics.frame_count
      # retorna verdadeiro
      return true
    end
    # retorna falso
    return false
  end
end


It's commented by me on portuguese, but you can translate it with translator(I'm lazy right now :P)
All you need is to configure @emoticon hash up there with the keys and the arguments of the Atrib_Emoticon class.
You need to configure in this hash every 'animated' image that you want to use...(notice that this picture is cached on pictures folder)
the first example is:
"ok"  => Atrib_Emoticon.new("ok", 16)

"ok" is the key word that you will use to call this animation.
the first argument of Atrib_Emoticon is the name of the picture cached. The second one is the number of frames of the same picture.


To call this, simply create a normal event, doesn't need any local switches or parallel process, and on call script, do just like in this example:
Emoticon.new("ok", 2)

the first argument is the keyword that you configured previously on the hash.
the second argument is the position of this animation.
If you read the script, you'll notice that if it's 0, the animation will occur above the event that called this.
If it is higher than 0, then it will occur above the event with that id.

If you use a number that doesn't exists in terms of event id's it will raise an error obviously :P This could be easily corrected by adding a branch but I don't see any point of using numbers that will raise an error lol

See you :)
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

maximusmaxy

Thanks for the script, i couldn't get it to work the way i wanted it to though. I was using my script in a parallel process so i could reference a location without an event having to be there, or usually because there is already an event there so i can't call the script by using player touch.
Thanks for you help by the way  :)

Apidcloud

I'm glad it helped, but did you try the event without being on parallel?
You can use either local switches or let it as trigger :P Should work as well ^^

By the way, if you want to use the script, I can post here some pictures that were on its Demo.
It has exclamation point as well :P
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

maximusmaxy

A link to the demo would be lovely

Apidcloud

Quote from: maximusmaxy on August 20, 2011, 12:59:35 am
A link to the demo would be lovely


Well I don't remember from where I download it, but the name is emoticons 1.0 xD
*Points to google search*
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit