Parametric weapon

Locked
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Parametric weapon

Post 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 !
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
UglyFoot
Posts: 139
Joined: Fri Jul 22, 2011 12:35 pm

Re: Parametric weapon

Post 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?
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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.
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
UglyFoot
Posts: 139
Joined: Fri Jul 22, 2011 12:35 pm

Re: Parametric weapon

Post by UglyFoot »

Good :up: :)
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
UglyFoot
Posts: 139
Joined: Fri Jul 22, 2011 12:35 pm

Re: Parametric weapon

Post by UglyFoot »

Then I guess this article might be helpful:
http://www.quakewiki.net/archives/code3 ... cle9.shtml
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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.
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
UglyFoot
Posts: 139
Joined: Fri Jul 22, 2011 12:35 pm

Re: Parametric weapon

Post 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.
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
UglyFoot
Posts: 139
Joined: Fri Jul 22, 2011 12:35 pm

Re: Parametric weapon

Post by UglyFoot »

Good, I'm surprised that it worked but it's good to know :)
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 ?
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Parametric weapon

Post 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?
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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).
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Parametric weapon

Post by CZghost »

q3w_post-topic.jpg
Here
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post by D-Meat »

:tard: sorry :tard: :puke: :dork:

back to topic now :)
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
D-Meat
Posts: 159
Joined: Tue May 17, 2011 8:52 am

Re: Parametric weapon

Post 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 !
[url=http://www.dmitri-engman.fr/]My blog[/url] - [url=http://dmeat.free.fr/book/]My portfolio[/url]
---------------------
[url=http://lvlworld.com/#c=m1&i=1908&d=12%20Dec%202012&m=All&p=review]MJDM2[/url] - [url=http://lvlworld.com/#c=m1&i=2108&d=12%20Dec%202012&m=All&p=review]DmeatSP01[/url] - [url=http://lvlworld.com/#c=m1&i=2132&d=12%20Dec%202012&m=All&p=review]DmeatSP02[/url]
Locked