Question about a LUA script

Status
Not open for further replies.

Kitty Rapist

The Trustworth Douche
Uh, i was doing some LUA tests when i found myself stuck in a big tiny problem:

Basically my script is supposed to give you the magnet shield (the one that attracts rings) to you while you are in the super form, and remove it from you when you turn back to normal.

Cool, the part where "it gives the shield to you" works completely fine, but no matter what i do, i can't remove it from the player once he returns to his regular form.

Here is the both scripts i made:

This is the first one that gives you the shield when you are super:

Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo //if player exists (lolwot)
        and player.powers[pw_super] //And you're in your super form
            player.powers[pw_shield] = SH_ATTRACT //you will also have the magnet shield ability
        end
    end
end)
And this is the script that was supposed to remove it from you when you turn back to normal

Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo //if player exists (lolwot)
        and player.powers[pw_shield] = SH_ATTRACT //and you currently have the Magnet Shield
        and player.prevrings < 1 //and if your previous amount of rings are less than 1...
            player.powers[pw_shield] = SH_NONE //you will have no shields what-so-ever
        end
    end
end)
Can someone tell me what in the living hell i'm doing wrong? Because i honestly have no idea.

Really sorry for bothering any of you with this silly issue i have.


EDIT: i think that might be of some help. the console gives me this exact message when i load up the wad:

WARNING: shield.wad|LUA_SHID:4: unexpected symbol near ' ='
 
Last edited:
In the line "and player.powers[pw_shield] = SH_ATTRACT " in the second part, try replacing "=" with "==".
 
In the line "and player.powers[pw_shield] = SH_ATTRACT " in the second part, try replacing "=" with "==".

The Warning didn't appeared anymore, but it still doesn't remove the shield...
i guess the problem is in the script after all.

I'll do some changes, thank you very much for your help anyways
 
Honestly, i don't recall it exactly, but i suppose it is a check of the player previous amount of rings.
For... preventing... something from happening... i guess?

It was just a random thing i tried to do.
I first tried to use player.mo.health like i recall some LUA scripts using so but it didn't work.
So i started looking around some LUAs i had downloaded hoping to find the "missing link" that i was needing at stumbled across that.

Then i said to myself "It doesn't hurt to try, right?"

Probably i should've keep the player.mo.health before posting...
 
My modification, Great Divide, happens to already have this mechanic. Here's how I did it:

Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo) and (player.mo.health) then
			//Characters can attract rings while super
			if player.powers[pw_super] then
				player.powers[pw_shield] = SH_ATTRACT
			end
			//If player was just super and has an attraction shield, remove it
			if not (player.powers[pw_super])
			and (player.mo.wasjustsuper) then
				player.powers[pw_shield] = SH_NONE
			end

			//<other stuff you want to do>

			//From the perspective of next tic, was the player super last tic?
			if player.powers[pw_super] then
				player.mo.wasjustsuper = true
			else
				player.mo.wasjustsuper = nil
			end
		end
	end
end)
 
Last edited:
My modification, Great Divide, happens to already have this mechanic. Here's how I did it:

Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if (player.mo) and (player.mo.health) then
        //Characters can attract rings while super
        if player.powers[pw_super] then
            player.powers[pw_shield] = SH_ATTRACT
        end
        //If player was just super and has an attraction shield, remove it
        if not (player.powers[pw_super])
        and (player.mo.wasjustsuper) then
            player.powers[pw_shield] = SH_NONE
        end

        //<other stuff you want to do>

        //From the perspective of next tic, was the player super last tic?
        if player.powers[pw_super] then
            player.mo.wasjustsuper = true
        else
            player.mo.wasjustsuper = nil
        end
    end
end)


Oh, i see, i just came up with a solution before i saw this but yours looks WAY better

here's what i did:

Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo //if player exists (lolwot)
        and player.powers[pw_shield] == SH_ATTRACT //and you currently have the Magnet Shield
        and player.health ==1 //and if you have 0 rings
        and All7Emeralds(emeralds)==1 //and if you have all the emeralds, there is no way to turn super if you don't have the emeralds, so just a security check
        and not player.powers[pw_super] //and if you are not in the super form
            player.powers[pw_shield] = SH_NONE //you will have no shields what-so-ever
        end
    end
end)

It works fine, the only problem that i found in mine's is that when breaking the magnet shield box while having 0 rings will not give you any shield.

PS: why i was using player.mo.health lol? that wasn't going to work at all. good job, me.

I never thought about using a pseudo-variable to check if the player was super in the last tic, guess i have many things to learn.

Thank you again, everyone.
 
Welp, sorry for the inconvenience. but i need to ask one more question.
Instead of making a thread about every single question i come up with would be unnecessary and annoying for both users and moderators. So i'll just throw it here instead...

Anyways no more stalling, here's the question: there is any known way of reseting a stage music to it's deafult via LUA?

If that didn't made so much sense, you could say i want to create a script that would work like "tunes default".

Is that even possible?
 
COM_BufInsertText(player, "tunes default") should do the trick. It's literally writing the text in the console and executing it, all via Lua.
 
S_ChangeMusic(mapmusic) would also do the trick. If you wanted it to work only for a particular player, use S_ChangeMusic(mapmusic, true, player) instead.
 
Wait, could you do this with stuff like "name sonic; color blue"?

Yes. Any command can be executed through COM_BufInsertText(). Though people should be careful when loading certain scripts, as misuse of this function can have rather stupid consequences.
 
for player in players.iterate do COM_BufInsertText(player, [[setcontrol "jump" "KEY0"]]) end -- How the heck do you...
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top