Pages: [1]
  Print  
Author Topic: I developped a feature "best weapon", i need help.  (Read 16207 times)
MCMic
Nub


Cakes 0
Posts: 17



« on: August 12, 2008, 01:14:33 PM »

Hi, I developped my own feature, who allow two things:
-first, the auto-switch siwtch only if we take a weapon better than the one we have in hand.
-The second thing is the possibility to assign to a key the action "choose the best weapon I have" (I choose the right click)

The order of weapons is the default order (so the best weapon is the plasma gun, but if we talk about damage/second, it is really the best weapon)

Now I need help to add variables which allow the player to change the order of the weapons in a menu of the setup.

If you want to test, there is a version of OA 0.7.7 with my feature in attachment.
[EDIT] it doesn't works, it said
Quote
test.tar.gz.
You cannot upload that type of file. The only allowed extensions are txt,doc,pdf,jpg,gif,mpg,png,md3,blend,c,h,shader,script,skin,tga,wav,ogg,mp3,map,zip,tar.gz,bz2,tar.bz2,7z.
[EDIT2] I add it in 7zip in my second post of this topic. enjoy. (please leave comments if you try it)

My modification of the code :
I add a function CG_BestWeapon_f() in the file cgame/cg_weapon.c, just after the function CG_NextWeapon_f
Code:
/*
===============
CG_BestWeapon_f
===============
*/
void CG_BestWeapon_f( void ) {
int i;
int original;

if ( !cg.snap ) {
return;
}
if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
return;
}

cg.weaponSelectTime = cg.time;
original = cg.weaponSelect;

for ( cg.weaponSelect = 0 ; cg.weaponSelect < MAX_WEAPONS ; cg.weaponSelect++ ) {
if ( CG_WeaponSelectable( cg.weaponSelect ) && cg.weaponSelect > original) {
original = cg.weaponSelect;
}
}
if ( i == MAX_WEAPONS ) {
cg.weaponSelect = original;
}
}

I add a line in cg_local.h :
Code:
Line 1437 : void CG_BestWeapon_f( void );

I add a line in cg_consolecmds.c :
Code:
Line 469 :  { "weapbest", CG_BestWeapon_f },

I add 10 lines in ui_controls2.c :
Code:
Line 109 : #define ID_WEAPBEST 29
Line 189 : menuaction_s bestweapon;
Line 261 : {"weapbest", "best weapon", ID_WEAPBEST, ANIM_IDLE, '0', -1, -1, -1},
Line 303 : (menucommon_s *)&s_controls.bestweapon,
Line 1420-1424 : s_controls.bestweapon.generic.type     = MTYPE_ACTION;
s_controls.bestweapon.generic.flags     = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS|QMF_GRAYED|QMF_HIDDEN;
s_controls.bestweapon.generic.callback  = Controls_ActionEvent;
s_controls.bestweapon.generic.ownerdraw = Controls_DrawKeyBinding;
s_controls.bestweapon.generic.id        = ID_WEAPBEST;
Line 1612 : Menu_AddItem( &s_controls.menu, &s_controls.bestweapon );
For the Define, i add 1 to all the define for can insert mine.
So I Have that :
Code:
#define ID_WEAPNEXT 28
#define ID_WEAPBEST 29
#define ID_GESTURE 30
#define ID_CHAT 31
#define ID_CHAT2 32
#define ID_CHAT3 33
#define ID_CHAT4 34

// all others
#define ID_FREELOOK 35
#define ID_INVERTMOUSE 36
#define ID_ALWAYSRUN 37
#define ID_AUTOSWITCH 38
#define ID_MOUSESPEED 39
#define ID_JOYENABLE 40
#define ID_JOYTHRESHOLD 41
#define ID_SMOOTHMOUSE 42
...

I add a line in ui_shared.c :
Code:
Line 3165 : {"weapbest", '°', -1, -1, -1},

I think it's all for the second thing.

for the first, i just changed the function CG_ItemPickup in cg_event :
Code:
/*
================
CG_ItemPickup

A new item was picked up this frame
================
*/
static void CG_ItemPickup( int itemNum ) {
cg.itemPickup = itemNum;
cg.itemPickupTime = cg.time;
cg.itemPickupBlendTime = cg.time;
// see if it should be the grabbed weapon
if ( bg_itemlist[itemNum].giType == IT_WEAPON ) {
// select it immediately
if ( cg_autoswitch.integer && bg_itemlist[itemNum].giTag != WP_MACHINEGUN && bg_itemlist[itemNum].giTag > cg.weaponSelect ) {
cg.weaponSelectTime = cg.time;
cg.weaponSelect = bg_itemlist[itemNum].giTag;
}
}

}

PS : i'm french, please scuse my bad english :-/
« Last Edit: August 12, 2008, 02:03:46 PM by MCMic » Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #1 on: August 12, 2008, 01:55:00 PM »

Now I need help to add variables which allow the player to change the order of the weapons in a menu of the setup.

I would add a CVAR that can look like this:

cg_bestweapons "ml mg gn cg sg gl lg rl rg bfg" and then use Q_strstr to find the index of the active weapon and the weapon I just picked up (that I didn't already have or was out of ammo for)

I'm not that strong in designing menues so I cannot help there. It might also change significantly in missionpack
Logged

There are nothing offending in my posts.
MCMic
Nub


Cakes 0
Posts: 17



« Reply #2 on: August 12, 2008, 02:00:29 PM »

I wish add a variable by weapon, so the player can choose too give 0 to all weapon expect of RocketLauncher and RailGun which have 1 and 2. In this way his autoswitch/bestweaponkey will give him a RocketLauncher or nothing.
With this system the feature is more powerfull.

But i don't now how add a variable, take it a default value, use it, change it, etc... (I tried but i don't understand Qvar's system)

[EDIT] I add in attachment the 0.7.7 version with my modification.
« Last Edit: August 12, 2008, 02:02:57 PM by MCMic » Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #3 on: August 12, 2008, 02:06:25 PM »

http://code3arena.planetquake.gamespy.com/articles/article9.shtml#placing_cvars

You can do what you say too: "rl rg" (rocket launcher < railgun)

I prefer having as few CVARs as possible as they can create quite a mess with mods, that is why I would place it in one cvar.
Logged

There are nothing offending in my posts.
MCMic
Nub


Cakes 0
Posts: 17



« Reply #4 on: August 12, 2008, 02:08:24 PM »

http://code3arena.planetquake.gamespy.com/articles/article9.shtml#placing_cvars

You can do what you say too: "rl rg" (rocket launcher < railgun)

I prefer having as few CVARs as possible as they can create quite a mess with mods, that is why I would place it in one cvar.
ok, thank you, I will see that.
Logged
ic3w1nd
Nub


Cakes 1
Posts: 15



« Reply #5 on: August 13, 2008, 03:12:31 AM »

-first, the auto-switch siwtch only if we take a weapon better than the one we have in hand.

The problem is “better” ... Well, im quite good with the rocket launcher. If we have a fight, 1:1 kicking each others ass with rockets and wooops, there is a railgun, because we wight all over the map and try to get each other, i accidently run over the item ... well, thats it, i’m dead because of the script thinks, the railgun is better Smiley

There needs to be a function “only switch when last shot was XX seconds ago” Smiley
Logged

*pow*
MCMic
Nub


Cakes 0
Posts: 17



« Reply #6 on: August 13, 2008, 04:46:36 AM »

-first, the auto-switch siwtch only if we take a weapon better than the one we have in hand.

The problem is “better” ... Well, im quite good with the rocket launcher. If we have a fight, 1:1 kicking each others ass with rockets and wooops, there is a railgun, because we wight all over the map and try to get each other, i accidently run over the item ... well, thats it, i’m dead because of the script thinks, the railgun is better Smiley

There needs to be a function “only switch when last shot was XX seconds ago” Smiley
Why not.

but first the order of weapons will can be changed in the setup, and secondly you can desable the autoswitch Wink (i don't use the auto-switch, but i use a lot the best weapon action)

So I'll make a personnalisable order of weapons, and if you want add a function "only switch when last shot was XX seconds ago", do it yourself Tongue
But what i'll maybe do is that the autoswitch only the weapon we take is better than the one we have in hand AND if we have in hand our best weapon. So if you have a rocket launcher and prefer use the shotgun, walk on a rocket launcher won't change your weapon.

But for now i just try to make a personnalisable order ^^
Logged
MCMic
Nub


Cakes 0
Posts: 17



« Reply #7 on: August 13, 2008, 05:22:59 AM »

http://code3arena.planetquake.gamespy.com/articles/article9.shtml#placing_cvars

You can do what you say too: "rl rg" (rocket launcher < railgun)

I prefer having as few CVARs as possible as they can create quite a mess with mods, that is why I would place it in one cvar.
I tried to use only one Cvar and  stock "00010203040506070809111213", for can compare the number assigned to each weapon, but i can't use "strcmp" because i can't include "string.h" :
Code:
CGAME_Q3LCC code/cgame/cg_weapons.c
cpp: code/cgame/cg_weapons.c:25 Could not find include file "string.h"

So can I make a table of cvars? (one by weapon)
Or how can i do?
« Last Edit: August 13, 2008, 05:25:19 AM by MCMic » Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #8 on: August 13, 2008, 07:49:00 AM »

Use Q_stricmp instead.

My suggestion is something like this function that returns a positive number or NULL if the weapon is not in the list.
WARNING: Unverified code!
Code:
int weaponValue(int weaponIndex) {
    char* s;
    char weaponlist[MAX_CVAR_VALUE_STRING];
    trap_Cvar_VariableStringBuffer( "cg_weaponlist", weaponlist, sizeof( weaponlist ) );
    switch(weaponIndex) {
        case WP_MACHINEGUN: //I don't remember how it is defined
             s = "mg";
             break;
        /* ... Insert the rest of the weapons ... */
        case WP_RAILGUN:
             s = "rg";
             break;
        default:
             return 0; //We don't know that weapon
    };
    return Q_stristr(weaponlist,s); //Find a pointer to the place in the list the weapon appears. Higher if the weapon is written later and NULL if it does not exist.
}
Logged

There are nothing offending in my posts.
MCMic
Nub


Cakes 0
Posts: 17



« Reply #9 on: August 13, 2008, 08:12:22 AM »

I'll first try to use a string with the values.

I have this weard error when i compile :
Code:
Q3ASM build/release-linux-i386/baseoa/vm/ui.qvm
error: symbol UI_WeaponsMenu undefined

But "UI_WeaponsMenu" is only used in files that i didn't modified.
Logged
MCMic
Nub


Cakes 0
Posts: 17



« Reply #10 on: August 14, 2008, 10:15:09 AM »

I can't compile my game like you explained me in this topic http://openarena.ws/board/index.php?topic=1970.0
the folder "vm" is empty after i compile.

Code:
LD build/release-linux-i386/openarena.i386
make[2]: quittant le répertoire « /home/come/openarena/source/080/ioquake3svn1438 »
make[1]: quittant le répertoire « /home/come/openarena/source/080/ioquake3svn1438 »

The make sims work correctly.
I don't understand what append.

It works in the 077 repertory, but not in 080. I don't understand why.
« Last Edit: August 14, 2008, 10:25:54 AM by MCMic » Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #11 on: August 14, 2008, 10:41:04 AM »

It is because I have disabled compilation of VMs.

Find "Makefile.local" open it and enable compilation of VM files again. It is disabled because most people want to compile the source to get a working binary, not to create mods.

I will in the near future provide two separate tar-files. One with engine for people who need to create binaries and one with VM for people who want to mod.
Logged

There are nothing offending in my posts.
MCMic
Nub


Cakes 0
Posts: 17



« Reply #12 on: August 14, 2008, 11:08:49 AM »

Thanks, it works, should I use a CVAR_ARCHIVE or a CVAR_USERINFO ?
Logged
sago007
Posts a lot
*

Cakes 62
Posts: 1664


Open Arena Developer


WWW
« Reply #13 on: August 14, 2008, 11:30:26 AM »

Thanks, it works, should I use a CVAR_ARCHIVE or a CVAR_USERINFO ?

It should be CVAR_ARCHIVE because you want to save it.

It should not be a CVAR_USERINFO because it should all be done on the client side if possible.
Logged

There are nothing offending in my posts.
MCMic
Nub


Cakes 0
Posts: 17



« Reply #14 on: August 14, 2008, 03:46:50 PM »

Okay, it works, I can change the order in my file q3config.cfg

Now I need to add a menu for configure that easy ^^
Logged
MCMic
Nub


Cakes 0
Posts: 17



« Reply #15 on: September 09, 2008, 07:15:04 AM »

Hey, Where do you think I should add my menu? in "Player" ? in "Controls"? in a new category? (in controls it's the easiest, but it's not really appropriate, right?)
This menu will look like the controls menu for weapons, one line by weapon with a number to associate.
Logged
Pages: [1]
  Print  
 
Jump to: