visual equipment / setattachment / parent/child ents

Discuss programming in the QuakeC language.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

visual equipment / setattachment / parent/child ents

Post by ceriux »

Visual Equipment mod release:

download
readme

mods mainly for coop and ffa use because the armor makes it to where you cannot see your custom colors.


-------------------------------------------------
okay so iv been attempting to get visual gear/weapons into quake. essentially what i did was edit the original player model i split the head from the body and weapons. the only part of the players model that it is still tied to the original player ent is the head model.

i spawn a new ent (pbody) and give it , it's own model. i then give the ent a think and next think which points to my body_think function. the body_think function tells pbody, that its frames are the same as its parents frames. the parent being the player/owner of pbody.

here's the thing i join the game with chase_active on i see the body set its frames to the idle frames then it crashes DP.

iv been trying to get help on IRC with this for the past 3 days. but no one there seems to know whats wrong. id really appreciate it if anyone could please point out what iv done/doing wrong. ill post the code here and a link to a pastebin.

--- body(); is only called once in client connect. i don't spam it in playerprethink or playerpostthink.

http://pastebin.com/zjU7kC4E

Code: Select all

// visual attachment stuff  (currently crashes)


void() body_think = 
{
	
	self.think = self.frame = self.parent.frame; // bodies frame is "parents" frame
	
	self.nextthink = time + 0.1; // think every 0.1 ticks

};

void() body =

{ 
	
	self.pbody = spawn ();  // spawn the body
	self.pbody.parent = self ;  // the bodies owner is the player
	
	
	
	setmodel (self.pbody, "progs/body.mdl"); // he will get the player body model
	setattachment (self.pbody, self.pbody.parent, ""); // attach the body model to "parent"
	
	self.pbody.think = body_think; // make the body think
	self.pbody.nextthink = time + 0.1; // it thinks every 0.1 ticks
};

EDIT : Right after i made this thread figured it out! im sorry, thread can be deleted. but ill post the fix and maybe the thread can be useful to someone else later on!



THE FIX:

Code: Select all

void() body_think = 
{
	self.frame = self.parent.frame; // bodies frame is "parents" frame
	self.think = body_think;
	
	self.nextthink = time + 0.01; // think every 0.01 ticks

};
Last edited by ceriux on Sun Nov 03, 2013 5:51 am, edited 3 times in total.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: visual equipment / setattachment / parent/child ents

Post by frag.machine »

I've made a multi part player model using MOVETYPE_FOLLOW instead of setattachment (see earlier version). It's tricky to make the body react in a synchronous way, but feasible.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: visual equipment / setattachment / parent/child ents

Post by ceriux »

i started using movetype_follow. i was told by LH that its not as good as setattachment, so i changed my code to use it.

it syncs pretty well as far as i can tell.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: visual equipment / setattachment / parent/child ents

Post by frag.machine »

hrmm, I think it's about time to me to learn more about setattachment then. :)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: visual equipment / setattachment / parent/child ents

Post by ceriux »

the code above could be used for weapons as well as a body =) right now im still using the quake guy. =) also works in multipalyer =)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: visual equipment / setattachment / parent/child ents

Post by Cobalt »

Sounds interesting , post a vid sample if u can.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: visual equipment / setattachment / parent/child ents

Post by ceriux »

sure as soon as i can. the current code posted above only draws the original body. but its easy enough to add in support for showing armors with a few lines (already added green armor.) id like to get some weapons added in before i make a video.

once i get all this added in, i might release the visual parts of my mod as a standalone so others can use it.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: visual equipment / setattachment / parent/child ents

Post by drm_wayne »

This is what i use to attach stuff to the player (weapons, legs etc...), works great in DQuake, Darkplaces but in FTEQW the legs are not really
synced xD
I use custom scratch qc so some stuff might look weird...

Legs ingame:

Image

Legs QC:

Code: Select all


void() legs_update =
	{
	float chasecam;
	chasecam = cvar("chase_active");
	if (chasecam == 1)	
	setmodel (self, string_null);
	else
	setmodel (self, "progs/players/p_legs.md2");	

	if (self.owner.deadflag != DEAD_NO)
            SUB_Remove();
		if (self.owner.incam == TRUE) // Intermission, we dont need to see our legs here
            SUB_Remove();
	makevectors(self.owner.v_angle);
	self.think = legs_update;
	self.nextthink = time + 0.01;
	
	self.angles_y = self.owner.angles_y;
	self.origin = self.owner.origin + v_up*-20;
	self.frame = self.owner.frame;
	}
		
void() player_legs = //Called at PutClientInServer
	{
	local entity legs
	makevectors(self.v_angle);
	legs = spawn();
	setmodel (legs, "progs/players/p_legs.md2");
	legs.solid = #SOLID_NOT;
	legs.movetype = #MOVETYPE_NOCLIP;
	legs.owner = self;
	legs.angles_y = self.angles_y;
	legs.origin = self.origin;
	legs.velocity = self.velocity;
	legs.drawonlytoclient = self;
	legs.frame = self.frame;
	legs.think = legs_update;
	legs.nextthink = time + 0.01;
	}


frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: visual equipment / setattachment / parent/child ents

Post by frag.machine »

float chasecam;
chasecam = cvar("chase_active");
if (chasecam == 1)
setmodel (self, string_null);
else
setmodel (self, "progs/players/p_legs.md2");
In DP there's a extension exactly to deal with this situation: IIRC is DP_VISIBLETOCLIENT. I'm using this and makes the code much simpler and elegant.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: visual equipment / setattachment / parent/child ents

Post by Spike »

fte defaults to prediction enabled.
cl_nopred to turn it off, or sv_nqplayerphysics to force it off for all clients (yay! authentic nq physics!).
you would see the same thing with DP and its cl_movement 1 setting.
setattachment works clientside so is meant to function properly regardless of prediction, instead of only when its disabled.
drm_wayne
Posts: 232
Joined: Sat Feb 11, 2012 5:47 pm

Re: visual equipment / setattachment / parent/child ents

Post by drm_wayne »

frag.machine wrote:
float chasecam;
chasecam = cvar("chase_active");
if (chasecam == 1)
setmodel (self, string_null);
else
setmodel (self, "progs/players/p_legs.md2");
In DP there's a extension exactly to deal with this situation: IIRC is DP_VISIBLETOCLIENT. I'm using this and makes the code much simpler and elegant.
I know, the qc i posted above is mainly designed for my customized PSP Engine, i already added some DP features like drawonlytoclient and nodrawtoclient.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: visual equipment / setattachment / parent/child ents

Post by frag.machine »

Just a correction: the DP extension I was referring actually is DP_ENT_EXTERIORMODELTOCLIENT.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: visual equipment / setattachment / parent/child ents

Post by ceriux »

update, im still working on this. got all the armor coded in, but the weapons are crashing the game so i have to figure that out first.

edit: so there wasnt any problem with my code, some how one of the models became corrupt and thats fixed. which essentially means there are 2 things left to do. there's a bug with the exit level cam where you see the body still, and theres a bug with ring of invisibility where you have a body walking around with a floating pair of eyes (kinda funny looking). after that all is finished! then i can release.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: visual equipment / setattachment / parent/child ents

Post by ceriux »

sorry for double post, mod has been finished, ill add information to the top of post.
Spirit
Posts: 1065
Joined: Sat Nov 20, 2004 9:00 pm
Contact:

Re: visual equipment / setattachment / parent/child ents

Post by Spirit »

Hey, it would be great if you could add a readme to the archive. Check out some readmes from idgames2 as good examples: https://www.quaddicted.com/files/idgame ... nversions/ :wink:

For Quake file hosting there is http://quaketastic.com/ : quaketastic - ZigguratVertigoBlewTronynsSocksOff
Improve Quaddicted, send me a pull request: https://github.com/SpiritQuaddicted/Quaddicted-reviews
Post Reply