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.