piranha modifying concerns

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
ivanmegafanboy
Flurry
Flurry
Posts: 175
Joined: Wed Aug 12, 2015 11:47 am

piranha modifying concerns

Postby ivanmegafanboy » 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:

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
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?

Kevsoft
Ripper II
Ripper II
Posts: 375
Joined: Sun Jul 27, 2014 8:03 am

Re: piranha modifying concerns

Postby Kevsoft » Thu Jan 05, 2017 2:07 am

There is information about ai values: ai values

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: piranha modifying concerns

Postby Hoeloe » Thu Jan 05, 2017 2:56 am

Your problem is that newpirai is shared across all of the NPCs. When you modify it for one, you're not using a different counter later, so it's altering other NPC's behaviours.

What you can do is either directly modify the NPC AI value, or use PNPC to wrap up the NPCs, and use the additional "data" table that comes with it, to store information per-NPC rather than using just one counter.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari