![]() |
![]() |
Salvax |
![]()
Post
#1
|
![]() Advanced Member ![]() ![]() ![]() Group: Members Posts: 75 Joined: 14-February 07 Member No.: 1,034 ![]() |
bot can't hold a gravity gun even the bot profile is edited : weapon = weapon_physcannon
lost weapon code in some files of the source? ![]() i am doing some thing on checkstuck part of the codes in bot.cpp, trying if bot can use gravity gun to push the objects away, but i find bot can't even hold a gravity gun...*faint* |
![]() ![]() |
Salvax |
![]()
Post
#2
|
![]() Advanced Member ![]() ![]() ![]() Group: Members Posts: 75 Joined: 14-February 07 Member No.: 1,034 ![]() |
"phys_swap" is for switching back to a weapon the bot was holding, and SetActiveWeapon won't switch back, but only give bot a static gun.
this is the sample code for bot to push and pull objects, plz check. seems m_pController->SetActiveWeapon can't be used here directly ? - bot.cpp - QUOTE void CBot :: checkStuck () { static float fTime; fTime = engine->Time(); if ( m_fLastWaypointVisible == 0 ) { m_bFailNextMove = false; if ( !hasSomeConditions(CONDITION_SEE_WAYPOINT) ) m_fLastWaypointVisible = fTime; } else { if ( hasSomeConditions(CONDITION_SEE_WAYPOINT) ) m_fLastWaypointVisible = 0; else { if ( (m_fLastWaypointVisible + 2.0) < fTime ) { m_fLastWaypointVisible = 0; m_bFailNextMove = true; } } } if ( m_fCheckStuckTime > fTime ) return; float fVelocity = m_vVelocity.Length2D(); float fIdealSpeed = m_fIdealMoveSpeed; if ( m_pButtons->holdingButton(IN_DUCK) ) fIdealSpeed /= 2; if ( fIdealSpeed == 0 ) return; // not stuck float fPercentMoved = fVelocity/fIdealSpeed; if ( fPercentMoved < 0.1 ) { m_pButtons->jump(); m_pButtons->duck(0.25f,0.25f); m_pController->SetActiveWeapon("weapon_physcannon"); // switch to Gravity Gun by salvax , but how to make this work ? encountered error !!! m_pButtons->attack() //bot use gravity gun to push by salvax m_pButtons->attack2() //bot use gravity gun to pull by salvax m_fCheckStuckTime = fTime + 4.0f; m_pController->SetActiveWeapon(m_pProfile->getWeapon()); //switch back to the weapon in bot profile by salvax, still have error here!! } . . . . PS : how to let a bot holding a gravity gun switch to the gun he just picked up ? This problem really hurts my head ![]() PS2: how to let bot have specified weapon in bot profile and also the bot can pick up weapons ? This is very important, without this function , i can't continue. THX A LOT ! PS3: i add [void CHLDMBot :: modThink2 ()] into bot_hldm_bot.cpp for switching to gravity gun as i said above in the codes and add [modThink2 ();] into bot_hldm_bot.h under [class CHLDMBot : public CBot] if i wanna use modThink2(), what should i type? neither CHLDMBot->modThink2(); or m_pBot->modThink2(); works. ![]() |
Cheeseh |
![]()
Post
#3
|
![]() Admin ![]() ![]() ![]() ![]() ![]() Group: Admin Posts: 3,066 Joined: 11-September 03 From: uk Member No.: 1 ![]() |
why do you need a modthink2 ?? Just use the one function.
what error are you getting ??? anyway... CODE m_pController->SetActiveWeapon("weapon_physcannon"); // switch to Gravity Gun by salvax , but how to make this work ? encountered error !!! m_pButtons->attack() //bot use gravity gun to push by salvax m_pButtons->attack2() //bot use gravity gun to pull by salvax m_fCheckStuckTime = fTime + 4.0f; m_pController->SetActiveWeapon(m_pProfile->getWeapon()); //switch back to the weapon in bot profile by salvax, still have error here!! This won't work anyway. These sort of things only update at the end of each frame, you need to understand game programming in particular the half-life game engine. You need to SetActiveWeapon() to the weapon you want when you want it, then use it, which may take a couple of frames or a few seconds, then switch back to the weapon using m_pController->SetActiveWeapon(m_pProfile->getWeapon()); The half-life engine handles time as a consitently increasing float number, it increases by 1.0 every second. You can make a timer, by storing a variable accessabile by the bot a both start and end of the timer, such as in CBot, call it float m_flGravityGunSwitchTimer, and initialise to zero. This floating point number can be used to represent the end time you want the bot to switch back to the previous weapon by using "if (m_flGravityGunSwitchTimer && (engine->Time() > m_flGravityGunSwitchTimer))" and starting the timer by setting "m_flGravityGunSwitchTimer = engine->Time() + 2.0f;" this makes the if statement true when two seconds pass from the current time when it is given that value. This "if statement" can be checked everytime in ModThink or Think. Then after switching the weapon back to normal set "m_flGravityGunSwitchTimer = 0.0f;" The timer value can also be checked if the time is when before switching the weapons. You can find out what the previous weapon was by using "m_pPlayerInfo->GetWeaponName()" as shown in the HLDMBot::modthink code. You can store a const char* m_szPrevWeaponName, for example, and store this, and then go back to it using SetActiveWeapon on m_szPrevWeaponName. //::Init /////////// m_szPreviousWeapon = NULL; m_flGravityGunSwitchTimer = 0.0f; // changing weapon //////////// m_szPreviousWeapon = m_pPlayerInfo->GetWeaponName(); m_pController->SetActiveWeapon("weapon_physcannon"); m_flGravityGunSwitchTimer = engine->Time + 2.0f; //////////// // Think or modthink (in hldmbot) //////////// if (m_flGravityGunSwitchTimer && (engine->Time() > m_flGravityGunSwitchTimer)) // timer end { m_pController->SetActiveWeapon(m_szPreviousWeapon); m_flGravityGunSwitchTimer = 0.0f; } else if ( m_flGravityGunSwitchTimer ) // between timer { if ( RandomInt(1,100) < 10 ) PrimaryAttack(); } //////////// You can figure this kind of thing out automatically if you have experience with the engine and C++ programming. This posted code is pure example only, and may require some thinking to get it working together into the program. |
![]() ![]() |
![]() |
Lo-Fi Version | Time is now: 21st August 2025 - 11:45 PM |