• Do not use Works in Progress as a way of avoiding the releases system! Works in Progress can be used for sharing early betas and for getting suggestions for improvement. Releases of finished content are not allowed in this forum! If you would like to submit a finished addon, click here for instructions on how to do so.

Help with character transparency script.

Status
Not open for further replies.

CyanKnight

When the nightmare is endless!!!
I've been at this for a little over 30 minutes now and to no avail i haven't figured out how to get this to work. Can anyone help me with this?

Code: addHook("ThinkFrame", do
for player in players.iterate
if player.mo and player.mo.skin == "chaos"
if not (player.mo.frame = $1|TR_TRANS1000)
player.mo.frame = $1|TR_TRANS500
end
-----
In-game it says:
Added file trans6.lua (1 lumps)
Loading Lua script from trans6.lua
Pardon me while I initialize the Lua scripting interface...
WARNING: trans6.lua:1: '=' expected
-----
Any insight?
 
When checking values you have to use ==
There's also the fact that you're using |, which is OR, instead of & which would get the results you want.
So, change
if not (player.mo.frame = $1|TR_TRANS1000)
to
if not (player.mo.frame == player.mo.frame & TR_TRANS1000)

The "do" you have at the top should also be "function()" and not not "do"

$1 also doesn't work on checks or something. I dunno, something I've experienced before and still applies here.

Also like MPS said, TR_TRANS500 and TR_TRANS1000 aren't actual values. I'll let you fix these to what ever you want, though

Lastly, you'd need to fill out the remaining ends. With all these, it should look like:

Code:
addHook("ThinkFrame", function()
	for player in players.iterate
		if player.mo and player.mo.skin == "chaos"
			if not (player.mo.frame == player.mo.frame & TR_TRANS1000)
				player.mo.frame = $1 | TR_TRANS500
			end
		end
	end
end)
 
Last edited:
Code:
player.mo.frame = $1 & TR_TRANS500

This line here wouldn't work (if it was, for example, TR_TRANS60 instead of the non-existent TR_TRANS500) - that's the AND operator, for checking flags, and not OR, for adding flags, so it was actually right.

Also, using do does work, it's a faster way of using function(), as it doesn't need any arguments.
 
Alright, so looking at the code (specifically the part that says TR_TRANS1000) I'm going to assume you want the player to be always 50% transparent.

This would be the code you want:
Code:
addHook("ThinkFrame", do
for player in players.iterate do
if player and player.valid then

    if player.mo and player.mo.valid and player.mo.skin == "chaos" then
        player.mo.frame = $|TR_TRANS50
    end

end
end
end)
You don't need the check for full opacity, since there's no constant representing full opacity and there is no need for it either as you're just forcing the player to be transparent.
I've also added .valid checks in some parts because sometimes it happens that a player or a mobj suddenly stop being valid and any script can end spewing errors...


Also,
When checking values you have to use ==
<snip>
if not (player.mo.frame == player.mo.frame & TR_TRANS1000)
Lua doesn't explicitly require a comparator operator, like == or >= or the like.
If there is no comparator, Lua will check if the formula in the if check is true or false (false being the number 0 or any number below 0, the boolean false, or even nil, while true is the opposite).
 
Status
Not open for further replies.

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

Back
Top