0 votes

I'm still learning, but i seriously need help on this one, is there a way to force a player to drop one loot after timer stops?

in Engine by (14 points)

1 Answer

0 votes
var loot_timer    
func _ready():
    loot_timer = Timer.new()
    loot_timer.wait_time = 5
    loot_timer.one_shot = true
    # here is where you can specify what function gets called
    # when the timer timers out, in this case it's drop_one_loot
    loot_timer.connect("timeout",self,"drop_one_loot")
    self.add_child(loot_timer)

func some_func_to_start_timer():
    do_some_stuff()
    do_other_stuff()
    loot_timer.start()

# called when loot_timer times out based on the connect() function above
func drop_one_loot():
    var loot_to_drop = get_loot_to_drop()
    drop_loot(loot_to_drop)

That code would go in your player class. Your implementation of get_loot_to_drop() and drop_loot() are entirely up to how you've structured your loot system and game as a whole though. I would need more information about how your code is structured if you need help with that part.

by (2,834 points)

Now that I think of it, is this for one loot to be dropped? Or the entire loot? Cuz I forgot to specify that the player can choose what to drop (1item) from the player's inventory

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.