17.09.2015, 17:37
[Plugin] samp.js - JavaScript for SA-MP
17.09.2015, 18:49
You forgot the dialogid argument in showDialog function, look.
it should be:
and how to escape the string for use in SQLite functions? in pawn I use format and %q
it should be:
PHP код:
return ShowPlayerDialog(this.id, dialogid, style, caption, info, button1, button2);
17.09.2015, 22:54
(
Последний раз редактировалось Kamper; 18.09.2015 в 03:01.
)
Is it possible create a global variable to be accessible from another JS files? A kind of global variable accessible from any file
#edit
I figured out that I can simply use include function to load some JS file with a global variable xD
#another question
Can I assign a value to a new attribute of player's object, eg player.test = 1, that when the player disconnect this object will be cleared?
I noticed that when you use the function GameModeExit to reload the server, the changes made in source don't have any effect in the server until you close/open it again. It's quite bother...
#edit
I figured out that I can simply use include function to load some JS file with a global variable xD
#another question
Can I assign a value to a new attribute of player's object, eg player.test = 1, that when the player disconnect this object will be cleared?
I noticed that when you use the function GameModeExit to reload the server, the changes made in source don't have any effect in the server until you close/open it again. It's quite bother...
18.09.2015, 08:07
(
Последний раз редактировалось SkittlesAreFalling; 18.09.2015 в 10:37.
)
Quote:
and how to escape the string for use in SQLite functions? in pawn I use format and %q
|
Код:
var mysql_escape_string = function(str) { return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) { switch (char) { case "\0": return "\\0"; case "\x08": return "\\b"; case "\x09": return "\\t"; case "\x1a": return "\\z"; case "\n": return "\\n"; case "\r": return "\\r"; case "\"": case "'": case "\\": case "%": return "\\"+char; // prepends a backslash to backslash, percent, // and double/single quotes } }); } String.format = function(str, arr) { var i = -1; var callback; callback = function(exp, p0, p1, p2, p3, p4) { if(exp=='%%') { return '%'; } if(arr[++i] === undefined) { return undefined; } var exp = p2 ? parseInt(p2.substr(1)) : undefined; var base = p3 ? parseInt(p3.substr(1)) : undefined; var val; switch(p4) { case 's': val = arr[i]; break; case 'c': val = arr[i][0]; break; case 'i': val = arr[i].toString(); break; case 'd': val = arr[i].toString(); break; case 'f': val = parseFloat(arr[i]).toFixed(exp); break; case 'p': val = parseFloat(arr[i]).toPrecision(exp); break; case 'e': val = parseFloat(arr[i]).toExponential(exp); break; case 'x': val = parseInt(arr[i]).toString(base?base:16); break; case 'd': val = parseFloat(parseInt(arr[i], base?base:10).toPrecision(exp)).toFixed(0); break; case 'q': val = mysql_escape_string(arr[i]); break; } val = (typeof(val) == 'object') ? JSON.stringify(val) : val.toString(base); var sz = parseInt(p1); /* padding size */ var ch = p1 && p1[0]=='0' ? '0' : ' '; /* isnull? */ while(val.length<sz) { val = p0 !== undefined ? val+ch : ch+val; /* isminus? */ } return val; } var regex = /%(-)?(0?[0-9]+)?([.][0-9]+)?([#][0-9]+)?([scfpexd])/g; return str.replace(regex, callback); } String.prototype.format = function() { return String.format(this, Array.prototype.slice.call(arguments)); }
Example:
Код:
const COLOR = { WHITE : 0xFFFFFFFF, TEAL : 0x008080FF }; SendClientMessage(player.id, COLOR.WHITE, ("Welcome to {%06x}%s{%06x}, {%06x}%s{%06x}!").format((COLOR.TEAL >>> 8), ServerData.name, (COLOR.WHITE >>> 8), (COLOR.TEAL >>> 8), player.name, (COLOR.WHITE >>> 8)));
18.09.2015, 08:36
Interesting.
18.09.2015, 10:28
(
Последний раз редактировалось SkittlesAreFalling; 26.09.2015 в 19:45.
)
Quote:
Is it possible create a global variable to be accessible from another JS files? A kind of global variable accessible from any file
#edit I figured out that I can simply use include function to load some JS file with a global variable xD #another question Can I assign a value to a new attribute of player's object, eg player.test = 1, that when the player disconnect this object will be cleared? I noticed that when you use the function GameModeExit to reload the server, the changes made in source don't have any effect in the server until you close/open it again. It's quite bother... |
Код:
include("js/SomeFunction.js"); // Includes all global variables from the path into the script. SomeFunction();
Код:
var script = require("js/SomeFunction.js"); // Includes all exported variables into the script. script.SomeFunction();
Код:
var SomeFunction = function() { print("This is some function"); } exports = { SomeFunction : SomeFunction }
Use a global variable instead:
var PlayerData = [];
//PlayerConnect
PlayerData[player.id] = {};
PlayerData[player.id].test = 1;
//PlayerDisconnect
PlayerData[player.id] = null; // Or if you want it to free up memory do: delete PlayerData[player.id];
18.09.2015, 16:40
Quote:
You'll be interested in:
~code~ works similar to SAMP's format function. [https://sampwiki.blast.hk/wiki/Format] Example: ~code~ ^ copy&paste from my code. |
19.09.2015, 07:59
Quote:
#another question
Can I assign a value to a new attribute of player's object, eg player.test = 1, that when the player disconnect this object will be cleared? I noticed that when you use the function GameModeExit to reload the server, the changes made in source don't have any effect in the server until you close/open it again. It's quite bother... |
You can put reload('scriptname.js'); in the GameModeExit and it will reload the javascript file
19.09.2015, 11:38
Great! For me that is the best plugin ever in SA-MP! I hope you keep working on it! I'm creating a great project using SAMP.js and build some includes to contributing to it
22.09.2015, 20:45
(
Last edited by Omer.; 22/10/2015 at 06:44 PM.
)
WOW! this is great! I've just started to new script with your plugin, had same problem with non-english characters
saved .js file with encoding utf-8
result:
saved .js file with encoding utf-8
Code:
$server.on("ScriptInit", function() { setlocale("Turkish"); // this only works on console }
Code:
23.09.2015, 18:11
Quote:
WOW! this is great! I've just started to new script with your plugin, had same problem with non-english characters
saved .js file with encoding utf-8 Code:
$server.on("ScriptInit", function() { setlocale("Turkish"); Code:
player.message("з З ğ Ğ ı İ ц Ц ş Ş ь Ь"); |
23.09.2015, 18:56
(
Last edited by Omer.; 23/09/2015 at 10:34 PM.
)
29.09.2015, 01:44
md5.js
Usage:
http://md5.gromweb.com/?md5=86fb269d...e0468ceca42a20
PLEASE:
Do not use this to store user passwords.
Code:
!function(a){"use strict";function b(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c}function c(a,b){return a<<b|a>>>32-b}function d(a,d,e,f,g,h){return b(c(b(b(d,a),b(f,h)),g),e)}function e(a,b,c,e,f,g,h){return d(b&c|~b&e,a,b,f,g,h)}function f(a,b,c,e,f,g,h){return d(b&e|c&~e,a,b,f,g,h)}function g(a,b,c,e,f,g,h){return d(b^c^e,a,b,f,g,h)}function h(a,b,c,e,f,g,h){return d(c^(b|~e),a,b,f,g,h)}function i(a,c){a[c>>5]|=128<<c%32,a[(c+64>>>9<<4)+14]=c;var d,i,j,k,l,m=1732584193,n=-271733879,o=-1732584194,p=271733878;for(d=0;d<a.length;d+=16)i=m,j=n,k=o,l=p,m=e(m,n,o,p,a[d],7,-680876936),p=e(p,m,n,o,a[d+1],12,-389564586),o=e(o,p,m,n,a[d+2],17,606105819),n=e(n,o,p,m,a[d+3],22,-1044525330),m=e(m,n,o,p,a[d+4],7,-176418897),p=e(p,m,n,o,a[d+5],12,1200080426),o=e(o,p,m,n,a[d+6],17,-1473231341),n=e(n,o,p,m,a[d+7],22,-45705983),m=e(m,n,o,p,a[d+8],7,1770035416),p=e(p,m,n,o,a[d+9],12,-1958414417),o=e(o,p,m,n,a[d+10],17,-42063),n=e(n,o,p,m,a[d+11],22,-1990404162),m=e(m,n,o,p,a[d+12],7,1804603682),p=e(p,m,n,o,a[d+13],12,-40341101),o=e(o,p,m,n,a[d+14],17,-1502002290),n=e(n,o,p,m,a[d+15],22,1236535329),m=f(m,n,o,p,a[d+1],5,-165796510),p=f(p,m,n,o,a[d+6],9,-1069501632),o=f(o,p,m,n,a[d+11],14,643717713),n=f(n,o,p,m,a[d],20,-373897302),m=f(m,n,o,p,a[d+5],5,-701558691),p=f(p,m,n,o,a[d+10],9,38016083),o=f(o,p,m,n,a[d+15],14,-660478335),n=f(n,o,p,m,a[d+4],20,-405537848),m=f(m,n,o,p,a[d+9],5,568446438),p=f(p,m,n,o,a[d+14],9,-1019803690),o=f(o,p,m,n,a[d+3],14,-187363961),n=f(n,o,p,m,a[d+8],20,1163531501),m=f(m,n,o,p,a[d+13],5,-1444681467),p=f(p,m,n,o,a[d+2],9,-51403784),o=f(o,p,m,n,a[d+7],14,1735328473),n=f(n,o,p,m,a[d+12],20,-1926607734),m=g(m,n,o,p,a[d+5],4,-378558),p=g(p,m,n,o,a[d+8],11,-2022574463),o=g(o,p,m,n,a[d+11],16,1839030562),n=g(n,o,p,m,a[d+14],23,-35309556),m=g(m,n,o,p,a[d+1],4,-1530992060),p=g(p,m,n,o,a[d+4],11,1272893353),o=g(o,p,m,n,a[d+7],16,-155497632),n=g(n,o,p,m,a[d+10],23,-1094730640),m=g(m,n,o,p,a[d+13],4,681279174),p=g(p,m,n,o,a[d],11,-358537222),o=g(o,p,m,n,a[d+3],16,-722521979),n=g(n,o,p,m,a[d+6],23,76029189),m=g(m,n,o,p,a[d+9],4,-640364487),p=g(p,m,n,o,a[d+12],11,-421815835),o=g(o,p,m,n,a[d+15],16,530742520),n=g(n,o,p,m,a[d+2],23,-995338651),m=h(m,n,o,p,a[d],6,-198630844),p=h(p,m,n,o,a[d+7],10,1126891415),o=h(o,p,m,n,a[d+14],15,-1416354905),n=h(n,o,p,m,a[d+5],21,-57434055),m=h(m,n,o,p,a[d+12],6,1700485571),p=h(p,m,n,o,a[d+3],10,-1894986606),o=h(o,p,m,n,a[d+10],15,-1051523),n=h(n,o,p,m,a[d+1],21,-2054922799),m=h(m,n,o,p,a[d+8],6,1873313359),p=h(p,m,n,o,a[d+15],10,-30611744),o=h(o,p,m,n,a[d+6],15,-1560198380),n=h(n,o,p,m,a[d+13],21,1309151649),m=h(m,n,o,p,a[d+4],6,-145523070),p=h(p,m,n,o,a[d+11],10,-1120210379),o=h(o,p,m,n,a[d+2],15,718787259),n=h(n,o,p,m,a[d+9],21,-343485551),m=b(m,i),n=b(n,j),o=b(o,k),p=b(p,l);return[m,n,o,p]}function j(a){var b,c="";for(b=0;b<32*a.length;b+=8)c+=String.fromCharCode(a[b>>5]>>>b%32&255);return c}function k(a){var b,c=[];for(c[(a.length>>2)-1]=void 0,b=0;b<c.length;b+=1)c[b]=0;for(b=0;b<8*a.length;b+=8)c[b>>5]|=(255&a.charCodeAt(b/8))<<b%32;return c}function l(a){return j(i(k(a),8*a.length))}function m(a,b){var c,d,e=k(a),f=[],g=[];for(f[15]=g[15]=void 0,e.length>16&&(e=i(e,8*a.length)),c=0;16>c;c+=1)f[c]=909522486^e[c],g[c]=1549556828^e[c];return d=i(f.concat(k(b)),512+8*b.length),j(i(g.concat(d),640))}function n(a){var b,c,d="0123456789abcdef",e="";for(c=0;c<a.length;c+=1)b=a.charCodeAt©,e+=d.charAt(b>>>4&15)+d.charAt(15&b);return e}function o(a){return unescape(encodeURIComponent(a))}function p(a){return l(o(a))}function q(a){return n(p(a))}function r(a,b){return m(o(a),o(b))}function s(a,b){return n(r(a,b))}function t(a,b,c){return b?c?r(b,a):s(b,a):c?p(a):q(a)}"function"==typeof define&&define.amd?define(function(){return t}):a.md5=t}(this);
Code:
md5("Hello world!"); // 86fb269d190d2c85f6e0468ceca42a20
PLEASE:
Do not use this to store user passwords.
04.10.2015, 01:37
(
Last edited by SkittlesAreFalling; 06/11/2015 at 07:54 AM.
)
FCNPC.inc.js (https://sampforum.blast.hk/showthread.php?tid=428066)
Example.js (http://prntscr.com/8nhgsx)
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.
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
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.
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) |
04.10.2015, 03:46
27.10.2015, 07:50
here some utils:
example usage for ReturnUser:
Code:
var IsNumeric = function(input) { return (input - 0) == input && (''+input).trim().length > 0; };
Code:
var ReturnUser = function(text) { if(IsNumeric(text)) { return $players[text]; } else { let found = []; for(let player of $players) { if(player.name.indexOf(text) != -1) { found.push(player); } } return found.length == 1 ? found[0] : found; } };
Code:
$server.on("PlayerCommandText", function(player, text){ let args = text.split(' '); let cmd = args.shift(); switch(cmd) { case '/pm': { if(isNaN(args[0])){ SendClientMessage( player, -1, "/pm [playerid/Part of Name] [message]"); return 1; } let arg1 = args.shift(); let target = ReturnUser(arg1); if(!target) { return player.message(-1, "Couldn't find " + arg1); } if(Array.isArray(target)) { return player.message(-1, "Found matches: " + _.pluck(target, "id").join(", ")); // include underscore.js } msg = args.join(' '); SendClientMessage(target.id, -1, `PM from ${player.name}: ${msg}`); return 1; } } return 0; });
28.10.2015, 00:14
Quote:
Code:
var IsNumeric = function(input) { return (input - 0) == input && (''+input).trim().length > 0; }; |
You can simply:
Code:
var IsNumeric = function(test) { return (isNaN(parseFloat(test)) == false && isFinite(test) == true); }
Quote:
print([ IsNumeric("test"), IsNumeric(true), IsNumeric("69"), IsNumeric("19.94") ]); // { 0: false, 1: false, 2: true, 3: true } |
28.10.2015, 04:08
(
Last edited by Omer.; 28/10/2015 at 04:37 PM.
)
isFinite is nice, but my function works well with floats too
19.06.2016, 08:54
Will development continue for this plugin, or is it in a somewhat stable state?
« Next Oldest | Next Newest »
Users browsing this thread: 7 Guest(s)