Changing Player (Seamless?)
Moderator: InsideQC Admins
15 posts
• Page 1 of 1
Changing Player (Seamless?)
Ok, I am trying to fake weapon attachments, my method and my choice to do it this way is irrelevant, I just need some help, I'm a tad rusty in QC, its been awhile.
I have multiple player models, one for each weapons and matching frames etc.
I want it when you pick up a weapon and/or you switch to the weapon, it changes the player's model to the one matching his new weapon. Where would the best place be to place this code? I tried in W_setcurrentammo, setmodel and setsize after the weapon stuff, nothing happened.
I have multiple player models, one for each weapons and matching frames etc.
I want it when you pick up a weapon and/or you switch to the weapon, it changes the player's model to the one matching his new weapon. Where would the best place be to place this code? I tried in W_setcurrentammo, setmodel and setsize after the weapon stuff, nothing happened.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
check this hacked-ass code in putclientinserver (); in client.qc for how id software changed models on the fly!
- Code: Select all
setmodel (self, "progs/eyes.mdl");
modelindex_eyes = self.modelindex;
setmodel (self, "progs/player.mdl");
modelindex_player = self.modelindex;
-

Error - InsideQC Staff
- Posts: 865
- Joined: Fri Nov 05, 2004 5:15 am
- Location: VA, USA
Sooooo, would this work?
or would i need to define a new modelindex or something?
I see in powerups where is says self.modelindex = modelindex_eyes, where would I make a modelindex_weapon1, 2, 3, 4 etc?
- Code: Select all
setmodel (self, "progs/player_a");
modelindex_weapon1 = self.modelindex;
or would i need to define a new modelindex or something?
I see in powerups where is says self.modelindex = modelindex_eyes, where would I make a modelindex_weapon1, 2, 3, 4 etc?
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
Ghost_Fang wrote:Sooooo, would this work?
- Code: Select all
setmodel (self, "progs/player_a");
modelindex_weapon1 = self.modelindex;
or would i need to define a new modelindex or something?
I see in powerups where is says self.modelindex = modelindex_eyes, where would I make a modelindex_weapon1, 2, 3, 4 etc?
Awhile back I was playing around with visible weapons... doing it the same way you are. I didn't come up with the code and for the life of me I can't remember where I the code came from (VisWeap (Visible Weapons) by a Mr. Garnett?). If you like I could send or post the edited qc files.
Can't remember if there were any glitches, but it did seem to work.
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
sure, post some excerpts from the code, I just need the general ieda and I can go off from that. Kinda like centerprinting names when you look at them, I didn't like how the code was setup so I did it my own way, but I still needed to see the code to spawn some ideas.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
Ok... here goes... it's not pretty... and I would love to see what you come up with or what comments others have!
And again, not my code/idea... just wanted to check it out... never pursued it any further
This is what I have in a separate qc (vwep.qc) file:
Then in client.qc in PutClientInServer:
Now place CheckModel(); in the following places:
Client.qc - CheckForPowerups function
player.qc - PlayerDie function
weapons.qc - W_SetCurrentAmmo
And to finish... in world.qc - worldspawn function:
And again, not my code/idea... just wanted to check it out... never pursued it any further
This is what I have in a separate qc (vwep.qc) file:
- Code: Select all
float modelindex_playernail;
float modelindex_playersnail;
float modelindex_playergren;
float modelindex_playerrock;
float modelindex_playerlight;
float modelindex_playeraxe;
float modelindex_playersshot;
float modelindex_playershot;
void () CheckModel
{
if (self.weapon == IT_AXE)
self.modelindex = modelindex_playeraxe;
else if (self.weapon == IT_SHOTGUN)
self.modelindex = modelindex_playershot;
else if (self.weapon == IT_SUPER_SHOTGUN)
self.modelindex = modelindex_playersshot;
else if (self.weapon == IT_NAILGUN)
self.modelindex = modelindex_playernail;
else if (self.weapon == IT_SUPER_NAILGUN)
self.modelindex = modelindex_playersnail;
else if (self.weapon == IT_GRENADE_LAUNCHER)
self.modelindex = modelindex_playergren;
else if (self.weapon == IT_ROCKET_LAUNCHER)
self.modelindex = modelindex_playerrock;
else if (self.weapon == IT_LIGHTNING)
self.modelindex = modelindex_playerlight;
};
Then in client.qc in PutClientInServer:
- Code: Select all
// oh, this is a hack!
setmodel (self, "progs/eyes.mdl");
modelindex_eyes = self.modelindex;
//vwep start
setmodel (self, "progs/player_nail.mdl"); //vwep
modelindex_playernail = self.modelindex;
setmodel (self, "progs/player_snail.mdl"); //vwep
modelindex_playersnail = self.modelindex;
setmodel (self, "progs/player_gren.mdl"); //vwep
modelindex_playergren = self.modelindex;
setmodel (self, "progs/player_rock.mdl"); //vwep
modelindex_playerrock = self.modelindex;
setmodel (self, "progs/player_light.mdl"); //vwep
modelindex_playerlight = self.modelindex;
setmodel (self, "progs/player_axe.mdl"); //vwep
modelindex_playeraxe = self.modelindex;
setmodel (self, "progs/player_sshot.mdl"); //vwep
modelindex_playersshot = self.modelindex;
setmodel (self, "progs/player_shot.mdl"); //vwep
modelindex_playershot = self.modelindex;
//vwep end
Now place CheckModel(); in the following places:
Client.qc - CheckForPowerups function
- Code: Select all
// use the eyes
self.frame = 0;
self.modelindex = modelindex_eyes;
}
else
CheckModel(); //VWep
player.qc - PlayerDie function
- Code: Select all
self.radsuit_finished = 0;
CheckModel(); //vwep
weapons.qc - W_SetCurrentAmmo
- Code: Select all
else
{
self.currentammo = 0;
self.weaponmodel = "";
self.weaponframe = 0;
}
CheckModel (); //vwep
And to finish... in world.qc - worldspawn function:
- Code: Select all
precache_model ("progs/player.mdl");
//vwep start
precache_model ("progs/player_axe.mdl");
precache_model ("progs/player_shot.mdl");
precache_model ("progs/player_sshot.mdl");
precache_model ("progs/player_nail.mdl");
precache_model ("progs/player_snail.mdl");
precache_model ("progs/player_gren.mdl");
precache_model ("progs/player_rock.mdl");
precache_model ("progs/player_light.mdl");
//vwep end
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
Hmmm, im not sure i fully understand modelindex... I hope you don't mind I just copy/paste the whole thing haha. It's my own personal game me and my friends play anyways, not public.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
Ghost_Fang wrote:Hmmm, im not sure i fully understand modelindex... I hope you don't mind I just copy/paste the whole thing haha. It's my own personal game me and my friends play anyways, not public.
Lol... no problem... I'm not a big "copy/paste then walk a way" fan... but sometimes it's just nice to dissect something that works.
I dissected it from some code way "back in the day" and had it saved to a txt file. Ha!.. I actually had it saved on an old floppy! Not sure why!
Anyways, I don't understand the whole modelindex thingy either and was going to take a stab at it but got side-tracked with a VB project (QCPad).
By the way... the code I posted is from a mod called VisWeap and was created by somebody named Tom Garnett (Nihilist). This is credit to him!
I've heard other comments similar to Error's... must be something to do with engine side of things?
DP has a pretty cool feature that allows you to "stick" an entity to another entity. So if you're running DP maybe this is an easier/cleaner way of creating a visible weapon mod. Hmmm, I think this may have been done already?
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
Mexicouger wrote:I don't really understand model index either...
When you do something like:
- Code: Select all
setmodel (self, "progs/player.mdl");
Internally the engine sets in the informed entity (self in this case) a float field (.modelindex) with an index to the internal model caching array, so when Quake is going to render this entity avatar it refers to this index.
What the code above does is: for every model, call setmodel() then stores the index value set by the engine into a global var; later, when we want to apply a fast model swap, we just need to copy back the desired model index (for example, the player carrying the rocket launcher) back to .modelindex.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Aww.. So as a quick test, you could go into player_pre_think, and do something like this/
And it is basically a more faster/efficient way of switching the players model? Hmm, Kinda neat.
if (self.weapon == IT_SHOTGUN)
self.modelindex = player_shot;
And it is basically a more faster/efficient way of switching the players model? Hmm, Kinda neat.
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
Mexicouger wrote:Aww.. So as a quick test, you could go into player_pre_think, and do something like this/if (self.weapon == IT_SHOTGUN)
self.modelindex = player_shot;
And it is basically a more faster/efficient way of switching the players model? Hmm, Kinda neat.
Assuming in your example player_shot is the name of the global var where you previously stored the model index, yes.
EDIT: However, you won't want to change models in PlayerPreThink. The better suited place would be the same points where you would change the viewmodel.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Junrall wrote:DP has a pretty cool feature that allows you to "stick" an entity to another entity. So if you're running DP maybe this is an easier/cleaner way of creating a visible weapon mod. Hmmm, I think this may have been done already?
I tried doing something like that, i deleted the character off the weapon, made it its own entity, and if the player had that weapon it spawned the character-less weapon on top of the player, and the weapon.frames = owner's frames. But you saw the weapon in first person mode. So i threw that Idea out the window.
- Ghost_Fang
- Posts: 336
- Joined: Thu Nov 12, 2009 4:37 am
This is the same method used for RING of SHADOWS, swapping out the eyes.mdl for the player.mdl.
In client.qc void () PutClientInServer =
you may find something like this
It's kind of a hack, as
will check if the model ("progs/eyes.mdl") is precached on the server.
If so, then the self.modelindex is assigned with the index number from the server's model cache, and saved to modelindex_eyes...
Later on, when you want to swap models on the fly, instead of loading them when you need them, use the .modelindex
In your case you can set the modelindex in the code when you change weapons...
In client.qc void () PutClientInServer =
you may find something like this
- Code: Select all
if (modelindex_eyes == 0) // hasn't been done yet
{
setmodel (self, "progs/eyes.mdl");
modelindex_eyes = self.modelindex;
setmodel (self, "progs/h_player.mdl");
modelindex_head = self.modelindex;
}
setmodel(self, "progs/player.mdl");
modelindex_player = self.modelindex;
setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
self.view_ofs = '0 0 22';
It's kind of a hack, as
- Code: Select all
setmodel (self, "progs/eyes.mdl");
will check if the model ("progs/eyes.mdl") is precached on the server.
If so, then the self.modelindex is assigned with the index number from the server's model cache, and saved to modelindex_eyes...
- Code: Select all
modelindex_eyes = self.modelindex;
Later on, when you want to swap models on the fly, instead of loading them when you need them, use the .modelindex
- Code: Select all
if (self.invisible_finished)
{
self.modelindex = modelindex_eyes;
setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
}
In your case you can set the modelindex in the code when you change weapons...
- r00k
- Posts: 1110
- Joined: Sat Nov 13, 2004 10:39 pm
15 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest