SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Editing > Editing Help

Reply
 
Thread Tools Search this Thread
Old 07-29-2018   #1
Labyrinthia
Man, I have no idea
 
Labyrinthia's Avatar
Default Delay button press check & shields gfx issues, help?

So, I won't bother with the specific details but I made this silly script as a concept for something else I'm working on.

Code:
local CANCHANGE = false
local CANREVERT = true

addHook("ThinkFrame", function()
	for player in players.iterate do
		if player.mo.skin == "sonic"
		and player.mo.health >= 6
		and player.powers[pw_shield] == SH_NONE
			CANCHANGE = true
		else
			CANCHANGE = false
		end

		if player.mo.skin == "sonic"
		and player.powers[pw_shield] != SH_NONE
			CANREVERT = true
		else
			CANREVERT = false
		end

		if CANCHANGE == true
		and (player.cmd.buttons & BT_CUSTOM1)
			player.powers[pw_shield] = SH_BOMB
			player.mo.health = player.mo.health - 5
			player.health = $1 - 5
			S_StartSound(nil, sfx_shield)
		end

		if CANREVERT == true
		and (player.cmd.buttons & BT_CUSTOM1)
			player.powers[pw_shield] = SH_NONE
			S_StartSound(nil, sfx_shldls)
		else
			return
		end
	end
end)
This should give you the Armageddon Shield (as long as you have no shields) if you pressed CUSTOM 1, at the cost of 5 rings. And then it should remove any shield you have if you pressed CUSTOM 1 again.

It works "fine", yes, but I'm running into 2 issues:
  1. The game is calling the function way too much (every frame that CUSTOM1 is being held instead of only once per keypress, no matter how long it's held)
  2. The sprite for the shield simply doesn't appear even though it is there, as in, still protects me from a hit and explodes like it should.

I'm guessing that the second one is because calling the shield doesn't also spawns the sprite for it, so I might have an idea or two to circumvent it but I don't know how to work with the first one. Is it possible to make a time window that pressing CUST1 won't activate the script? Or make it so that after the function is called once, it won't happen again until you release the key and press it again? Genuinely don't know what to do here.
Labyrinthia is offline   Reply With Quote
Old 07-29-2018   #2
742mph
My work is never done yet
 
742mph's Avatar
Default

* You can use P_SpawnShieldOrb(player) to set player's shield orb appearance to the appropriate one.

* To detect when a player first presses a button, store in a player-specific variable whether they are holding that button, and update that variable at the end of your once-per-tic thinker. This means that, during your thinker, the variable represents whether the player was holding the button last tic. When they're holding the button right now, but weren't holding it last tic, that means they've pressed it.
__________________
Quote:
<Evilgasm> the opposite of egoraptor is Toa Tahu
742mph is offline   Reply With Quote
Old 07-29-2018   #3
Labyrinthia
Man, I have no idea
 
Labyrinthia's Avatar
Default

Quote:
Originally Posted by 742mph View Post
* You can use P_SpawnShieldOrb(player) to set player's shield orb appearance to the appropriate one.

* To detect when a player first presses a button, store in a player-specific variable whether they are holding that button, and update that variable at the end of your once-per-tic thinker. This means that, during your thinker, the variable represents whether the player was holding the button last tic. When they're holding the button right now, but weren't holding it last tic, that means they've pressed it.
WOAH this took a while, more than I'm proud to admit, but thank you. I got it working!
Labyrinthia is offline   Reply With Quote
Old 07-29-2018   #4
Steel Titanium
 
Steel Titanium's Avatar
Default

I would like to point out that this.
Code:
S_StartSound(nil, sfx_shldls)
Code:
S_StartSound(nil, sfx_shield)
Would cause the sound to play for every player in the server, if in a netgame, just add a player argument to the end of the functions so the sound only plays for the player who triggered it, like so.
Code:
S_StartSound(nil, sfx_shldls, player)
__________________
I regret something I never did.
Steel Titanium is online now   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.