SA-MP Forums Archive
PHP scripting support for SAMP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: PHP scripting support for SAMP (/showthread.php?tid=356376)

Pages: 1 2


PHP scripting support for SAMP - rfksna - 03.07.2012

So yeah.. as title says.. you can make your own gamemodes in PHP

I was thinking that maybe someone here might want this so i posted it.

The build may have some bugs as it is untested.

Currently supported functions are the ones from:
a_samp.inc (0.3e)
a_players.inc (0.3e)
a_vehicles.inc (0.3e)
a_objects.inc (0.3e)

- MySQL is enabled in PHP. You can use these functions http://www.php.net/manual/en/ref.mysql.php
- Added $_SAMP superglobal variable. An example is that you can store the players info in $_SAMP['players'][].. and you don't need to declare it as global in each function or callback that you want to use.


So how does it work?
* This is basically a plugin (plugins\phsamp.dll) that uses php (php5ts.dll) and its extension (php_plugin.dll) to call functions from samp.
* The archive contains a folder "_phps" and the main script that gets executed when you start the server is "nxmain.php"
* Logs are saved in "_phps/php_errors.log" but you can change that in php.ini
* When creating gamemodes you do not need to restart the server or reload the filterscript. You can just type "/rr" and the php will be reloaded (_phps/nxmain.php). Look into the filterscript source for more details.

Download for PHSAMP

Download for PHSAMP source

Notice that this is the first thing that i ever done in c++, so please excuse me for my bad c++ code


Re: PHP scripting support for SAMP - Niko_boy - 03.07.2012

any examples
Nice idea and though , may be this help ppl to learn php easily :P [not really]


Re: PHP scripting support for SAMP - rfksna - 03.07.2012

You have an example _phps folder. look in nxmain.php and see how it works


Re: PHP scripting support for SAMP - Roperr - 03.07.2012

Can you give us some examples of what we could do with this? Anything new and extraordinary?


Respuesta: Re: PHP scripting support for SAMP - [DOG]irinel1996 - 03.07.2012

Quote:
Originally Posted by Roperr
View Post
Can you give us some examples of what we could do with this? Anything new and extraordinary?
Probably you'll be able to use SA-MP functions in php websites.


Re: PHP scripting support for SAMP - rfksna - 03.07.2012

Quote:
Originally Posted by Y_Less
View Post
You need to include the plugin source code to release here I'm afraid, but it looks like a nice start.
Source code added.


Re: PHP scripting support for SAMP - next-studio|TheKiller - 03.07.2012

A friend of mine already created a lua plugin, so he can transfer lua for sa-mp without problems, now it's php, well, sa-mp is on a good way!


I would be doing a mysql class for it after my one done, which you can connect into mysql server, if the mysql pass, user or host refused the connection, the server isn't going to crash.


Re: PHP scripting support for SAMP - next-studio|TheKiller - 05.07.2012

Sorry for bumping,
I've took a look on the source code, but it's missing some files, if you try to compile, it outputs a error from the file: phpx.h.
Take a look on it, thanks!


Re: PHP scripting support for SAMP - CoaPsyFactor - 06.07.2012

You wanna marry me ... This is awesome!!!! Now I'll create some gamemodes with this, and give you HUGE credits !!!!


Re: PHP scripting support for SAMP - rfksna - 08.07.2012

Quote:
Originally Posted by next-studio|TheKiller
View Post
Sorry for bumping,
I've took a look on the source code, but it's missing some files, if you try to compile, it outputs a error from the file: phpx.h.
Take a look on it, thanks!
Hello,

In order to get the plugin compiled it is required that you first download the php source code from here http://php.net/downloads.php.


Also note that i've updated the server files. Fixed some small bugs.


Re: PHP scripting support for SAMP - Rg-Gaming.Info - 08.07.2012

Awesome !!!! So we can basicly use all stuff and convert it to PHP AWESOME ! Im pro at PHP ill make awesome gamemodes. !


Re: PHP scripting support for SAMP - rfksna - 08.07.2012

Yes. Here is an example taken from nxmain.php

PHP Code:
if($cmd[0] == '/setskin'){
    
$skinid = (int)$cmd[1];
    
SetPlayerSkin($playerid$skinid);
    
SendClientMessage($playeridCOLOR_BLUE" * Skin changed!");




Re: PHP scripting support for SAMP - next-studio|TheKiller - 08.07.2012

Most likely, we can connect into remote servers, take the data for the server, and manage it there, without a problem.

I will be taking a look on the source code, and reporting some bugs which are found there(well, the first bug is on the $name variable, which show's alot of "stupid" chars with the name)


Re: PHP scripting support for SAMP - rfksna - 08.07.2012

I know that bug. It was fixed. You need to update php_plugin.dll and plugins/phsamp.dll


Re : PHP scripting support for SAMP - Eony - 13.08.2012

How is the development of this going?


Re: PHP scripting support for SAMP - wups - 13.08.2012

Holy cow. You don't need to compile PHP, that means you can edit the game mode without any restarts!


Re : Re: PHP scripting support for SAMP - scott1 - 13.08.2012

Quote:
Originally Posted by Y_Less
View Post
You would still need to restart it because the script will be loaded in to memory, all it skips is the compilation phase.
So if there are some errors, like { missing,

we wont get error, but in game, the server will crash?

Max


Re : Re: PHP scripting support for SAMP - Eony - 14.08.2012

Quote:
Originally Posted by wups
View Post
Holy cow. You don't need to compile PHP, that means you can edit the game mode without any restarts!
You actually do need to restart (/rr), just not a whole GMX but still a restart.

Quote:
Originally Posted by scott1
View Post
So if there are some errors, like { missing,

we wont get error, but in game, the server will crash?

Max
No, nothing will happen but you will get an error in the console / logs, so don't forget to check that often


Re: PHP scripting support for SAMP - Steven82 - 14.08.2012

Quote:
Originally Posted by Rg-Gaming.Info
View Post
Awesome !!!! So we can basicly use all stuff and convert it to PHP AWESOME ! Im pro at PHP ill make awesome gamemodes. !
How will you be a pro?

From my understanding you're still using SA-MP syntax. Just because you're good at PHP doesn't mean you're going to be able to make the next GamerX server with PHP now.


Re : Re: PHP scripting support for SAMP - Eony - 14.08.2012

Quote:
Originally Posted by Steven82
View Post
How will you be a pro?

From my understanding you're still using SA-MP syntax. Just because you're good at PHP doesn't mean you're going to be able to make the next GamerX server with PHP now.
No, you're using the PHP syntax with this. You do all the data processing like you normally would in PHP, then you call SA-MP functions providing that data. That said, you still have to know what each SA-MP functions do, what they return, and so forth.

For example, you could do ..

Code:
define('COLOR_BLUE', 0x0000FFAA);
$string = "Hello:this:is:jack";
$string = explode(':', $string)

SendClientMessage($playerid, COLOR_BLUE, " $string[3]);
That would display "jack". explode() does not exist in PAWN, you can have something similar to this in PAWN but you would have to use sscanf or a premade split function.

You're simply calling SA-MP functions using PHP code syntax and semantics.