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

samp.js is a plugin which allows you to create scripts in JavaScript for SA-MP.

It is currently in Alpha mainly due to the amount of changes I do every day which are not fully tested or complete. It is however being used on live servers without any issues.

Features:
  • JavaScript - Easy to use dynamic language
  • Runs on the fast V8 JavaScript Engine - The same engine powering Chrome/Chromium and Node.js
  • Async/Threaded Sockets library ( example Irc bot class included )
  • MySQL library *NEW*. Easy to use Async(threaded) MySQL implementation
  • Player wrapper class ( Vehicle, Objects, Dialog, TextDraw etc classes to come )
  • New ES6 JavaScript features including classes, block scope variables and template strings
  • Modules
  • Advanced Event loop
Due to focusing on implementing features and fixing bugs the current documentation is lacking in some places but I am more than happy to supply examples and help for anything you request.

Due to the high system requirements for compiling ( thanks to V8 ) and lack of complete instructions and makefiles/project files I highly recommend testing using the binaries supplied, until I make working instructions available.

All pawn functions have been automatically recreated in JavaScript, with the syntax basically the same except for when referenced variables are involved.

Most plugins can also be used within samp.js, a special nodejs converter script can be ran which will convert all the plugins functions into JavaScript functions.

Example Script:

PHP Code:
$server.on("ScriptInit", function(){
      
// Create a timer which runs once a minute infinitely
     
SetTimer(function(){
           
// loop through all players
           
for(let player of $players){
                
player.health-=0.1;
           }
     }, 
60000, -);
});
$server.on("GameModeInit", function(){
    print(
"Game Mode Started");
});
$server.on("PlayerSpawn", function(player){
     
// Get players position - let is a local var
     
let pos player.pos;
     
// Create a new vehicle at the players position
     
let vehid CreateVehicle(522pos.x+1pos.ypos.zpos.a, -1,-1,0);
     
// Put the player in the vehicle we just created
     
player.vehicle vehid;
});
$server.on("PlayerCommandText", function(playertext){
       
let args text.split(' ');
       
let cmd args.shift();
       
let msg args.join(' ');
       switch(
cmd){
            case 
'/pm':
             {
                  if(
isNaN(args[0])){
                      
SendClientMessageplayer, -1"/pm [playerid] [message]");
                      return 
1;  
                  } 
                  
                   
let id args.shift();
                   
msg args.join(' ');
                   
SendClientMessage(id,0x00FF00F, `PM from ${player.name}${msg}`);
                   return 
1;
             }
             
       }
       return 
0;
       
}); 
MySQL Example

I will provide more examples as I go

You can find me in #samp.js on the irc.tl network

GitHub Page

API Documentation


Latest Release
Latest Release - Linux
Latest Release - Windows

Streamer Plugin Support with Callbacks
https://github.com/damospiderman/sam...ugins/streamer

Streamer Callback example
PHP Code:
$server.on("DynamicObjectMoved", function(objectid){
});
$server.on("PlayerEditDynamicObject", function(playerobjectidresponsex,y,z,rx,ry,rz){
}); 
Special Thanks
ev0lution - Testing, Scripts, emotional support


Laronic - Bug finding and code additions


andievandy - Bug finding and code additions
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: 12 Guest(s)