Swapping items
Swapping items
Could someone point me in the right direction for swapping items with other items. For example, I would like my mod to have the ability to replace the mega health with a weapon or some other item such as red armor etc.
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
You can swap the classname of the item with the classname of another item in g_spawn.c in the G_CallSpawn() function.
Say you want to replace all the railguns on the map to BFGs
if(Q_stricmp(ent->classname, "weapon_railgun") == 0)
strcpy(ent->classname, "weapon_bfg");
as long as it's before this bit
// check item spawn functions
for ( item=bg_itemlist+1 ; item->classname ; item++ )
it should work.
Say you want to replace all the railguns on the map to BFGs
if(Q_stricmp(ent->classname, "weapon_railgun") == 0)
strcpy(ent->classname, "weapon_bfg");
as long as it's before this bit
// check item spawn functions
for ( item=bg_itemlist+1 ; item->classname ; item++ )
it should work.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
But I think that just spawns different weapons rather than lets you choose in real time which power-up you really want. You could implement this as he wants but it would be nice to have some UI code that lets you toggle between holdables just like you can with weapons.corncobman wrote:You can swap the classname of the item with the classname of another item in g_spawn.c in the G_CallSpawn() function.
Say you want to replace all the railguns on the map to BFGs
if(Q_stricmp(ent->classname, "weapon_railgun") == 0)
strcpy(ent->classname, "weapon_bfg");
as long as it's before this bit
// check item spawn functions
for ( item=bg_itemlist+1 ; item->classname ; item++ )
it should work.
Nexus. What can you actually do? Can you do modeling or something graphical? I would be willing to help you code as long as you did something for me. I am in (what I think is) the opposite situation to you, I want to code but also want to avoid learning blender and GTKRadiant etc.
Re: Swapping items
I am not great with C but I am learning. What corncobman wrote did work but as you said its just for weapons. I'm assuming that doing this similar thing for items isn't as easy?
Also, I would like to make this configurable and not just static within the function. For instance, I would like to have a command similar to this:
modname_swap_weapon_railgun "weapon_bfg" // swaps railgun with bfg on the fly
Also, I would like to make this configurable and not just static within the function. For instance, I would like to have a command similar to this:
modname_swap_weapon_railgun "weapon_bfg" // swaps railgun with bfg on the fly
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Swapping items
Doing entity swapping during game play, when the level and its assets have already been loaded, is somewhat of a hassle.
The client won't load assets of entities that aren't part of the map. So when you mix in a new entity, you'll need to load its assets manually. Grep the cgame source for the CG_Register*() functions.
The client won't load assets of entities that aren't part of the map. So when you mix in a new entity, you'll need to load its assets manually. Grep the cgame source for the CG_Register*() functions.
Re: Swapping items
Well, when I said on the fly I didn't mean during gameplay. I would like to set it during the change to a new map so each map has its own different settings.
In my mod I have the ability to exec a config file for each map within my rotation script. All that I need to do is figure out how to code this in to allow the swapping of items and weapons.
EDIT: I was able to successfully swap the mega with railgun with corncob's suggestion so items CAN also be swapped. Now I just have to figure out a way to make this configurable from my mod's .c file. Any suggestions from you C guru's?
EDIT: I have run into a problem with this scheme. I am needing to replace the spawn point with another item / weapon not the entire class. What is happening for instance, on ctf4 I would like to move the railgun to the mid where mega spawns. Then make the mega spawn on both of the platforms where the railgun once was.
Using this scheme above it puts the railgun where mega was no problem. However, once the second if is executed it replaces all of the railguns with mega's. 
In my mod I have the ability to exec a config file for each map within my rotation script. All that I need to do is figure out how to code this in to allow the swapping of items and weapons.
EDIT: I was able to successfully swap the mega with railgun with corncob's suggestion so items CAN also be swapped. Now I just have to figure out a way to make this configurable from my mod's .c file. Any suggestions from you C guru's?

EDIT: I have run into a problem with this scheme. I am needing to replace the spawn point with another item / weapon not the entire class. What is happening for instance, on ctf4 I would like to move the railgun to the mid where mega spawns. Then make the mega spawn on both of the platforms where the railgun once was.
Code: Select all
if(Q_stricmp(ent->classname, "item_health_mega") == 0) {
strcpy(ent->item, "weapon_railgun");
}
if(Q_stricmp(ent->classname, "weapon_railgun") == 0) {
strcpy(ent->item, "item_health_mega");
}

-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
In my mod, what I did was to use cvars, for example something like
if(Q_stricmp(ent->classname, "bfg") == 0) {
strcpy(ent->item, replacebfg.string);
}
Define replacebfg in g_main.c, somewhere in the cvar table list and add an entry for it in g_local.h
you can then put something like
set replacebfg "weapon_railgun"
in a cfg file or set it ingame.
As for your problem, put an else before the second if.
if(Q_stricmp(ent->classname, "bfg") == 0) {
strcpy(ent->item, replacebfg.string);
}
Define replacebfg in g_main.c, somewhere in the cvar table list and add an entry for it in g_local.h
you can then put something like
set replacebfg "weapon_railgun"
in a cfg file or set it ingame.
As for your problem, put an else before the second if.
Code: Select all
if(Q_stricmp(ent->classname, "item_health_mega") == 0) {
strcpy(ent->item, "weapon_railgun");
}
else if(Q_stricmp(ent->classname, "weapon_railgun") == 0) {
strcpy(ent->item, "item_health_mega");
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
Ok, I think I did everything you suggested, however I am getting a couple warnings when compiling.
g_spawn.c
q3as.c
q3as.h
Errors:
g_spawn.c: warning: passing arg 1 of `__strcpy_small' from incompatible pointer type
It does compile however it isn't changing the item to what I set the cvar to. Any idea what I'm doing wrong?
g_spawn.c
Code: Select all
if(Q_stricmp(ent->classname, "item_health_mega") == 0) {
strcpy(ent->item, as_swap_item_health_mega.string );
}
Code: Select all
{ &as_swap_item_health_mega, "as_swap_item_health_mega", "item_health_mega", 0, 0, qfalse },
Code: Select all
extern vmCvar_t as_swap_item_health_mega;
g_spawn.c: warning: passing arg 1 of `__strcpy_small' from incompatible pointer type
It does compile however it isn't changing the item to what I set the cvar to. Any idea what I'm doing wrong?
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
Is there a particular reason you are putting it in q3as.c and q3as.h as opposed to g_main.c and g_local.h?
You could try putting
#include "q3as.h"
at the top of the g_spawn.c file.
You could try putting
#include "q3as.h"
at the top of the g_spawn.c file.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
I have already included the header file. It shouldnt matter which one its in as long as its included. right?
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
yes. Also make sure you have actually defined as_swap_item_health_mega, probably in q3as.c or something.
vmCvar_t as_swap_item_health_mega;
The bit in the header file is to let other files see it.
vmCvar_t as_swap_item_health_mega;
The bit in the header file is to let other files see it.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
Yes, I forgot to mention it but I do have this added at the end of the cvar list in q3as.c
vmCvar_t as_swap_item_health_mega;
vmCvar_t as_swap_item_health_mega;
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
The only thing I can think of to try is
strcpy(ent->item, va("%s", as_swap_item_health_mega.string) );
strcpy(ent->item, va("%s", as_swap_item_health_mega.string) );
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
same warnings...
passing 1 of '__strcpy_small' from incompatible pointer type
passing 1 of 'strcpy' from incompatible pointer type
passing 1 of '__strcpy_small' from incompatible pointer type
passing 1 of 'strcpy' from incompatible pointer type
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
What are you using to compile?
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
Dunno, I don't get that warning when I compile and it works fine for me, but I am using a different compile method.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
Re: Swapping items
I know it has to be something small im doing wrong... anyone else ever seen this error and/or know what it means???
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Swapping items
Is ent->item a string? I somehow doubt it.
-
- Posts: 304
- Joined: Fri Aug 08, 2003 7:00 am
Re: Swapping items
Oops! *facepalm*
I knew it was something blatantly obvious that I missed somehow.
I knew it was something blatantly obvious that I missed somehow.

-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]