SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 02/07/2015, 06:38 AM   #1
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 469
Reputation: 147
Default samp.js - JavaScript for SA-MP - v0.1.9.4


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
__________________

Last edited by !damo!spiderman; 19/08/2015 at 06:01 AM.
!damo!spiderman is offline   Reply With Quote
Old 02/07/2015, 06:43 AM   #2
RuNBoY
Big Clucker
 
Join Date: Dec 2013
Posts: 115
Reputation: 8
Default Re: samp.js - JavaScript for SA-MP

good
RuNBoY is offline   Reply With Quote
Old 02/07/2015, 06:45 AM   #3
ev0lution
Gangsta
 
ev0lution's Avatar
 
Join Date: Jul 2009
Posts: 700
Reputation: 373
Default Re: samp.js - JavaScript for SA-MP

This is the greatest thing to happen to SA-MP since SA-MP.

I've been running my server using samp.js for over a month now, and it was seriously so easy to develop with JS. RIP pawn.
__________________
ev0lution is offline   Reply With Quote
Old 02/07/2015, 09:21 AM   #4
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,710
Reputation: 1255
Default Re: samp.js - JavaScript for SA-MP

Awesome. I might write puzzles and extensions with this and leave the groundwork type code in Pawn, thank you for blessing this upon us!
[HLF]Southclaw is offline   Reply With Quote
Old 02/07/2015, 10:33 AM   #5
Ritzy
High-roller
 
Ritzy's Avatar
 
Join Date: Jun 2014
Location: GPS failed.
Posts: 1,446
Reputation: 104
Default Re: samp.js - JavaScript for SA-MP

Nice job! SA-MP's scripting available in so many languages now <3
Ritzy is online now   Reply With Quote
Old 02/07/2015, 12:54 PM   #6
FSAOskar
Big Clucker
 
Join Date: Feb 2015
Location: Germany
Posts: 94
Reputation: 22
Default AW: samp.js - JavaScript for SA-MP

Nice, I've been waiting for this so long. Are you planning to constantly update this or is it just like a test ?
Also could you please add some benchmarks ?
FSAOskar is offline   Reply With Quote
Old 02/07/2015, 01:20 PM   #7
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 469
Reputation: 147
Default Re: AW: samp.js - JavaScript for SA-MP

Quote:
Originally Posted by FSAOskar View Post
Nice, I've been waiting for this so long. Are you planning to constantly update this or is it just like a test ?
Also could you please add some benchmarks ?
I've been working on it for over a month, I plan to keep on updating it

Will add benchmarks, but benchmarks aren't really a good way of measuring speed of an entire program. It's fast in most places slower in calling Native pawn functions
__________________
!damo!spiderman is offline   Reply With Quote
Old 02/07/2015, 01:30 PM   #8
theYiin
Big Clucker
 
theYiin's Avatar
 
Join Date: Aug 2013
Location: Lithuania
Posts: 110
Reputation: 53
Default Re: samp.js - JavaScript for SA-MP

Is it possible to hook callbacks? Are you planning to add command processor?
Quote:
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.
More information about plugin support would be awesome.

Looking forward to this plugin, js is amazing, so are you
theYiin is offline   Reply With Quote
Old 02/07/2015, 01:34 PM   #9
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,093
Reputation: 130
Default Re: samp.js - JavaScript for SA-MP

These is second best thing after ColAndreas. Just hope it wont end up as samphp plugin. Dont forget to support important plugins like Streamer and ColAndreas (Both natives and callbacks/events)

Gonna try it out soon...Just imagine OOP and dynamically sized arrays in samp...
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 02/07/2015, 01:56 PM   #10
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 469
Reputation: 147
Default Re: samp.js - JavaScript for SA-MP

Quote:
Originally Posted by theYiin View Post
Is it possible to hook callbacks? Are you planning to add command processor?
More information about plugin support would be awesome.

Looking forward to this plugin, js is amazing, so are you
Callbacks are a bit tricky... I will try and work out a nice way to incorporate them... There are functions so you can call javascript from pawn so you could do it in a round about way currently.
__________________
!damo!spiderman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript. Banditukas Everything and Nothing 18 04/04/2015 06:00 PM
[Pedido] botão: script/ HTML/ JAVASCRIPT | SAMP FOLDER/FILE MestreSmart Português/Portuguese 6 28/02/2015 06:16 PM
Use PHP in javascript Banditukas Everything and Nothing 5 08/11/2014 06:44 AM
javascript samp:// [Ger]Little_Grandpa Help Archive 6 21/08/2010 07:24 PM


All times are GMT. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.