Thread: ScriptHook
View Single Post
Old 04-07-2009   #6
rappo
Professional Dumbass
 
rappo's Avatar
 
Join Date: Aug 2003
Location: Los Angeles
Posts: 6,949
rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.rappo is a God.
Okay I compiled and ran my own version, and it works. I think the main problem is that you had TaskPlayAnim(..."spli ff") with a space between the spli and ff... you have to make that "spliff" and it might work. But here's my version, and it's working (the only thing is, there's no spliff model, just the smoke, but you have to code in RequestModel if you want the actual thing to appear):

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();
};
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.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);
	}
}
rappo is online now   Reply With Quote