Thread: ScriptHook
View Single Post
Old 05-27-2009   #14
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
Sure, but this code is this same what you have in post up.

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

#include <windows.h>

using namespace Scripting;

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

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

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

void CustomFiberThread::setDefaultValues() {
	playSpliff = false;
}

void CustomFiberThread::Start() {
	setDefaultValues();
	NativeThread::Start();
}

void CustomFiberThread::RunScript() {
	while(IsThreadAlive()) {
		if((GetAsyncKeyState(VK_F12) && 1) != 0) {
			LogInfo("Requesting spliff animation");
			RequestAnims("amb@smoking_spliff");
			playSpliff = true;
		}

		if(playSpliff && HaveAnimsLoaded("amb@smoking_spliff")) {
			LogInfo("Playing spliff animation");
			TaskPlayAnim(GetPlayerPed(), "create_spliff", "amb@smoking_spliff", 4.0f, 0, 0, 0, 0, -1);
			playSpliff = false;
		}

		Wait(100);
	}
}
Scripting.h
Code:
#pragma once

#include "../ScriptHook/Scripting.h"

namespace Scripting {
	static void TaskPlayAnim(Ped ped, const ch *animSequence, const ch *animName, f32 speed, int loop, f32 x, f32 y, f32 z, int ms) { NativeInvoke::Invoke("TASK_PLAY_ANIM", ped, animSequence, animName, speed, loop, x, y, z, ms); }
}
CustomFiberThread.h
Code:
#pragma once

#include "../ScriptHook/NativeFiberThread.h"
#include "../ScriptHook/ScriptingEnums.h"
#include "../ScriptHook/ScriptingTypes.h"

class CustomFiberThread : public NativeFiberThread {
private:
	Scripting::Player GetPlayer();
	Scripting::Ped GetPlayerPed();

	b8 playSpliff;

protected:
	void RunScript();
	void setDefaultValues();
	void Start();

public:
	CustomFiberThread();
};
__________________



My nick on YT - RyderPL
Leito is offline   Reply With Quote