limiting time between script execution?

Discuss all aspects related to modding Zandronum here.
Post Reply
Tango
 
Posts: 21
Joined: Tue Jun 19, 2012 1:20 am

limiting time between script execution?

#1

Post by Tango » Wed Feb 13, 2013 3:13 am

not sure if that's really the best title but here goes.

i think it'd be neat to have some sort of time freeze command (but without skulltag's lolorange screen time freeze sphere). something you could activate just by a single key press. say you press X and freeze command is activated for 5 seconds. but before you can do it again, the game forces you to wait some amount of seconds before you can activate it again.

some sort of hud indication of when it's available to use/ability to upgrade how frequently it's used and how long it lasts would eventually be cool too but i'll start with the basics

anyway i think i can set up global script stuff and key bindings but beyond the basics i am pretty clueless

Catastrophe
Retired Staff / Community Team Member
Posts: 2571
Joined: Sat Jun 02, 2012 2:44 am

RE: limiting time between script execution?

#2

Post by Catastrophe » Wed Feb 13, 2013 3:18 am

Bind <keyhere> "freeze"

^ Do that in the console.

User avatar
Ænima
Addicted to Zandronum
Posts: 3582
Joined: Tue Jun 05, 2012 6:12 pm

RE: limiting time between script execution?

#3

Post by Ænima » Wed Feb 13, 2013 3:25 am

If you wanted to make a mod that does that, you'd have to inherit from PowerTimeFreezer.

http://zdoom.org/wiki/Classes:PowerTimeFreezer
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

Tango
 
Posts: 21
Joined: Tue Jun 19, 2012 1:20 am

RE: limiting time between script execution?

#4

Post by Tango » Wed Feb 13, 2013 3:41 am

Catastrophe wrote: Bind <keyhere> "freeze"

^ Do that in the console.
yeah but the problem with that is i can keep pressing X to freeze and unfreeze whenever the hell i want. even if i added a bit that specified wait 100 tics and then unfreeze, there's nothing to stop me from just pushing the key again etc etc.
Ænima wrote: If you wanted to make a mod that does that, you'd have to inherit from PowerTimeFreezer.

http://zdoom.org/wiki/Classes:PowerTimeFreezer
ah, thank you. it looks like that's virtually the same as the freeze command though right? and i guess since it's a powerup it's not quite the same as just binding something to a key and limiting usage of that key press. i'll look into it though, thank ye kindly

HexaDoken
Forum Regular
Posts: 352
Joined: Wed Jul 04, 2012 8:27 am
Location: Void. Russian Void.

RE: limiting time between script execution?

#5

Post by HexaDoken » Wed Feb 13, 2013 4:51 am

Time freeze powerup is NOT the same as the freeze command :U It freezes music.
On the other hand, freeze command doesn't work in multiplayer, while this does.

To limit the usage of a key for a certain amount of time, do next:
1) Create a dummy Inventory item. It does nothing, you can't use it, but it can sit in your inventory.
2) When executing the freeze script, check if you have this inventory. If yes, do nothing(probably display a message).
3) If you do not have it, give it and freeze time away. Execute another script while we're at it.
4) That script is going to just Delay() the required amount of time, and take the inventory away.

This is the most basic cooldown setup. It doesn't allow you to measure how much cooldown time you have left, though. To do that, you can give multiple of inventory items, take them one by one in each period of time, and measure the cooldown time remaining by the amount of items remaining. Experiment.

Tango
 
Posts: 21
Joined: Tue Jun 19, 2012 1:20 am

RE: limiting time between script execution?

#6

Post by Tango » Wed Feb 13, 2013 6:01 am

aha. in between my latest post and yours, HexaDoken, i started doing a similar method, but i couldn't get it to work anyway. i was trying to use ACS_Execute in the frames of the timefreeze decorate entry... as i said, didn't work, but it was unnecessary anyway. i ended up doing essentially what you suggested, but without the dumm inventory item. if you're curious:

[spoiler]#include "zcommon.acs"

int hastime;

Script 799 (void)
{
If(hastime == FALSE)
GiveInventory("timefreezer1", 1);
ACS_ExecuteAlways(800, 1, 0, 0, 0);
}

script 800 (void)
{
hastime = true;
Delay(200);
hastime = false;
}[/spoiler]

such a basic thing i've wanted to do for years... never bothered really trying though. what would be an advantage to your method verbatim HexaDoken over this one?

thank you all, it is much appreciated

edit: ok i found a problem. can apparently keep pushing the key really quickly and it'll keep repeating. will try to fix later sigh
Last edited by Tango on Wed Feb 13, 2013 6:05 am, edited 1 time in total.

HexaDoken
Forum Regular
Posts: 352
Joined: Wed Jul 04, 2012 8:27 am
Location: Void. Russian Void.

RE: limiting time between script execution?

#7

Post by HexaDoken » Thu Feb 14, 2013 5:34 am

You should learn some ACS syntax. Particulary the fact that whatever goes to the If block must be in curly braces.

Code: Select all

If(hastime == FALSE)
{
GiveInventory("timefreezer1", 1);
ACS_ExecuteAlways(800, 0, 0, 0, 0);
}
Like that. Also, I dunno why the second argument of your ACS_ExecuteAlways is 1, it should be 0.
Advantage of your method over mine is that it has a slightly less resource cost(I think?) while my method is actually multiplayer compatible.

Sirion
New User
Posts: 17
Joined: Sat Aug 04, 2012 1:55 pm

RE: limiting time between script execution?

#8

Post by Sirion » Thu Feb 14, 2013 3:54 pm

I'm not sure what you want, but try something like this:

Decorate:
[spoiler]

Code: Select all

Actor X_CoolDown : PowerDamage
{
	DamageFactor "Nothing", 1.0
	Powerup.Duration 35 //You can also type -1 instead of 35 for one second
}
[/spoiler]

ACS:
[spoiler]

Code: Select all

Script 100 (void) //This script gets executed by your button
{
    if( CheckInventory("X_CoolDown") )
        terminate;

    /* .... do stuff .... */
}
[/spoiler]

The timer (aka X_CoolDown) will vanish after one second on its own (Zandronum checks for Powerups and their powerup duration. If the time counter is beyond the duration limit, the item goes away.)

Post Reply