Module API FAQ |
Scrollerkey « Citoyen » 1404850620000
| 0 | ||
I'm spawning objects using tfm.exec.addShamanObject(). I've managed to create a semi-functional spawn clock for people being able to spawn the boxes. All I need now is proper box despawning. I'll post my code: boxTimer = 0 despawnTime = 1 -- .5 seconds spawnTime = 0 spawnWaitTime = 5 -- .5 seconds function eventNewPlayer(playerName) tfm.exec.bindKeyboard(playerName, 32, true, true) end for i,v in pairs(tfm.get.room.playerList) do tfm.exec.bindKeyboard(i, 32, true, true) end function eventKeyboard(playerName, key, down, x, y) key = 32 if down == true and tfm.get.room.playerList[playerName].isFacingRight and spawnTime == 0 then tfm.exec.addShamanObject(1, x + 20, y - 10, 0, 40, false) spawnTime = 1 boxTimer = 0 elseif down == true and not tfm.get.room.playerList[playerName].isFacingRight and spawnTime == 0 then tfm.exec.addShamanObject(1, x - 20, y - 10, 0, -40, false) spawnTime = 1 boxTimer = 0 end end function eventLoop() if spawnTime < spawnWaitTime and spawnTime >= 1 then spawnTime = spawnTime + 1 else if spawnTime == spawnWaitTime then spawnTime = 0 end if boxTimer == despawnTime then --if tfm.get.room.objectList[id] then --tfm.exec.removeObject(id) --end else boxTimer = boxTimer + 1 end end end My main issue is finding out how I can properly get the id to the boxes that are being spawned. Would I use a "for" command like what I did for a few other things? |
Shamousey « Consul » 1404851460000
| 0 | ||
tfm.exec.addShamanObject() returns the ID of the shaman object it spawns. Try something like this: ids={} table.insert(ids,tfm.exec.addShamanObject(1,400,200)) for i,id in ipairs(ids) do tfm.exec.removeObject(id) table.remove(ids,i) end |
Scrollerkey « Citoyen » 1404876840000
| 0 | ||
All right, I added that (and added a few more things to enhance the experience), and it worked. My only issue now is that the object doesn't despawn fast enough. .5 seconds is too long for what I'm trying to do. I've hatched the idea to make it so that the item is removed after it has traveled a certain distance away from its origin (or from the player) on the X axis. My only issue is that I have no idea how to. I discovered that I could make the player a usable variable (which helped a lot), but I don't know if I can set the player's location as one or how I'd even make the box despawn when it is however-many units away from the player. Here is what my code looks like so far: boxTimer = 0 despawnTime = 1 -- .5 seconds spawnTime = 0 spawnWaitTime = 5 -- .5 seconds --realSpawnTime = spawnTime * 2 --realSpawnWaitTime = spawnWaitTime * 2 function eventNewPlayer(playerName) tfm.exec.bindKeyboard(playerName, 32, true, true) end for i,v in pairs(tfm.get.room.playerList) do tfm.exec.bindKeyboard(i, 32, true, true) end ids = {} function eventKeyboard(playerName, key, down, x, y) key = 32 playerX = x butt = playerName if down == true and tfm.get.room.playerList[playerName].isFacingRight and spawnTime == 0 then table.insert(ids,tfm.exec.addShamanObject(1, x + 20, y - 10, 0, 40, false)) spawnTime = 1 boxTimer = 0 elseif down == true and not tfm.get.room.playerList[playerName].isFacingRight and spawnTime == 0 then table.insert(ids,tfm.exec.addShamanObject(1, x - 20, y - 10, 0, -40, false)) spawnTime = 1 boxTimer = 0 end end function eventLoop() if spawnTime < spawnWaitTime and spawnTime >= 1 then spawnTime = spawnTime + 1 elseif spawnTime == spawnWaitTime then spawnTime = 0 end if boxTimer >= despawnTime then for i,id in ipairs(ids) do tfm.exec.removeObject(id) table.remove(ids,i) print(id) end else boxTimer = boxTimer + 1 end if spawnTime == 0 then ui.addTextArea(0, "PUNCH!", butt) else ui.addTextArea(0, "Hold it....", butt) end end playerX wasn't out where it could be readily reached, I suppose. It may be of use or not. :/ EDIT: I see that tfm.get.room.objectList has the ability to get an object's X. I'm not too sure if I'm using the command correctly, typing wise. tfm.get.room.objectList[id].x Is that how? XD EDIT 2: I've actually managed to take the timer out of the equation and answered my own question. My only issue as of now is how slow the eventLoop() function is. Is there any way to speed it up? Dernière modification le 1405037280000 |
Jojololly « Citoyen » 1405442580000
| 0 | ||
Why isn't this script working? Thanks! ^^ eventPlayerGetCheese(String playerName) tfm.exec.killPlayer(String playerName) end tfm.exec.newGame(5231006) Dernière modification le 1405442640000 |
Eliaseeg « Citoyen » 1405443360000
| 0 | ||
Jojololly a dit : You have to define "string playername", add "function" behind eventPlayerGetCheese and add @code in tfm.exec.newGame. Here you go: function eventPlayerGetCheese(name) tfm.exec.killPlayer(name) end tfm.exec.newGame("@5231006") |
Shamousey « Consul » 1405445820000
| 0 | ||
Eliaseeg a dit : Actually that part of their code was fine, you don't need the @ symbol infront of maps for them to play with tfm.exec.newGame. |
Jojololly « Citoyen » 1405447860000
| 0 | ||
Eliaseeg a dit : Omg I didn't notice! I had just copy pasted it from the documentation :P I'm a nub. |
Daryan « Citoyen » 1405448040000
| 0 | ||
Hi can you help me at spawning shaman items via comamnd? like in #utility or if not please make me this as command (in the spoiler) for name,player in pairs(tfm.get.room.playerList) do tfm.exec.bindKeyboard(name, 16, true, true) end function eventKeyboard(name, key, down, x, y) if key == 16 then tfm.exec.addShamanObject(tfm.enum.shamanObject. ball, x, y, 0, 0, 0, false) end tfm.exec.bindKeyboard(name, 16, true, true) end |
Jojololly 1405450200000
| | ||
[Modéré par Katburger, raison : removed] Dernière modification le 1405450440000 |
Eliaseeg « Citoyen » 1405480740000
| 0 | ||
Shamousey a dit : Ooh. I've never used that way, thanks anyway |
Jojololly « Citoyen » 1405528980000
| 0 | ||
What do I put in the brackets for this? tfm.exec.setTimeLeft(Int seconds, Boolean init) |
Scrollerkey « Citoyen » 1405545720000
| 0 | ||
This: function eventMouse(playerName, x, y) print("Mouse.") end I'm curious as to why this is not responding. Am I doing it correctly? |
Eliaseeg « Citoyen » 1405556820000
| 0 | ||
Jojololly a dit : Seconds = Seconds that you want put on the map Boolean init = True or false. For example: tfm.exec.setTimeLeft(200, true) Scrollerkey a dit : You need bind the all players. function eventNewPlayer(name) system.bindMouse(name, true) end for name,_ in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end function eventMouse(playerName, x, y) print("Mouse.") end |
Podoko « Citoyen » 1405606680000
| 0 | ||
is it possible to do a "copy to clipboard" button ? |
Conwolf « Citoyen » 1405823880000
| 0 | ||
Hi...where is the list of functions and events? The one in the OP isn't working for me... |
Thewav « Citoyen » 1405850940000
| 0 | ||
Podoko a dit : With current functions no. Conwolf a dit : http://atelier801.com/topic?f=5&t=451587 |
Fierywarpath « Citoyen » 1406897460000
| 0 | ||
ok so I created a button class to make it easier for me to create custom textArea buttons. but I can't figure out how to loop through all the objects of the class. here's the link to my code: http://pastebin.com/TVq3fKCk i need to check if the mouse is in the boundaries of the button when the player clicks, and return the object if it is on one. thanks :) ok, you can ignore my previous post. I found a way to get it working myself :) here's the code if anyone wants it: http://pastebin.com/Hm0yxWtd Dernière modification le 1407284760000 |
Fierywarpath 1407235980000
| | ||
[Modéré par Whiskypickle, raison : Please do not double post, edit your existing post instead] |
Fubuuck « Citoyen » 1407997260000
| 0 | ||
Does tfm.exec.removeObject only correspond with tfm.exec.addShamanObject? Or is it possible to remove shaman items/objects spawned by the shaman. |
Shamousey « Consul » 1408030980000
| 0 | ||
tfm.exec.removeObject works with the shaman object IDs returned by tfm.get.room.objectList, tfm.exec.addShamanObject, and eventSummoningEnd. id=tfm.exec.addShamanObject(10,400,200) -- The ID of the anvil will be stored in the variable "id". tfm.exec.removeObject(id) -- The anvil will be removed. |