Something I must be missing about SendEntity

Discuss CSQC related programming.
Post Reply
Subject9x
Posts: 7
Joined: Thu Feb 10, 2011 4:12 am
Contact:

Something I must be missing about SendEntity

Post by Subject9x »

Hello all, I'm working on a total conversion mod of Darkplaces to a mech shooter.
I've progressed far enough where creating a custom UI will help in testing character stats, so naturally its time to dig into some CSQC.

I've gotten one AddStat function working, but what's really throwing me is .SendEntity.

I want to use the SendEntity functionality to setup tempory entities as data channels to push updates to the client. So far I can pass info for ents that follow the player around...but I can't send random entities with data I want. If I send the player's "leg" entity, the data gets received, but the ent's origin gets completely messed up :/

SSQC:

Code: Select all

.float(entity viewer) SendEntity;
.float SendFlags;
.float Version;
float MSG_ENTITY = 5;

//one of my 'SendEntity' calls
float() csqc_SendVecComp={
  WriteByte(MSG_ENTITY, ENT_ADDVECCOMP);
  WriteString(MSG_ENTITY, self.c_name);
  WriteByte(MSG_ENTITY, self.max_health);
  WriteByte(MSG_ENTITY, self.health);
  WriteByte(MSG_ENTITY, self.armorvalue);
  WriteByte(MSG_ENTITY, self.max_armor);
  return TRUE;
};

Code: Select all

   
//the temporary entity to send
     local entity senda;
    senda = spawn();
    senda.c_name = self.e_legs.c_name;
    senda.health = self.e_legs.health;
    senda.max_health = self.e_legs.max_health;
    senda.armorvalue = self.e_legs.armorvalue;
    senda.max_armor =  self.e_legs.max_armor;
    senda.SendEntity = csqc_SendVecComp;
    senda.Version = senda.Version+1;
CSQC

Code: Select all

void CSQC_Ent_Update(float bIsNewEntity)
{
	local float i;
	i = readbyte();
  if(i == ENT_ADDVECCOMP){
    if(bIsNewEntity){
      local string n;
      n = readstring();
      if(n == M_LEGS){
        LEG_HP_MX = readbyte();
        LEG_HP_CUR = readbyte();
        LEG_ARM_CUR = readbyte();
        LEG_ARM_MX = readbyte();
      }
    }
  }
}
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Something I must be missing about SendEntity

Post by Spike »

if you write it, you read it. simple as shit.
or, to explain to people who don't understand simple, if you follow a branch in the ssqc then you must follow an equivelent branch in the csqc such that the same datatypes are read as those that were sent.
failure to do so, for instance because you fucked around with 'bIsNewEntity' (which has jack shit to do with the actual data that was sent), will de-sync the data stream, resulting in the engine interpretting 'junk' as the next entity. you can use bIsNewEntity to set up new defaults, but its generally best to just validate against some field yourself, in case the networking fell behind and the server respawned the entity as something else. either way, you MUST read the exact data that was actually sent, in the same order. if you discard it when its not new then that's fine, or you follow a different branch that discards the results of the read builtins then sure, but the exact same order of writes must be read. I can repeat that again, but I'm bored of pointing out the basic fundamentals of how ANY byte stream works (including networking ones, feel free to google fifos if you want to waste even more time).
you can verify that this is happening with the 'sv_csqcdebug 1' setting in FTE, but DP is more limited so good luck with that.

.Version is obsolete, use .SendFlags instead.

sending strings is generally very wasteful.

here's some docs I wrote on csqc ages ago. https://sourceforge.net/p/fteqw/code/HE ... format=raw and it looks like you would benefit from reading up on it.

Yes, I'm rude. Its called frustration.
Post Reply