Problem with sprites Created 8 months ago2023-08-18 03:28:11 UTC by RoJAn RoJAn

Created 8 months ago2023-08-18 03:28:11 UTC by RoJAn RoJAn

Posted 8 months ago2023-08-18 03:28:11 UTC Post #347783
Hey, great everyone, I was doing a command where if you press a specific key, the player would ask for help from a medic just like in TFC or Sven Coop.
//call medic
void CBasePlayer::MedicToogle(void)
{
CSprite * m_pCall = NULL;

if (gpGlobals->time < m_flCounter)
{
return;
}

//const Vector Position = pev->origin + Vector(0, 45, 0);

switch (RANDOM_LONG(1, 2))
{
case 1:
EMIT_SOUND(ENT(pev), CHAN_VOICE, "speech/saveme1.wav", 1, ATTN_NORM);
m_flCounter = gpGlobals->time + 3.5;
break;
case 2:
EMIT_SOUND(ENT(pev), CHAN_VOICE, "speech/saveme2.wav", 1, ATTN_NORM);
m_flCounter = gpGlobals->time + 3.5;
break;
}
if (m_pCall == NULL)
{
m_pCall = CSprite::SpriteCreate("sprites/saveme.spr", Vector(0, 0, 45), TRUE);
if (m_pCall)
{
m_pCall->SetTransparency(kRenderTransAdd, 255, 255, 255, 255, kRenderFxNoDissipation);
m_pCall->SetAttachment(edict(), 1);
m_pCall->SetScale(0.5);
m_pCall->TurnOn();
m_pCall->AnimateAndDie(20.0f); // different framerates = more visual variation
}
}
}
This inside` "Player.cpp"`.
Thing is that I'm using a sprite called "saveme.spr", from the TFC files, and it doesn't work as it should. This one remains invisible and does not appear, try with other sprites and most of them did appear when pressing the key, from what I understand, there's some sprites that must be added in a different way, like the "voiceicon.spr", so I wanted to know If any of you have any ideas and can tell me about this problem.

I'll wait for your answers.
Posted 8 months ago2023-08-18 17:28:48 UTC Post #347784
Try using the TE_PLAYERATTACHMENT message instead. It creates a temporary entity attached to the player that sticks around for a specific amount of time.

It works by using the clientIndex variable in TEMPENTITY along with the flags FTENT_PLYRATTACHMENT and FTENT_PERSIST, so if this message doesn't do the trick you can make your own. The rest of TEMPENTITY's variables you should be able to set up like you would a server side entity.
Posted 8 months ago2023-08-20 05:21:56 UTC Post #347788
Yeah, i'm kinda lost... tried to do that, but i just get errors and crashes, i think i'm missing something.
i'll see if i can figure this out later.

Edit: Still on this problem, the message directly doesn't recognize any model/sprite given and just finded this on my console: No model -24064! , so im kinda stuck now.
MESSAGE_BEGIN(MSG_BROADCAST, SVC_TEMPENTITY); //here we start a message which draws a beam behind a player

WRITE_BYTE(TE_PLAYERATTACHMENT); //sets the beam to follow the entity(player)
WRITE_SHORT(entindex()); // entity
WRITE_COORD(20);
WRITE_SHORT(m_mCall); //model/sprite
WRITE_BYTE(20); //life

MESSAGE_END(); //ends the message we started above
m_mCall already has a precache with a sprite that worked, I tried other messages that were not "TE_PLAYERATTACHMENT" and they managed to make the sprite appear (to a certain extent), so I think something is misspelled.
I'm pretty sure i'm doing something wrong but i don't know what.
Posted 8 months ago2023-08-22 03:45:14 UTC Post #347794
Hey, just fixed it, and i can't belive how i fixed it.
First, i writted the code much better and added a CBasePlayer to my void, which solved most of the problem, but then this message appeared: No model 175!
I spent hours trying to figure out the problem, and the answer is kinda surprising.
You see, the sprite wasn't supposed to be precached in the player's Precache(), so i precached the sprite in weapons.cpp, added an extern short to weapons.h and done!
//call medic
void CBasePlayer::MedicToogle(CBasePlayer* pPlayer)
{

if (gpGlobals->time < m_flCounter)
{
return;
}

switch (RANDOM_LONG(1, 2))
{
case 1:
EMIT_SOUND(ENT(pev), CHAN_VOICE, "speech/saveme1.wav", 1, ATTN_NORM);
m_flCounter = gpGlobals->time + 3.5;
break;
case 2:
EMIT_SOUND(ENT(pev), CHAN_VOICE, "speech/saveme2.wav", 1, ATTN_NORM);
m_flCounter = gpGlobals->time + 3.5;
break;
}

MESSAGE_BEGIN(MSG_BROADCAST, SVC_TEMPENTITY, pPlayer->pev->origin);
WRITE_BYTE(TE_PLAYERATTACHMENT);
WRITE_BYTE((BYTE)pPlayer->entindex());
WRITE_COORD(45);
WRITE_SHORT(g_sModelIndexMedic);
WRITE_SHORT(30);
MESSAGE_END();

}
This is the new code.
You must be logged in to post a response.