04.10.2015, 03:10
Quote:
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); } 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 (Otherwise FCNPC will crash the server, sorry) |