Discord
Login
Community
DARK THEME

messages

how i can code that when you in a near of an object(char) you can press a button(space) and then a dialogue came i use the helpers from mrlam

what is "mrlam" ?

explore >> search >> text

https://microstudio.dev/i/osterberg/texttools/

https://microstudio.dev/i/DanMan97/chat/

@DanMan97 thanks that what i look for how can i make that multiple npc say other things

I guess give the npc a special I'd ID number so they say a specific phrase for their id

If you're confused then it's ok here is some code:

npc = class
  constructor = function(x,y,name,limit,id)
    this.x = x
    this.y = y
    this.dist = 0
    this.chat = false
    this.chatprogress = 1
    this.name = name
    this.limit = limit
    this.id = id
  end
  chatting = function()
    if this.chat == false then
      player_movement()
    end
    this.dist = sqrt((this.x - player_x)^2 + (this.y-player_y)^2)
    if this.dist < 50 and keyboard.C then
      this.chat = true
    end
    if this.chat == true and keyboard.press.SPACE and this.chatprogress != this.limit then
      this.chatprogress = this.chatprogress + 1
    elsif this.chat == true and keyboard.press.ESCAPE and this.chatprogress == this.limit then
      this.chat = false
      this.chatprogress = 1
    end
  end
  display = function()
    if this.dist < 50 and this.chat == false then
      screen.drawText("Press 'C' to chat",this.x, this.y+20,10,"rgb(255,255,255)")
    end
    if this.id == 1 then
      if this.chat == true then
        screen.fillRect(-150,-20,50,50,"rgb(0,255,0)")
        screen.drawText(":D",-150,-20,40,"rgb(0,0,0)")
        screen.drawText(this.name,-80,-20,40,"rgb(255,255,255)")
        screen.fillRect(0,-70,screen.width,60,"rgb(48,48,48)")
        screen.drawRect(0,-70,screen.width,60,"rgb(255,255,0)")
        if this.chatprogress == 1 then
          screen.drawText("Hi!",0, -60,20,"rgb(0,0,0)")
          screen.drawText("(press space to continue)",0, -75,20,"rgb(0,0,0)")
        end
        if this.chatprogress == 2 then
          screen.drawText("This is the end",0, -60,20,"rgb(0,0,0)")
          screen.drawText("(press esc to exit)",0, -75,20,"rgb(0,0,0)")
        end
      end
    end

    #Different ID 
    if this.id == 2 then
      if this.chat == true then
        screen.fillRect(-150,-20,50,50,"rgb(0,255,0)")
        screen.drawText(":D",-150,-20,40,"rgb(0,0,0)")
        screen.drawText(this.name,-80,-20,40,"rgb(255,255,255)")
        screen.fillRect(0,-70,screen.width,60,"rgb(48,48,48)")
        screen.drawRect(0,-70,screen.width,60,"rgb(255,255,0)")
        if this.chatprogress == 1 then
          screen.drawText("Different chat",0, -60,20,"rgb(0,0,0)")
          screen.drawText("(press space to continue)",0, -75,20,"rgb(0,0,0)")
        end
        if this.chatprogress == 2 then
          screen.drawText("Differnt this is the end",0, -60,20,"rgb(0,0,0)")
          screen.drawText("(press esc to exit)",0, -75,20,"rgb(0,0,0)")
        end
      end
    end
    screen.fillRect(this.x,this.y,20,20,"rgb(0,255,0)")
    screen.drawText(":D",this.x, this.y,15,"rgb(0,0,0)")
    
  end
end

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community