Jump to content

Home

How can I make BUTTON_ATTACK as if pressed in cgame?


Vruki Salet

Recommended Posts

I have made a command in g_cmds.c that needs the game to make like BUTTON_ATTACK has been pressed without the player really doing so.

 

in bg_pmove.c, within PM_Weapon, I have the following:

 


#ifdef QAGAME
if (g_entities[pm->ps->clientNum].client->vsnSaberCombat.swingingSaber == qtrue)
	{
	pm->cmd.buttons |= BUTTON_ATTACK;
	}
#endif


 

As you can see it's only in QAGAME so it works fine if my client is the same as my server like when I run it as a non-dedicated listening server, but doesn't work for any clients when I run the code on a dedicated server.

 

How can I make the cgame also virtually press BUTTON_ATTACK at the same time?

 

PS.:

 

I tried out ways that avoided using #ifdef QAGAME but it didn't seem to help. "cmd.buttons |= BUTTON_ATTACK" still didn't work from cgame files though I tried it in various places. As it is now the QAGAME version is back since it's more convenient in other ways.

Link to comment
Share on other sites

It turns out I made a mistake. I am using a modified copy of PM_SaberAttackForMovement and when I got rid of the QAGAME I forgot that the whole function is wrapped in #ifdef QAGAME so I didn't get rid of those. Now I got rid of them and it helps. Thanks for pointing me in the right direction Tinny.

Link to comment
Share on other sites

Now there's another problem to address, maybe you can help again. It goes like this: I have a command set up in g_cmd.c that swings the saber in various directions by feeding a version of PM_SaberAttackForMovement virtual movement directions and then causing a simulated attack button press to fire within PM_Weapon in bg_pmove.c. This works great in standalone client games and listen servers, where I can use 7 numpad keys to make the saber swing all over the place, and I can do swing combos (like yellow scissors etc.) just like regular mouse-driven sabering in normal JKA. Transitions all work like they're supposed to. However now when I run the game as a dedicated server and join it, the buttons swing my saber in the right direction but I can't combo anymore, now in all stances the saber has to do a full swing 100% then come back all the way back to "ready" before it will let me swing again with the keys. There are no transitions and no flowing from one swing into another.

 

Any ideas why this might be happening?

Link to comment
Share on other sites

If I get you right then the answer to the first question is that I make a console command and bind it to the key I want and it makes a command define in g_cmds.c go.

 

For the second question, I made it so that the next swing could only be commanded during certain times (experimented with various: e.g. once the original swing was 40% done), so the command wouldn't count outside of those times, but when I hit this current problem I opened it up to make the server allow the command at any time.

 

UPDATE: I have a variable (vsnInt1, essentially userInt1) that when greater than 0 tells the server to "press" BUTTON_ATTACK for me. It used to be "pressed" in bg_pmove.c but I moved it to pm_weaponlightsaber. (Both places behave the same.) I need it to be reset to 0 after a swing so it doesn't just swing forever once it's been made greater than 0 by the command in g_cmds.c, so I put "pm->ps->vsnInt1 = 0;" before returns in my equivalent of PM_SaberAttackForMovement at first, and then changed it to the end of pm_weaponlightsaber. (Both places behave the same.) This is giving a clue to the problem. Without the "pm->ps->vsnInt1 = 0" I swing perpetually once the first command is given. With it, I can make exactly 1 full swing at a time always returning to ready stance before I can swing again.

Link to comment
Share on other sites

I'm not sure about this but I believe that placing it in g_cmd.c won't cause lag. I believe that the taunt and meditate emotes are controlled that way.

 

Basically, the command will be processed and applied to the playerstates on the game side. Technically it won't be applied until the next server frame, but that's the case no matter what you do. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...