View Full Version : Lots of Questions :P
Marine
05-20-2007, 03:07 PM
Hey,
Basically just playing with modding, scrapped my last mod because the code was getting screwed up, so at the moment ive got these ideas::
HL2MP Mod Code.
Teams
Military Vehicles
Only problem, i would like the vehicles to be able to be flipped over, and "killed".
When they are killed there is a delay of about 10 seconds before it respawns where it was.
I have got the "killing" part done, but i can't get it to respawn. Any ideas? Also, it wont "flip over", it will go half-way but just flips back upright...
Cheers
Marine
foomanchurocks
05-20-2007, 03:13 PM
Hi Marine,
If you are trying to get vehicles working in multiplayer I believe your in big trouble. As far as I know, Steam said it was impossible to get vehicles working properly in multiplayer do to prediction issues (whatever that means :P). I don't know if they have fixed the source engine to support this yet or if they ever will so you may want to look it up first.
Jordan
::EDIT::
Also, I find it helpful to get one feature working at a time. Then when your sure that feature is properly implemented, BACK UP the entire source code folder to a seperate location just incase you screw up your code. Then you have a copy to revert back to.
Marine
05-20-2007, 03:22 PM
Yeh, ive heard about the prediction, and tbh i dont care :P Its just going to be tank shooting tank no racing stuff like that. Its not totally around vehicles either, there will only be one or two (The tank and humvee i have were done for gmod 9). :P
But yeh, one feature at a time is a good plan, just gotta get my SVN working properly now.
Still need to know how to respawn the vehicle / let them be flipped over tho :P
NokiaTokia
05-20-2007, 03:46 PM
You never actually have to remove the vehicle from memory, instead when the vehicle dies you spawn a explosion and gib, then you reset the vehicle to its starting position and reset all of its initial stats. (When it spawns, remember where it spawns using something like VecSpawn = GetAbsOrigin() ).
As for the vehicle tipping, valve was kind of enough to introduce a nice method of changing the tipping value. In your vehicles class use the following code:
float VehicleName::GetUprightStrength( void )
{
return 1.0f; // The higher the value, the harder to tip over...
}
Marine
05-20-2007, 03:57 PM
Aah, cheers, that actually makes sense :P
Source coding is actually quite logical (I am finding out), interesting to learn C++ in a fun way rather than web page after web page).
I might need help later with Lua embedding (Very simple implementation, i can work out the more advanced stuff).
Marine
05-20-2007, 04:38 PM
Ok, another problem. In the spawn function it saves the vehicles position, but it does not return it most of the time (When it does and you get back in it it teleports back to where it flipped over).
http://www.pastebin.ca/499244
There is vehicle_jeep.cpp
I should in theory work, but i cant see whats going on there :S
NokiaTokia
05-20-2007, 04:50 PM
BaseClass::SetAbsOrigin(m_vecSpawnPos);
BaseClass::SetAbsAngles(m_vecSpawnAng);
should be
SetAbsOrigin(m_vecSpawnPos);
SetAbsAngles(m_vecSpawnAng);
BaseClass refers to sending or getting information from its parent class...
Marine
05-20-2007, 04:53 PM
Oh... Jees.
I used BaseClass:: to get the function list (I make sure im typing it right), and i must have forgotten to remove it. :(
I'll see if it works now then i have to go to bed (Its 1am here, gotta wake up at 9am today :D)
Marine
05-20-2007, 04:57 PM
It doesnt actually move at all now, it just stays upside down continually exploding... Maybe i need BaseClass:: on both get and set?
Edit:: Nope, same again, it either stays upside down and continually explodes, or it moves back to its original position (Where if you get in or touch it, or touch/shoot where it blew up), it teleports you and it back to where it was when it exploded the first time. Very weird.
http://img526.imageshack.us/img526/2213/tanktest0000fw5.th.jpg (http://img526.imageshack.us/my.php?image=tanktest0000fw5.jpg)
(It moves to about a meter off the ground when it returns)....
Marine
05-21-2007, 04:29 AM
Ok, ive tried a different approach to use the Physics Get/SetPosition (A mad idea after looking at the Garry's Mod wiki).
Only problem is converting between types :S
vehicle_jeep.h
Vector* m_vecSpawnPos; // Spawns the jeep at its original position...
QAngle* m_vecSpawnAng;
Thats only my variable definition.
vehicle_jeep.cpp
void CPropJeep::Think(void)
{
BaseClass::Think();
CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
if ( m_bEngineLocked )
{
m_bUnableToFire = true;
if ( pPlayer != NULL )
{
pPlayer->m_Local.m_iHideHUD |= HIDEHUD_VEHICLE_CROSSHAIR;
}
}
else if ( m_bHasGun )
{
// Start this as false and update it again each frame
m_bUnableToFire = false;
if ( pPlayer != NULL )
{
pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_VEHICLE_CROSSHAIR;
}
}
// Water!?
HandleWater();
SetSimulationTime( gpGlobals->curtime );
SetNextThink( gpGlobals->curtime );
SetAnimatedEveryTick( true );
if ( !m_bInitialHandbrake ) // after initial timer expires, set the handbrake
{
m_bInitialHandbrake = true;
m_VehiclePhysics.SetHandbrake( true );
m_VehiclePhysics.Think();
}
// Check overturned status.
if ( !IsOverturned() )
{
m_flOverturnedTime = 0.0f;
}
else
{
m_flOverturnedTime += gpGlobals->frametime;
}
if ( m_flOverturnedTime > 10.0f ) // Been more than 10 seconds of being overturned? If so, blow the ****er up! :P
{
m_flOverturnedTime = 0.0f;
SetRenderColor(255,0,0);
ExplosionCreate( GetAbsOrigin() + Vector( 0, 0, 16 ), GetAbsAngles(), ToBaseCombatCharacter(GetOwnerEntity()), GetDamage(), 500, SF_ENVEXPLOSION_NODLIGHTS, 0.0f, this);
IPhysicsObject *pPhysics = VPhysicsGetObject();
pPhysics->SetPosition(m_vecSpawnPos,m_vecSpawnAng,false);
// SetAbsOrigin(m_vecSpawnPos);
//SetAbsAngles(m_vecSpawnAng);
SetRenderColor(0,0,255);
}
// spin gun if charging cannon
//FIXME: Don't bother for E3
if ( m_bCannonCharging )
{
// m_nSpinPos += JEEP_GUN_SPIN_RATE;
//SetPoseParameter( JEEP_GUN_SPIN, m_nSpinPos );
}
// Aim gun based on the player view direction.
if ( m_hPlayer && !m_bExitAnimOn && !m_bEnterAnimOn )
{
Vector vecEyeDir, vecEyePos;
m_hPlayer->EyePositionAndVectors( &vecEyePos, &vecEyeDir, NULL, NULL );
if ( IsXbox() )
{
autoaim_params_t params;
params.m_fScale = AUTOAIM_SCALE_DEFAULT * 10.0f;
params.m_fMaxDist = autoaim_max_dist.GetFloat();
m_hPlayer->GetAutoaimVector( params );
// Use autoaim as the eye dir if there is an autoaim ent.
vecEyeDir = params.m_vecAutoAimDir;
}
// Trace out from the player's eye point.
Vector vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH );
trace_t trace;
UTIL_TraceLine( vecEyePos, vecEndPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &trace );
// See if we hit something, if so, adjust end position to hit location.
if ( trace.fraction < 1.0 )
{
vecEndPos = vecEyePos + ( vecEyeDir * MAX_TRACE_LENGTH * trace.fraction );
}
//m_vecLookCrosshair = vecEndPos;
AimGunAt( &vecEndPos, 0.1f );
}
StudioFrameAdvance();
// If the enter or exit animation has finished, tell the server vehicle
if ( IsSequenceFinished() && (m_bExitAnimOn || m_bEnterAnimOn) )
{
if ( m_bEnterAnimOn )
{
m_VehiclePhysics.ReleaseHandbrake();
StartEngine();
// HACKHACK: This forces the jeep to play a sound when it gets entered underwater
if ( m_VehiclePhysics.IsEngineDisabled() )
{
CBaseServerVehicle *pServerVehicle = dynamic_cast<CBaseServerVehicle *>(GetServerVehicle());
if ( pServerVehicle )
{
pServerVehicle->SoundStartDisabled();
}
}
// The first few time we get into the jeep, print the jeep help
if ( m_iNumberOfEntries < hud_jeephint_numentries.GetInt() )
{
//UTIL_HudHintText( m_hPlayer, "#Valve_Hint_JeepKeys" );
//m_iNumberOfEntries++;
}
}
// If we're exiting and have had the tau cannon removed, we don't want to reset the animation
GetServerVehicle()->HandleEntryExitFinish( m_bExitAnimOn, !(m_bExitAnimOn && TauCannonHasBeenCutOff()) );
}
// See if the ammo crate needs to close
if ( ( m_flAmmoCrateCloseTime < gpGlobals->curtime ) && ( GetSequence() == LookupSequence( "ammo_open" ) ) )
{
m_flAnimTime = gpGlobals->curtime;
m_flPlaybackRate = 0.0;
SetCycle( 0 );
ResetSequence( LookupSequence( "ammo_close" ) );
}
else if ( ( GetSequence() == LookupSequence( "ammo_close" ) ) && IsSequenceFinished() )
{
m_flAnimTime = gpGlobals->curtime;
m_flPlaybackRate = 0.0;
SetCycle( 0 );
ResetSequence( LookupSequence( "idle" ) );
CPASAttenuationFilter sndFilter( this, "PropJeep.AmmoClose" );
EmitSound( sndFilter, entindex(), "PropJeep.AmmoClose" );
}
}
Errors from the Compile log:
------ Build started: Project: server_hl2mp, Configuration: Debug HL2MP Win32 ------
Compiling...
vehicle_jeep.cpp
d:\modding\hl2\marinesmod\src\dlls\hl2_dll\vehicle _jeep.cpp(724) : error C2664: 'IPhysicsObject::SetPosition' : cannot convert parameter 1 from 'Vector *' to 'const Vector &'
Reason: cannot convert from 'Vector *' to 'const Vector'
No constructor could take the source type, or constructor overload resolution was ambiguous
Creating browse information file...
lodle
05-21-2007, 05:14 AM
use castings:
const_cast<Vector >(&vecSpawnPos)
that should do it i think
Marine
05-21-2007, 08:12 AM
Uh Oh :(
const_cast<const Vector >(&m_vecSpawnPos);
pPhysics->SetPosition(m_vecSpawnPos,m_vecSpawnAng,false);
The lines giving me grief
d:\modding\hl2\marinesmod\src\dlls\hl2_dll\vehicle _jeep.cpp(724) : error C2440: 'const_cast' : cannot convert from 'Vector **' to 'const Vector'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
d:\modding\hl2\marinesmod\src\dlls\hl2_dll\vehicle _jeep.cpp(725) : error C2664: 'IPhysicsObject::SetPosition' : cannot convert parameter 1 from 'Vector *' to 'const Vector &'
Reason: cannot convert from 'Vector *' to 'const Vector'
No constructor could take the source type, or constructor overload resolution was ambiguous
I fixed the first couple of errors, but thats got me stumped. I tried const Vector, everything i could think of.
Cheers
lodle
05-21-2007, 08:16 AM
u ether need to save it to another var:
Vector temp = const_cast<const Vector >(*m_vecSpawnPos);
pPhysics->SetPosition(temp,m_vecSpawnAng,false);
or use it inline:
pPhysics->SetPosition(const_cast<const Vector >(*m_vecSpawnPos),m_vecSpawnAng,false);
casting is like adding, uses less by it self. I suggest you read up on casting in c++ it is very usefull and used often in the source code.
Oh and i screwed up with the & there. Just change it to a *.
(& returns the address of the value, * returns the value at the address.)
Marine
05-21-2007, 08:27 AM
Aah, i'm getting there :P I am more knowledgable in C++ while doing this, next big task for me will be getting some VERY simple Lua bindings in there for weapons or vehicles.
I will need some help with that, then i will probably be able to get it done by myself. (Not as many bindings as Garry's Mod, no flippin way :P)
Marine
05-21-2007, 08:56 AM
ehicle_jeep.cpp
d:\modding\hl2\marinesmod\src\dlls\hl2_dll\vehicle _jeep.cpp(724) : error C2440: 'const_cast' : cannot convert from 'Vector' to 'Vector'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast
Oh dear oh dear, the compilers gone Nutty (Why does it need to convert Vector to Vector?
lodle
05-21-2007, 03:48 PM
ok we are almost there. Well the first error msg you had before was complaning that the vector wasnt constant. so thats what const_cast does (make it constant). And yes we cast this vector to vector because we want it to stay the same. ANother way to do this is to cheat:
const Vector temp = *m_vecSpawnPos;
pPhysics->SetPosition(temp,m_vecSpawnAng,false);
See if that works.
(i hate const things, worst is strings with const :()
Parthalan
05-23-2007, 01:45 AM
This doesn't look to be a problem with const, guys. Returning to the original error,
error C2664: 'IPhysicsObject::SetPosition' : cannot convert parameter 1 from 'Vector *' to 'const Vector &'
The function IPhysicsObject::SetPosition, to which you are passing m_vecSpawnPos (which is declared as a Vector *), takes an argument of type Vector &! When a parameter is specified as const, it ensures that the function will not modify the variable - not that the variable you pass must be const. This makes sense, too, as if we had declared a const Vector, we want to be able to create functions which won't violate const semantics. If it helps, think of it this way. We can convert non-constant types to constant types implicitly, but we can not convert constants to non-constants (this is the situation where you would need const_cast)!
With this in mind, you have two options, either you can dereference your pointer when you call SetPosition, and any other methods that take arguments of Vector &, or you can change the type of the variable, which seems to be the better option. These vector methods are designed for passing by reference, so there is no real performance impact, and you won't need to have pointer operations every time you want to work with the variable.
lodle
05-23-2007, 02:36 AM
Well past exp with that error means that it had to be constant. What i posted above should work.
or this is partalans way and should work according to him:
pPhysics->SetPosition(*m_vecSpawnPos,m_vecSpawnAng,false);
Marine
05-23-2007, 03:26 AM
Well past exp with that error means that it had to be constant. What i posted above should work.
or this is partalans way and should work according to him:
pPhysics->SetPosition(*m_vecSpawnPos,m_vecSpawnAng,false);
I actually found that to work by myself :P but the vehicle still didnt Completely move, it would teleport and then when you touched it or shot it either at the position it was before,or its new position, it would teleport back upside down. I gave up at this point, im going to get all of the other stuff into my mod and then i will work on some vehicles (Maybe with prediction if TG wants to help me :( )
You shouldn't need to be casting your vectors like that - your issue is that you're storing pointers to your Vectors and QAngles. The majority of functions take them by reference.
Reason: cannot convert from 'Vector *' to 'const Vector'
Gives it away in your first compile error log - store a straight Vector value rather than a pointer and you'll find life, way, way easier.
[edit]
Parthalan beat me to it.
but the vehicle still didnt Completely move, it would teleport and then when you touched it or shot it either at the position it was before,or its new position, it would teleport back upside down.
That sounds like an issue with the physics shadow not updating, as that controls the actual position of the entity. You can see a similar thing with the default SDK bots - their physics shadow isn't updated very often so you'll often find them snapping back to where it actually is.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.