Thread: ScriptHook
View Single Post
Old 04-06-2009   #1
Leito
Registered User
 
Leito's Avatar
 
Join Date: Jan 2009
Posts: 53
Leito will become famous soon enoughLeito will become famous soon enoughLeito will become famous soon enoughLeito will become famous soon enoughLeito will become famous soon enoughLeito will become famous soon enough
ScriptHook

Hi. My next topic about animation xD But I else learn and i dont know how to make any animation when i press F10. I found script, but i have error. Anybody help me? This script is in LogInfo("animation");.

Code:
#include "CustomFiberThread.h"
#include "Scripting.h"
#include "../ScriptHook/Log.h"

#include <windows.h>

// Pull in all our scripting functions/types
using namespace Scripting;

CustomFiberThread::CustomFiberThread()
{
	SetName("CustomFiberThread");
}

// Some helper functions

Player CustomFiberThread::GetPlayer()
{
	Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
	return playerIndex;
}

Scripting::Ped CustomFiberThread::GetPlayerPed()
{
	Ped ped;
	GetPlayerChar(GetPlayer(), &ped);
	return ped;
}


void CustomFiberThread::SpawnCar(eModel model)
{
	RequestModel(model);

	while(!HasModelLoaded(model))
	{
		Wait(0);
	}

	LogInfo("Car model available... spawning it!");

	Ped ped = GetPlayerPed();

	Vehicle vehicle;
	f32 x,y,z;

	GetCharCoordinates(ped, &x, &y, &z);

	CreateCar(model, x, y, z, &vehicle, true);

	MarkModelAsNoLongerNeeded(model);

}

void CustomFiberThread::ChangePlayerSkin(eModel model)
{
	RequestModel(model);

	while(!HasModelLoaded(model))
	{
		Wait(0);
	}

	LogInfo("Skin model available... spawning it!");

	eInteriorRoomKey roomKey;
	
	GetKeyForCharInRoom(GetPlayerPed(), &roomKey);

	ChangePlayerModel(GetPlayer(), model);

	SetRoomForCharByKey(GetPlayerPed(), roomKey);

	MarkModelAsNoLongerNeeded(model);

}

// The real script

void CustomFiberThread::RunScript()
{
	// This is a fiber thread, so we use an loop to run the contents of this script.
	// The thread will terminate when we return from this function.

	while(IsThreadAlive())
	{

		if ((GetAsyncKeyState(VK_F5) & 1) != 0)
		{
			LogInfo("Spawning a random car");

			Vehicle vehicle;
			u32 modelHash;
			ScriptAny unknown;

			f32 x,y,z;
			GetCharCoordinates(GetPlayerPed(), &x, &y, &z);

			GetRandomCarModelInMemory(1, &modelHash, &unknown);
			CreateCar(modelHash, x, y, z, &vehicle, true);
		}
		else if ((GetAsyncKeyState(VK_F6) & 1) != 0)
		{
			LogInfo("Granting player $1000");

			AddScore(GetPlayer(), 1000);
		}
		else if ((GetAsyncKeyState(VK_F7) & 1) != 0)
		{
			LogInfo("Requested a MODEL_BANSHEE spawn");

			SpawnCar(MODEL_BANSHEE);
		}	
		else if ((GetAsyncKeyState(VK_F8) & 1) != 0)
		{
			LogInfo("Changing the player skin");

			ChangePlayerSkin(MODEL_IG_JOHNNYBIKER);
		}
		else if ((GetAsyncKeyState(VK_F9) & 1) != 0)
		{
			LogInfo("Changing the player skin back to Niko's");

			ChangePlayerSkin(MODEL_PLAYER);
		}




else if ((GetAsyncKeyState(VK_F10) & 1) != 0)
 {
LogInfo("animation");

  m_animName="amb@smoking_spliff";
  m_animSequence="create_spliff";
  speed=4.0f;
  RequestAnims(m_animName);
  anim=1;
  m_State = StateAnim;
  }


case StateAnim:
{
else if (HaveAnimsLoaded(m_animName))
 {
 Ped ped;
 Player playerIndex = ConvertIntToPlayerIndex(GetPlayerId());
 GetPlayerChar(playerIndex, &ped);
 TaskPlayAnim(ped,m_animSequence,m_animName,speed,0,0,0,0,-1);
 m_State = StateDefault;
 } 

}
break;



		// Call Wait() so we can process other scripts/game code
		// You must call Wait(...) in your loop code for a fiber thread!
		Wait(100);

	}


}
Leito is offline   Reply With Quote