piranha modifying concerns
Posted: Wed Jan 04, 2017 7:24 pm
I came up with the idea of a piranha plant that throws hammers (customized to look like snow balls). I made some sort of code were the plant repeatedly shoots like about ten times before hiding again. It works properly with one piranha plant, but since I used a basic "timer" and onTick functions, the more piranha plants there are on screen, the more fishy is their behavior, wich would lead to some unfair enemy patterns.
This is the code:
The only solution I had was to force all the piranhas into the control of one counter, so all of them will come out, shoot, and hide at the same time. I ended up creating some horrible freaks of nature, so I better stick with the code above.
But nevertheless I've seen some Lua codes were the modifications made to one NPC are independent of what the other NPC's of the same ID do. What do I mean? well, for example, the Moar Rinkas Api haves this bouncing purple rinkas that change direction when touching a block, but if I tried to replicate that, I would only be able to make one rinka bounce naturally, as all the other rinkas on screen would act as if they also bounced, but without touching a block. Just because one rinka bounced, the speed of all the rinkas will change at the same time. So, is there a detail that I am missing? something that I am ignorant about?
Also, there is no information at all about the "ai" of the piranha plant that shoots fireballs on the wiki. It is not something grave, because I figured out easily the pattern of that NPC, but it still confuses me. Anybody can edit articles on that wiki, right?
This is the code:
Code: Select all
local newpirai = 0
function onTick()
for i,piranha in ipairs(NPC.get(245,-1)) do
Text.print(piranha.ai1,0,0)
Text.print(piranha.ai2,0,20)
if piranha.ai2 == 2 then
if piranha.ai1 > 43 then
if piranha.ai1 < 51 then
newpirai = newpirai + 1
end
end
if newpirai < 71 then
if piranha.ai1 == 50 then
piranha.ai1 = 44
end
end
if newpirai == 71 then
piranha.ai1 = 51
newpirai = 0
end
end
end
for j,piraice in ipairs(NPC.get(246,-1)) do
piraice.id = 30
end
end
But nevertheless I've seen some Lua codes were the modifications made to one NPC are independent of what the other NPC's of the same ID do. What do I mean? well, for example, the Moar Rinkas Api haves this bouncing purple rinkas that change direction when touching a block, but if I tried to replicate that, I would only be able to make one rinka bounce naturally, as all the other rinkas on screen would act as if they also bounced, but without touching a block. Just because one rinka bounced, the speed of all the rinkas will change at the same time. So, is there a detail that I am missing? something that I am ignorant about?
Also, there is no information at all about the "ai" of the piranha plant that shoots fireballs on the wiki. It is not something grave, because I figured out easily the pattern of that NPC, but it still confuses me. Anybody can edit articles on that wiki, right?