Page 1 of 1

Parametric weapon

Posted: Tue Sep 16, 2014 12:59 pm
by D-Meat
Hello !

I actually also posted this message at the ioquake3 forum, I'm adding it here at the same time :)

I'm currently working on a dirty game prototype for a contest, and I might need a bit of help !

in my game, the player handles only one weapon, but it's characteristics will change as he picks up and plugs in some items.
Here are the 5 parameters :
- precision / spread
- number of bullets ( from one to 'x', so you can create some kind of shotgun)
- power + speed
- reload time
- heat / cool-off speed

these parameters are basically ints, maybe floats, I don't know yet.

Concretely, since I'm short on time, I was going to modify the machinegun to make it the "host" of this weapon ...
... And that's it, I don't know where to go to continue !

Obviously these parameters have to be shared by client and server. In which struct should I host it ? Will putting it in gentity_t->entityState_t would be good ?

I'll later have to manage an inventory for the player, I think that kind of data could be in the same place ...

I'm sure I'll have other questions coming ><

Thanks for reading, and sorry for my ignorance :)

cheers !

Re: Parametric weapon

Posted: Thu Oct 02, 2014 6:16 pm
by UglyFoot
Hello, I don't know exactly how to do it but I'll try to help.

Perhaps there is no need to add variables as they will be items and if I remember correctly they are stored in inventory (playerState_t).

As for changing the MG, check out FireWeapon, inside it there is a call to a function for each weapon, I would copy and edit Butllet_Fire.

By the way, what contest is it?

Re: Parametric weapon

Posted: Thu Oct 09, 2014 8:21 pm
by D-Meat
Hello ! Sorry for the inertia !
I was actually quite panicked when I posted this message, as I just finished that big part of my game about the level generation I couldn't plan calmly what I was going to do.

So 3 weeks later, I made some progress on that subject. The parametric weapon is basically implemented. I've let down the heat management for the moment. The inventory system is working but the UI of it is not ready.
UglyFoot wrote:Perhaps there is no need to add variables as they will be items and if I remember correctly they are stored in inventory (playerState_t).
Using existing variables in playerstate means recycling the stats[], persistant[], powerups[] and ammo[] arrays, which might have been fine but I prefer building my own systems whithout damaging or deleting the existing ones ... So I added stuff to the playerstate :
- The weapon's parameters (float precision, float power, int bullets, float reloadtime, and float heat)
- The weapon's installed item slots (array of 6 ints)
- The player's inventory (array of 16 ints)

I had to modify qcommon/msg.c to get this data across the network, and it seams to work ! I struggled a lot during the past 48 hours and the final implementation isn't very good looking but it works :)
UglyFoot wrote:As for changing the MG, check out FireWeapon, inside it there is a call to a function for each weapon, I would copy and edit Butllet_Fire.
Yup, so what I did was to add a new weapon and make it the default spawning weapon for the player. Then I plugged a custom 'fire' function that uses the machinegun's 'bullet_fire' function. When there are multiple bullets to be fired, I just use this function multiple times. I haven't stress-tested that yet, but since the shotgun is coded quite differently for network reasons, I could have problems in the future.
UglyFoot wrote:By the way, what contest is it?
It's a french contest taking place for the "TGS" (which means Toulouse game Show, not Tokyo game show). There is Frédéric Raynal among the Judges !


I made some nice progress today, but I'm already stuck on a new thing : I added a function that drops items from the inventory, and it seems to work fine server side, but client side the dropped item seems not synchronized, or actually it is sometime synchronized the first time, but the next drops are invisible and there is no sound / feedback icon when I pick them up (but they do get picked up server-side, I can tell from my G_Printfs inside my pickup function).

Have you or someone used a lot the "drop_item" functions ? Right now I'm clueless :)

Re: Parametric weapon

Posted: Fri Oct 10, 2014 9:57 am
by D-Meat
I made some progress by freeing unused entities, but things are still somehow random. I can drop an item, but if I pick it up and drop it again it's absent from cgame, it seams.

Re: Parametric weapon

Posted: Fri Oct 10, 2014 12:17 pm
by D-Meat
Solved.

[youtube]-_oFyfy77QU[/youtube]

What happened ?

Well, Since my items can be collected only once and don't respawn, I use the G_FreeEntity function. But used it too early, right before the EV_ITEM_PICKUP is sent in the Touch_Item function in g_items.c. Now I free the entity right after and everything works fine. Yay ! Actually, I don't know how it could work once in a while before.

Now, I have to plug in the inventory to my inventory screen. I'm crossing fingers to hope I won't run into strange problems :)

Re: Parametric weapon

Posted: Fri Oct 10, 2014 3:04 pm
by UglyFoot
Good :up: :)

Re: Parametric weapon

Posted: Fri Oct 10, 2014 3:19 pm
by D-Meat
Thanks for the support :)

I'm looking for somethin, but I'm not sure if it exists :
Is it possible to access cg from ui ? I've seen some Cvar read / write functions (trap_Cvar_VariableValue and trap_Cvar_SetValue). I could maybe write my own thing, but it sounds risky :)

Re: Parametric weapon

Posted: Fri Oct 10, 2014 3:30 pm
by UglyFoot
Then I guess this article might be helpful:
http://www.quakewiki.net/archives/code3 ... cle9.shtml

Re: Parametric weapon

Posted: Sat Oct 11, 2014 8:19 am
by D-Meat
Thanks for the link, it's a good read !

I've skipped some details, but I haven't seen anything that I want, for the moment.

What I need is some information stored in cg.predictedPlayerState, not in a Cvar.

I'll continue scratching :)

Re: Parametric weapon

Posted: Sun Oct 12, 2014 3:42 pm
by D-Meat
Okay so Things work as I want using Cvars and the various trap functions. It's a little bit heavy code wise, but nevermind.

I have a new question !

In a menu, is it possible to handle right mouse button to do something ?
Left mouse buttons triggers 'QM_ACTIVATED' event by default and executes the button's callback function.

I could handle some special key event using the *.menu.key function, but it's not related to the currently active item of the menu, it seems.

Re: Parametric weapon

Posted: Wed Oct 15, 2014 9:28 pm
by UglyFoot
My conclusion is the same as you. There are two events besides QM_ACTIVATED but they are triggered when the mouse moves over or away. I would try to do it without the right button.

Re: Parametric weapon

Posted: Fri Oct 17, 2014 12:21 pm
by D-Meat
I actually managed to handle the right mouse click in a menu !

I added a "callback2" function pointer in the menucommon_s struck, and somehow plugged it in and it works !

I managed to accomplish my objectives and I now have somewhat of a game ! I'll make a video soon to share :)

Re: Parametric weapon

Posted: Wed Oct 22, 2014 9:39 pm
by UglyFoot
Good, I'm surprised that it worked but it's good to know :)

Re: Parametric weapon

Posted: Wed Oct 29, 2014 10:18 am
by D-Meat
(I can't find the 'new topic' button ! is this normal ?)

Alright I'm on my final rush on this project, I hope I'll make it :)

I have a question :
For the moment, I've been using playerState_t to store my inventory and other stuff.

To balance the game, I've decided to split it into rounds. A game takes place in 3 rounds. I want the player to start the next round with all the stats, health and inventory he had previously.

What I tried to do is to set the inventory to empty only when a player connects and when he dies.
The inventory is cleared and reset when the player dies (this works). But when I tried to init the values inside the 'ClientConnect' function (in g_client.c) (which has the handy 'firstTime' variable), things get done (each inventory slot is set to -1), but when I check after I spawn, it has actually changed to 0.

This works when I place the initialization in the 'clientBegin' function, But this means the inventory gets reset when I move on to the next round of the game.

So, in order to keep all the info I want, should I move everything into ClientPersistant_t or CLientSession_t ?

Re: Parametric weapon

Posted: Wed Oct 29, 2014 11:43 am
by CZghost
D-Meat wrote:(I can't find the 'new topic' button ! is this normal ?)
Post topic would do the job. It is right under user controls links and under list of topics or under list of posts next to post reply button. Do you see that?

Re: Parametric weapon

Posted: Wed Oct 29, 2014 12:20 pm
by D-Meat
CZghost wrote:
D-Meat wrote:(I can't find the 'new topic' button ! is this normal ?)
Post topic would do the job. It is right under user controls links and under list of topics or under list of posts next to post reply button. Do you see that?
Ah, got it when I'm reading a topic. But there's none when I'm looking at the topic list ! (in any category).

Re: Parametric weapon

Posted: Wed Oct 29, 2014 12:43 pm
by CZghost
q3w_post-topic.jpg
Here

Re: Parametric weapon

Posted: Wed Oct 29, 2014 1:17 pm
by D-Meat
:tard: sorry :tard: :puke: :dork:

back to topic now :)

Re: Parametric weapon

Posted: Wed Oct 29, 2014 3:15 pm
by D-Meat
D-Meat wrote:So, in order to keep all the info I want, should I move everything into ClientPersistant_t or CLientSession_t ?
Moved what I needed to ClientSession_t (ent->client->sess). Everything works fine. Yay !