Welcome, Guest. Please login or register.

What openbor you prefer: Double dragon,battletoads or final fight !? by lirexpatrio
[December 07, 2012, 07:15:27 pm]


what are your favorite games OpenBOR?! by lirexpatrio
[December 07, 2012, 07:09:46 pm]


Post Some Awesome Videos by maxman
[December 07, 2012, 05:51:39 pm]


Can @cmd playmusic "aaaa" 1 also increse music sound ? by BeasTie
[December 07, 2012, 05:24:38 pm]


Streets of Rage: Silent Storm by mtrain
[December 07, 2012, 03:45:05 pm]


Site will be down for maintenance on 12/8/2012 thru 12/10/2012 by Damon Caskey
[December 07, 2012, 07:42:42 am]


Cancelled SOR 3d Remake by riccochet
[December 07, 2012, 03:58:33 am]


Dungeon Fighter: B.O.R. by msmalik681
[December 07, 2012, 03:24:27 am]


[TUTORIAL] How to create 4 Games of OpenBOR in 1 CD (650 MB) by magggas
[December 06, 2012, 09:46:25 pm]


custknife by Bloodbane
[December 06, 2012, 09:34:09 pm]


blockfx help by B.Kardi
[December 06, 2012, 04:09:14 pm]


street of age 4 hd by corradlo
[December 06, 2012, 01:41:36 pm]


ClaFan - Classic Fantasy ver 1.17 by soniczxblade
[December 06, 2012, 05:01:20 am]


Bug Archive by Bloodbane
[December 06, 2012, 02:00:44 am]


"Bio-Doom" and "Gears of Doom" by BulletBob
[December 05, 2012, 10:07:21 pm]


Contra Locked 'N' Loaded v2 by Bloodbane
[December 05, 2012, 09:39:43 pm]


Downloadable OpenBoR Manual by BeasTie
[December 05, 2012, 08:31:24 pm]


Having trouble testing changes by B.Kardi
[December 05, 2012, 03:05:53 pm]


DragonBall Absalon by msmalik681
[December 05, 2012, 02:52:13 pm]


[Hi-Res] Swamp by Vibrant
[December 05, 2012, 10:47:14 am]


  • Dot Guests: 139
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.



Author Topic: Script Request: Using a2-a4 for single-button and long inputs.  (Read 4250 times)

0 Members and 1 Guest are viewing this topic.

Offline Orochi_X

  • Hero Member
  • *****
  • Posts: 3301
  • Now! Count up your crimes.
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #15 on: April 02, 2010, 08:07:29 pm »
O.K. Here it is. I've left it intact (I.E. set up for 4 attack buttons , including jump and forwardjump checking) but it's set out in blocks so that you can see which sections you need to delete if you don't want them.

Also , I wrote this a long time ago so my naming conventions were different to DC's. I think that , from now on , I'll make an effort to use the same conventions. It might help towards the goal of making script easier to grasp if we all stick to the same thing. It doesn't strictly matter in this case , though , as it is a stand alone script.

This is a keyall script so just place it in the scripts folder and it will work for all players. I use this keyall script to save a little memory as all my heroes use this script and loading it multiple times is just silly. Any character specific commands go into their own scripts.

First up , initialise some variables.

Quote
       int player = getlocalvar("player");
   void self = getplayerproperty(player, "ent");
   int anim = getentityproperty(self, "animationid");
   float a = getentityproperty(self, "a");
   float base = getentityproperty(self, "base");

int player = getlocalvar("player");   We need to know which player pressed a button. This will return a number between 0 and 3. Player 1 = 0 , player 2 = 1 and so on. This will be useful later on.

void self = getplayerproperty(player, "ent");  This will tell us which character the player is controlling. We need to know this so that we can apply the changes to the correct entity. Now , whenever we want to do something with that entity , we simply use "self" instead of having to use "getplayerproperty(player, "ent")" every time.

int anim = getentityproperty(self, "animationid");  This tells us which animation the entity is currently playing.

The next two aren't strictly required but I'll explain them , and my reasons for including them and then you can decide.

float a = getentityproperty(self, "a"); This is the entity's current altitute (also reffered to as Y in other commands).
 
float base = getentityproperty(self, "base"); This is the base altitude. Should pretty much always be 0 (ground level)

Using those two , I am able to check that the entity is still on the ground. In theory , if you are in an idle , walk or run animation then you pretty much should be. However , there are a few odd circumstances when you are not. The lack of a (re)spawn animation , just before/after a jump are the biggest examples.

Now , we set up the variable to check the timing of the inputs.

Code: [Select]
if(playerkeys(player, 1, "movedown") || playerkeys(player, 1, "moveleft") || playerkeys(player, 1, "moveup") || playerkeys(player, 1, "moveright"))
{
setindexedvar(player, openborvariant("elapsed_time"));
}

Not much to explain here. If the player that activated the script is pressing a direction , we take the elapsed time and save it for future use.

|| means "or"
setindexedvar(player, openborvariant("elapsed_time"));  Indexedvars are a set of variables that are predefined in script.txt They are easy and efficient to access.
The first value is the variable you want to store the information to. As they are indexed , you would commonly use a number (think of it as an ID number) However , we need to use a variable for each player. Using a single var shared across four players would return false results (p1 presses a direction then p2 presses a button and the script thinks that enough time as passed for p2 to perform the move). We also don't want to set all 4 variables at the same time , either.

So , we use "player". Remember that we initialised it earlier? It returns a number that corresponds to the player that pressed the button. By using "player" instead of a number , the script reads player as the number we retrieved earlier and only saves the variable related to that player.

The second value is what we want to store. In this case , it's the elapsed time. This is an internal counter that is constantly increasing.

Next section!

Code: [Select]
if((anim == openborconstant("ANI_IDLE") || anim == openborconstant("ANI_WALK") || anim == openborconstant("ANI_RUN")) && a == base  && (openborvariant("elapsed_time") - getindexedvar(player) >= 25 || !getindexedvar(player)))
{

Here , I check that we are in a valid animation , that the hero is firmly on the ground and that enough time has passed between the direction button being pressed and the attack button being pressed.

&& means "and"
a == base means "a is the same as base". When you are jumping , a will be a higher value than base. We don't want that.

(openborvariant("elapsed_time") - getindexedvar(player) >= 25 This part subtracts the previously stored time from the current elapsed time. If the remaining amount is greater than ( > ) or equal to ( = ) 25 , then enough time has passed to perform the attack. Anything less and we assume the player was inputting a freespecial. Feel free to mess around with the 25. It was tight enough for my KOF style gameplay but you might want a different feel.

|| !getindexedvar(player) This can be read as " or there is no value stored to the variable" (It's a pretty loose "translation"). || I've explained. ! is a not operator The reason we need to check for this is because , until you press a direction , there will not be a value stored to the indexedvar (the indexedvar would not exist). This would normally prevent the scripted attack from working unless you walked around before trying to perform the scripted attack. However , by using the not operator , finding that the indexedvar does not exist allows the script to continue.

Next , checking the key press and applying the new animation and ai behaviour.

Quote
if(playerkeys(player, 1, "attack2"))
      {
         changeentityproperty(self, "aiflag", "attacking", 1);
         changeentityproperty(self, "aiflag", "idling", 0);
         changeentityproperty(self, "takeaction", "common_attack_proc");
         changeentityproperty(self, "animation", openborconstant("ANI_ATTACK2"), 1);
         changeentityproperty(self, "velocity", 0, 0, 0);
      }

if(playerkeys(player, 1, "attack2"))  If we press a2.
changeentityproperty(self, "aiflag", "attacking", 1);  Turn ON the attacking ai behaviour.
changeentityproperty(self, "aiflag", "idling", 0);  Turn OFF the idling behaviour. Idling also refers to walking and running.
changeentityproperty(self, "takeaction", "common_attack_proc"); Initiate the attacking "procedures".
changeentityproperty(self, "animation", openborconstant("ANI_ATTACK2"), 1);  Switch to the desired animation.
changeentityproperty(self, "velocity", 0, 0, 0);  Stop all movement.

Jumping. This should be easy to follow.

Code: [Select]
if(anim == openborconstant("ANI_JUMP"))
{
if(playerkeys(player, 1, "attack2"))
{
changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW9"), 1);
}

As you can see , there is no need to modify the ai behaviour.

Let me know what you think of the explainations. I started talking about operators and such but I think it may have been too much info. I think we should probably just update utunnels' F.A.Q. with that info and assume that it will get read by those who need it.


Anyway , here is one of my old vids to show the script in action.

http://www.youtube.com/watch?v=bptP8I6Ew1A#


Haha! I just remembered how funny/terrible that vid was. Only the first few seconds are relevant to this script.
« Last Edit: April 02, 2010, 08:35:53 pm by Orochi_X »


* Orochi_X says : " Sore ga doushita? " :looney:

Offline MasterExploder

  • Sr. Member
  • ****
  • Posts: 326
  • You spin me right round, baby, right round
    • THE TWITTER!
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #16 on: April 03, 2010, 12:14:14 am »
Thanks for sharing the script OX! This will certainly come in handy in my own projects!

Offline Bloodbane

  • Hero Member
  • *****
  • Posts: 7113
  • Dark Dragon
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #17 on: April 03, 2010, 10:01:16 am »
 Ah, thanks for the script Orochi_X! Instead of scripting freespecials with long input, the script handles the single input.
OpenBoR Manual

Basic OpenBoR Tutorials

OpenBoR Tricks & Tutorials

"The more often enemies attack, the more open they are to counter attacks"

Offline vies

  • Full Member
  • ***
  • Posts: 177
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #18 on: April 03, 2010, 12:37:56 pm »
Very nice. This'll definitely come in handy. Not to mention, it's one more example to study when I decide to start learning how to script.

Offline the7k

  • Hero Member
  • *****
  • Posts: 749
  • PSN: the_7k
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #19 on: April 03, 2010, 05:49:40 pm »
Many thanks, OX! You are a gentleman and a scholar.

Offline spawn

  • Hero Member
  • *****
  • Posts: 641
    • john morrison
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #20 on: April 03, 2010, 05:56:48 pm »
Many thanks, OX! You are a gentleman and a scholar.
BLEH :puking: suck up :P.Anyways what else can this type of script allow,I've been following this topic and it's very interesting.

Offline maxman

  • Hero Member
  • *****
  • Posts: 2763
  • I'm a slowpoke in speed.
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #21 on: April 04, 2010, 02:36:47 am »
I thought I have this already. Anyway, thanks for the share, OX. :)
Dragon Duo (W.I.P./Outdated demo (2010 version)) (in progress)
Captain Commando (in progress)
Unelmia: Dreamers' Fate (collaborating with contress/taskmaster) (in progress)

Best OpenBOR mods:Spoiler
1. World Heroes Supreme Justice
2. Golden Axe Myth
3. Art of Fighting: Beats of Rage Remix III
4. A Tale of Vengeance
5. Valdivia Ransom City (demo)
6. Sega Brawlers Megamix
7. Super Fightin Spirit
8. Angel-0

Offline baritonomarchetto77

  • Hero Member
  • *****
  • Posts: 1144
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #22 on: April 06, 2010, 05:58:54 am »
This kind of topics should be collected and/or pinned for future use being a sort of "scripting basic tutorial" (it remember me a very old post from Bloody which was explaining some UT script from his Golden Axe Remake).

Offline MatMan

  • Hero Member
  • *****
  • Posts: 1320
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #23 on: June 20, 2011, 07:39:39 am »
There is a script section in the downloads now. So placing the scripts there might be a good idea.

Scripts section....
http://lavalit.com:8080/index.php?action=downloads;cat=30

Edit.
Just noticed when that last message was posted. (long ago)

Offline magggas

  • Hero Member
  • *****
  • Posts: 735
  • .....
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #24 on: August 07, 2011, 03:18:43 pm »

setindexedvar(player, openborvariant("elapsed_time"));  Indexedvars are a set of variables that are predefined in script.txt They are easy and efficient to access.
The first value is the variable you want to store the information to. As they are indexed , you would commonly use a number (think of it as an ID number) However , we need to use a variable for each player. Using a single var shared across four players would return false results (p1 presses a direction then p2 presses a button and the script thinks that enough time as passed for p2 to perform the move). We also don't want to set all 4 variables at the same time , either.

So , we use "player". Remember that we initialised it earlier? It returns a number that corresponds to the player that pressed the button. By using "player" instead of a number , the script reads player as the number we retrieved earlier and only saves the variable related to that player.

The second value is what we want to store. In this case , it's the elapsed time. This is an internal counter that is constantly increasing.



I tried today this keyall script because i wanted to make later
some freespecials doable with my kick button.
The problem is this parameter of the script(setindexedvar(player, openborvariant("elapsed_time"));) make it not working so nice even if i try different values for it.

I have 2 problems actually:
1.with big value the kick move is hard to make or with small value the freespecial is hard to make.

2.When i am make the kick move then the follow up moves i have are not working allways :(

Is there maybe an solusion about?

Offline Orochi_X

  • Hero Member
  • *****
  • Posts: 3301
  • Now! Count up your crimes.
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #25 on: August 10, 2011, 03:30:31 pm »
The line you highlighted doesn't effect anything. It just saves a number.

Code: [Select]
if((anim == openborconstant("ANI_IDLE") || anim == openborconstant("ANI_WALK") || anim == openborconstant("ANI_RUN")) && a == base  && (openborvariant("elapsed_time") - getindexedvar(player) >= [b]25[/b] || !getindexedvar(player)))
The above is the code you should modify. Change the 25 to some other value.


* Orochi_X says : " Sore ga doushita? " :looney:

Offline magggas

  • Hero Member
  • *****
  • Posts: 735
  • .....
Re: Script Request: Using a2-a4 for single-button and long inputs.
« Reply #26 on: August 10, 2011, 04:39:21 pm »
I was talking too about this value getindexedvar(player) >= 25.
I have Just not explained right sorry  :-[

Here is a bit better explained my issues with this script:
Quote
I undarstand the point why is needed the elapsed time in this script but exactly this parameter makes it have no sense.
With big value the kick move is hard to make or with small value the long input freespecial is hard to make.

And the other thing is  when i press
the punch(A) button for direkt knockdown after my kick(A2)
the engine get confused and it not works allways.

I think the engine get confused because i am using your script ani0020.h for this direkt knockdown with punch.

That is why i was think if is maybe a way to make an Long input freespecial via script.

 



 0%




SimplePortal 2.3.3 © 2008-2010, SimplePortal