[Plugin] samp.js - JavaScript for SA-MP
#74

FCNPC.inc.js (https://sampforum.blast.hk/showthread.php?tid=428066)
Code:
const MOVE_TYPE_WALK = 0;
const MOVE_TYPE_RUN = 1;
const MOVE_TYPE_SPRINT = 2;
const MOVE_TYPE_DRIVE= 3;

const MAX_NODES = 64;

const NODE_TYPE_NONE = (-1);
const NODE_TYPE_PED = 0;
const NODE_TYPE_VEHICLE = 1;
const NODE_TYPE_BOAT = 2;

RegisterPublic("FCNPC_OnCreate", "i", "FCNPC_OnCreate", ['npcid']);
RegisterPublic("FCNPC_OnSpawn", "i", "FCNPC_OnSpawn", ['npcid']);
RegisterPublic("FCNPC_OnRespawn", "i", "FCNPC_OnRespawn", ['npcid']);
RegisterPublic("FCNPC_OnDeath", "iii", "FCNPC_OnDeath", ['npcid', 'killerid', 'weaponid']);
RegisterPublic("FCNPC_OnVehicleEntryComplete", "iii", "FCNPC_OnVehicleEntryComplete", ['npcid', 'vehicleid', 'seat']);
RegisterPublic("FCNPC_OnVehicleExitComplete", "i", "FCNPC_OnVehicleExitComplete", ['npcid']);
RegisterPublic("FCNPC_OnReachDestination", "i", "FCNPC_OnReachDestination", ['npcid']);
RegisterPublic("FCNPC_OnFinishPlayback", "i", "FCNPC_OnFinishPlayback", ['npcid']);
RegisterPublic("FCNPC_OnTakeDamage", "iiiif", "FCNPC_OnTakeDamage", ['npcid', 'damagerid', 'weaponid', 'bodypart', 'health_loss']);
RegisterPublic("FCNPC_OnFinishNodePoint", "ii", "FCNPC_OnFinishNodePoint", ['npcid', 'point']);
RegisterPublic("FCNPC_OnChangeNode", "ii", "FCNPC_OnChangeNode", ['playerid', 'nodeid']);
RegisterPublic("FCNPC_OnFinishNode", "i", "FCNPC_OnFinishNode", ['npcid']);

function FCNPC_SetUpdateRate(rate) {
	return CallNativeGDK("FCNPC_SetUpdateRate", "i", rate);
}

function FCNPC_InitZMap(file) {
	return CallNativeGDK("FCNPC_InitZMap", "s", file);
}

function FCNPC_Create(name) {
	return CallNativeGDK("FCNPC_Create", "s", name);
}

function FCNPC_Destroy(npcid) {
	return CallNativeGDK("FCNPC_Destroy", "i", npcid);
}

function FCNPC_Spawn(npcid, skinid, x, y, z) {
	return CallNativeGDK("FCNPC_Spawn", "iifff", npcid, skinid, x, y, z);
}

function FCNPC_Respawn(npcid) {
	return CallNativeGDK("FCNPC_Respawn", "i", npcid);
}

function FCNPC_IsSpawned(npcid) {
	return CallNativeGDK("FCNPC_IsSpawned", "i", npcid);
}

function FCNPC_Kill(npcid) {
	return CallNativeGDK("FCNPC_Kill", "i", npcid);
}

function FCNPC_IsDead(npcid) {
	return CallNativeGDK("FCNPC_IsDead", "i", npcid);
}

function FCNPC_SetPosition(npcid, x, y, z) {
	return CallNativeGDK("FCNPC_SetPosition", "ifff", npcid, x, y, z);
}

function FCNPC_GetPosition(npcid) {
	let out = CallNativeGDK("FCNPC_GetPosition", "iFFF", npcid);
	return {x: out[0], y: out[1], z: out[2]};
}

function FCNPC_SetAngle(npcid, a) {
	return CallNativeGDK("FCNPC_SetAngle", "if", npcid, a);
}

function FCNPC_GetAngle(npcid) {
	return CallNativeGDK("FCNPC_GetAngle", "iF", npcid);
}

function FCNPC_SetQuaternion(npcid, x, y, z) {
	return CallNativeGDK("FCNPC_SetQuaternion", "iffff", npcid, x, y, z);
}

function FCNPC_GetQuaternion(npcid) {
	let out = CallNativeGDK("FCNPC_GetQuaternion", "iFFFF", npcid);
	return {x: out[0], y: out[1], z: out[2], a: out[3]};
}

function FCNPC_SetVelocity(npcid, x, y, z) {
	return CallNativeGDK("FCNPC_SetVelocity", "ifff", npcid, x, y, z);
}

function FCNPC_GetVelocity(npcid) {
	let out = CallNativeGDK("FCNPC_GetVelocity", "iFFF", npcid);
	return {x: out[0], y: out[1], z: out[2]};
}

function FCNPC_SetInterior(npcid, interiorid) {
	return CallNativeGDK("FCNPC_SetInterior", "ii", npcid, interiorid);
}

function FCNPC_GetInterior(npcid) {
	return CallNativeGDK("FCNPC_GetInterior", "i", npcid);
}

function FCNPC_SetHealth(npcid, health) {
	return CallNativeGDK("FCNPC_SetHealth", "if", npcid, health);
}

function FCNPC_GetHealth(npcid) {
	return CallNativeGDK("FCNPC_GetHealth", "iF", npcid);
}

function FCNPC_SetArmour(npcid, armour) {
	return CallNativeGDK("FCNPC_SetArmour", "if", npcid, armour);
}

function FCNPC_GetArmour(npcid) {
	return CallNativeGDK("FCNPC_GetArmour", "iF", npcid);
}

function FCNPC_SetSkin(npcid, skin) {
	return CallNativeGDK("FCNPC_SetSkin", "ii", npcid, skin);
}

function FCNPC_GetSkin(npcid) {
	return CallNativeGDK("FCNPC_GetSkin", "i", npcid);
}

function FCNPC_SetWeapon(npcid, weaponid) {
	return CallNativeGDK("FCNPC_SetWeapon", "ii", npcid, weaponid);
}

function FCNPC_GetWeapon(npcid) {
	return CallNativeGDK("FCNPC_GetWeapon", "i", npcid);
}

function FCNPC_SetAmmo(npcid, ammo) {
	return CallNativeGDK("FCNPC_SetAmmo", "ii", npcid, ammo);
}

function FCNPC_GetAmmo(npcid) {
	return CallNativeGDK("FCNPC_GetAmmo", "i", npcid);
}

function FCNPC_SetKeys(npcid, keys) {
	return CallNativeGDK("FCNPC_SetKeys", "ii", npcid, keys);
}

function FCNPC_GetKeys(npcid) {
	let out = CallNativeGDK("FCNPC_GetKeys", "iIII", npcid);
	return {updown: out[0], leftright: out[1], keys: out[2]};
}

function FCNPC_SetSpecialAction(npcid, actionid) {
	return CallNativeGDK("FCNPC_SetSpecialAction", "ii", npcid, actionid);
}

function FCNPC_GetSpecialAction(npcid) {
	return CallNativeGDK("FCNPC_GetSpecialAction", "i", npcid);
}

function FCNPC_ToggleReloading(npcid, toggle) {
	return CallNativeGDK("FCNPC_ToggleReloading", "ii", npcid, toggle);
}

function FCNPC_ToggleInfiniteAmmo(npcid, toggle) {
	return CallNativeGDK("FCNPC_ToggleInfiniteAmmo", "ii", npcid, toggle);
}

function FCNPC_GoTo(npcid, x, y, z, type, speed, useZMap) {
	return CallNativeGDK("FCNPC_GoTo", "ifffifi", npcid, x, y, z, type, speed, useZMap);
}

function FCNPC_Stop(npcid) {
	return CallNativeGDK("FCNPC_Stop", "i", npcid);
}

function FCNPC_IsMoving(npcid) {
	return CallNativeGDK("FCNPC_IsMoving", "i", npcid);
}

function FCNPC_AimAt(npcid, x, y, z, shoot) {
	return CallNativeGDK("FCNPC_AimAt", "ifffi", npcid, x, y, z, shoot);
}

function FCNPC_StopAim(npcid) {
	return CallNativeGDK("FCNPC_StopAim", "i", npcid);
}

function FCNPC_MeleeAttack(npcid, delay) {
	return CallNativeGDK("FCNPC_MeleeAttack", "ii", npcid, delay);
}

function FCNPC_StopAttack(npcid) {
	return CallNativeGDK("FCNPC_StopAttack", "i", npcid);
}

function FCNPC_IsAiming(npcid) {
	return CallNativeGDK("FCNPC_IsAiming", "i", npcid);
}

function FCNPC_IsShooting(npcid) {
	return CallNativeGDK("FCNPC_IsShooting", "i", npcid);
}

function FCNPC_IsReloading(npcid) {
	return CallNativeGDK("FCNPC_IsReloading", "i", npcid);
}

function FCNPC_EnterVehicle(npcid, vehicleid, seatid, type) {
	return CallNativeGDK("FCNPC_EnterVehicle", "iiii", npcid, vehicleid, seatid, type);
}

function FCNPC_ExitVehicle(npcid) {
	return CallNativeGDK("FCNPC_ExitVehicle", "i", npcid);
}

function FCNPC_PutInVehicle(npcid, vehicleid, seatid) {
	return CallNativeGDK("FCNPC_PutInVehicle", "iii", npcid, vehicleid, seatid);
}

function FCNPC_RemoveFromVehicle(npcid) {
	return CallNativeGDK("FCNPC_RemoveFromVehicle", "i", npcid);
}

function FCNPC_GetVehicleID(npcid) {
	return CallNativeGDK("FCNPC_GetVehicleID", "i", npcid);
}

function FCNPC_GetVehicleSeat(npcid) {
	return CallNativeGDK("FCNPC_GetVehicleSeat", "i", npcid);
}

function FCNPC_StartPlayingPlayback(npcid, file) {
	return CallNativeGDK("FCNPC_StartPlayingPlayback", "is", npcid, file);
}

function FCNPC_StopPlayingPlayback(npcid) {
	return CallNativeGDK("FCNPC_StopPlayingPlayback", "i", npcid);
}

function FCNPC_PausePlayingPlayback(npcid) {
	return CallNativeGDK("FCNPC_PausePlayingPlayback", "i", npcid);
}

function FCNPC_ResumePlayingPlayback(npcid) {
	return CallNativeGDK("FCNPC_ResumePlayingPlayback", "i", npcid);
}

function FCNPC_OpenNode(nodeid) {
	return CallNativeGDK("FCNPC_OpenNode", "i", nodeid);
}

function FCNPC_CloseNode(nodeid) {
	return CallNativeGDK("FCNPC_CloseNode", "i", nodeid);
}

function FCNPC_IsNodeOpen(nodeid) {
	return CallNativeGDK("FCNPC_IsNodeOpen", "i", nodeid);
}

function FCNPC_GetNodeType(nodeid) {
	return CallNativeGDK("FCNPC_GetNodeType", "i", nodeid);
}

function FCNPC_SetNodePoint(nodeid, point) {
	return CallNativeGDK("FCNPC_SetNodePoint", "ii", nodeid, point);
}

function FCNPC_GetNodePointPosition(nodeid) {
	let out = CallNativeGDK("FCNPC_GetNodePointPosition", "iFFF", npcid);
	return {x: out[0], y: out[1], z: out[2]};
}

function FCNPC_GetNodePointCount(nodeid) {
	return CallNativeGDK("FCNPC_GetNodePointCount", "i", nodeid);
}

function FCNPC_GetNodeInfo(nodeid) {
	let out = CallNativeGDK("FCNPC_GetNodeInfo", "iIII", npcid);
	return {vehnodes: out[0], pednodes: out[1], navinodes: out[2]};
}

function FCNPC_PlayNode(npcid, nodeid, type) {
	return CallNativeGDK("FCNPC_PlayNode", "iii", npcid, nodeid, type);
}

function FCNPC_StopPlayingNode(npcid) {
	return CallNativeGDK("FCNPC_StopPlayingNode", "i", nodeid);
}

function FCNPC_GetZGround(x, y) {
	return CallNativeGDK("FCNPC_GetZGround", "ffF", x, y);
}
Example.js (http://prntscr.com/8nhgsx)
Code:
const COLOR = {
	WHITE 	: 0xFFFFFFFF
};

let skittlesId = INVALID_PLAYER_ID;

let HandleServerStart = function() {
	skittlesId = FCNPC_Create("Skittles");
	return true;
}

let HandleServerStop = function() {
	if(skittlesId != INVALID_PLAYER_ID) {
		FCNPC_Destroy(skittlesId);
	}
	return true;
}

let HandlePlayerSpawn = function(player) {
	if(player.isNPC == true) {
		return true;
	}
	
	let position = player.pos;
	
	position.o = player.facingAngle;
	// Get X Y in front of player, by Y_Less, converted to JS
	position.x += (2.5 * (Math.sin(-position.o / 180 * Math.PI)));
	position.y += (2.5 * (Math.cos(-position.o / 180 * Math.PI)));
	
	FCNPC_SetPosition(skittlesId, position.x, position.y, position.z);
	
	position.o += 180;
	
	if(position.o >= 360) {
		position.o -= 360;
	}
	
	FCNPC_SetAngle(skittlesId, position.o);
	
	SendClientMessage(player.id, COLOR.WHITE, "Welcome to the server, " + player.name + "! My name is Skittles.");
	return true;
}

let HandleFCNPCCreated = function(npcid) {
	if(FCNPC_IsSpawned(npcid) == false) {
		FCNPC_Spawn(npcid, 254, 0.0, 0.0, 5.0);
	}
	
	print("NPC (" + GetPlayerName(npcid) + "): created.");
	return true;
}

let HandleFCNPCSpawned = function(npcid) {
	print("NPC (" + GetPlayerName(npcid) + "): spawned.");
	return true;
}

let HandleFCNPCDamage = function(npcid, playerid, weaponid, bodypart, loss) {
	print("NPC (" + GetPlayerName(npcid) + "): took damage (" + loss + ").");
	return true;
}

let HandleFCNPCDeath = function(npcid, playerid, weaponid) {
	print("NPC (" + GetPlayerName(npcid) + "): died.");
	
	FCNPC_Respawn(npcid);
	return true;
}

$server.on('PlayerSpawn', HandlePlayerSpawn);

$server.on('GameModeInit', HandleServerStart);
$server.on('GameModeExit', HandleServerStop);

$server.on('FCNPC_OnCreate', HandleFCNPCCreated);
$server.on('FCNPC_OnSpawn', HandleFCNPCSpawned);
$server.on('FCNPC_OnTakeDamage', HandleFCNPCDamage); // Added Edit #1
$server.on('FCNPC_OnDeath', HandleFCNPCDeath); // Added Edit #2
Not fully tested, please PM me if you get an error.
Note you must downgrade to 0.3.7 R1.
(Otherwise FCNPC will crash the server, sorry)
I am no longer using FCNPC, but I will keep this updated on request.
Reply


Messages In This Thread
samp.js - JavaScript for SA-MP - v0.1.9.4 - by !damo!spiderman - 02.07.2015, 05:38
Re: samp.js - JavaScript for SA-MP - by RuNBoY - 02.07.2015, 05:43
Re: samp.js - JavaScript for SA-MP - by ev0lution - 02.07.2015, 05:45
Re: samp.js - JavaScript for SA-MP - by Ritzy2K - 02.07.2015, 09:33
AW: samp.js - JavaScript for SA-MP - by FSAOskar - 02.07.2015, 11:54
Re: AW: samp.js - JavaScript for SA-MP - by !damo!spiderman - 02.07.2015, 12:20
Re: samp.js - JavaScript for SA-MP - by theYiin - 02.07.2015, 12:30
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 02.07.2015, 12:34
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 02.07.2015, 12:56
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 02.07.2015, 13:17
Re: samp.js - JavaScript for SA-MP - by ev0lution - 03.07.2015, 05:50
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 03.07.2015, 14:54
Respuesta: samp.js - JavaScript for SA-MP - by [DOG]irinel1996 - 03.07.2015, 16:01
Re: samp.js - JavaScript for SA-MP - by BonhommeG - 03.07.2015, 16:23
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 03.07.2015, 16:43
Re: samp.js - JavaScript for SA-MP - by ev0lution - 04.07.2015, 00:56
Re: samp.js - JavaScript for SA-MP - by ev0lution - 04.07.2015, 08:43
Re: samp.js - JavaScript for SA-MP - by Crayder - 04.07.2015, 08:54
Re: samp.js - JavaScript for SA-MP - by BonhommeG - 04.07.2015, 12:06
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 04.07.2015, 12:10
Re: samp.js - JavaScript for SA-MP - by BonhommeG - 04.07.2015, 12:38
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 04.07.2015, 12:45
Re: samp.js - JavaScript for SA-MP - by GWMPT - 04.07.2015, 12:46
Re: samp.js - JavaScript for SA-MP - by BonhommeG - 04.07.2015, 13:02
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 04.07.2015, 13:06
Re: samp.js - JavaScript for SA-MP - by prineside - 05.07.2015, 10:38
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 05.07.2015, 14:13
Re: samp.js - JavaScript for SA-MP - by Kapersky™ - 05.07.2015, 15:02
Re: samp.js - JavaScript for SA-MP - by PeterJane - 05.07.2015, 19:47
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 05.07.2015, 23:37
Re: samp.js - JavaScript for SA-MP - by PeterJane - 06.07.2015, 13:15
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 11.07.2015, 04:37
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 12.07.2015, 15:08
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 13.07.2015, 05:28
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 15.07.2015, 02:19
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 16.07.2015, 10:18
Re: samp.js - JavaScript for SA-MP - by KayJ - 16.07.2015, 13:05
Re: samp.js - JavaScript for SA-MP - by iFrame - 16.07.2015, 14:41
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 20.07.2015, 15:19
Re: samp.js - JavaScript for SA-MP - by Laronic - 22.07.2015, 23:18
Re: samp.js - JavaScript for SA-MP - by Crayder - 22.07.2015, 23:38
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 23.07.2015, 01:27
Re: samp.js - JavaScript for SA-MP - by benel1 - 26.07.2015, 14:19
Re: samp.js - JavaScript for SA-MP - by BlackBank - 26.07.2015, 17:03
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 26.07.2015, 18:24
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 26.07.2015, 18:26
Re: samp.js - JavaScript for SA-MP - by Laronic - 04.08.2015, 17:25
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 05.08.2015, 12:28
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 05.08.2015, 13:27
Re: samp.js - JavaScript for SA-MP - by Lorenc_ - 05.08.2015, 14:13
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 05.08.2015, 19:08
Re: samp.js - JavaScript for SA-MP - by Battlezone - 24.08.2015, 19:03
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 25.08.2015, 05:15
Re: samp.js - JavaScript for SA-MP - by ev0lution - 25.08.2015, 05:18
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 25.08.2015, 05:21
Re: samp.js - JavaScript for SA-MP - by prineside - 05.09.2015, 21:06
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 06.09.2015, 08:59
Re: samp.js - JavaScript for SA-MP - by ChromeAmazing - 06.09.2015, 21:42
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 12.09.2015, 18:12
Re: samp.js - JavaScript for SA-MP - by j0n - 17.09.2015, 17:12
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 17.09.2015, 17:37
Re: samp.js - JavaScript for SA-MP - by HardWar - 17.09.2015, 18:49
Re: samp.js - JavaScript for SA-MP - by Kamper - 17.09.2015, 22:54
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 18.09.2015, 08:07
Re: samp.js - JavaScript for SA-MP - by Mowgli - 18.09.2015, 08:36
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 18.09.2015, 10:28
Re: samp.js - JavaScript for SA-MP - by HardWar - 18.09.2015, 16:40
Re: samp.js - JavaScript for SA-MP - by !damo!spiderman - 19.09.2015, 07:59
Re: samp.js - JavaScript for SA-MP - by Kamper - 19.09.2015, 11:38
Re: samp.js - JavaScript for SA-MP - by Omer. - 22.09.2015, 20:45
Re: samp.js - JavaScript for SA-MP - by DRIFT_HUNTER - 23.09.2015, 18:11
Re: samp.js - JavaScript for SA-MP - by Omer. - 23.09.2015, 18:56
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 29.09.2015, 01:44
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 04.10.2015, 01:37
Re: samp.js - JavaScript for SA-MP - by Abagail - 04.10.2015, 03:10
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 04.10.2015, 03:46
Re: samp.js - JavaScript for SA-MP - by Omer. - 27.10.2015, 07:50
Re: samp.js - JavaScript for SA-MP - by SkittlesAreFalling - 28.10.2015, 00:14
Re: samp.js - JavaScript for SA-MP - by Omer. - 28.10.2015, 04:08
Re: samp.js - JavaScript for SA-MP - by Anarkien - 19.06.2016, 08:54
Re: samp.js - JavaScript for SA-MP - by CoaPsyFactor - 20.06.2016, 16:56
Re: samp.js - JavaScript for SA-MP - by Pyrotech - 10.10.2016, 00:05
Re: samp.js - JavaScript for SA-MP - by CoaPsyFactor - 13.10.2016, 13:08
Re: samp.js - JavaScript for SA-MP - by Yaa - 23.11.2016, 12:02
Re: samp.js - JavaScript for SA-MP - by LifeIsGood - 24.11.2016, 07:37
Re: samp.js - JavaScript for SA-MP - by Yaa - 24.11.2016, 12:58
Re: samp.js - JavaScript for SA-MP - by lepegadore - 16.01.2017, 11:45
Re: samp.js - JavaScript for SA-MP - by Omer. - 12.02.2017, 12:02
Re: samp.js - JavaScript for SA-MP - by PhamHoang - 14.07.2017, 06:32
Re: samp.js - JavaScript for SA-MP - by NekoriDes - 02.12.2017, 22:26
Re: samp.js - JavaScript for SA-MP - by Kaperstone - 03.12.2017, 04:57
Re: samp.js - JavaScript for SA-MP - by LifeIsGood - 03.12.2017, 05:06
Re: samp.js - JavaScript for SA-MP - by Kaperstone - 03.12.2017, 05:58

Forum Jump:


Users browsing this thread: 3 Guest(s)