PHP scripting support for SAMP
#1

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
Reply
#2

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

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

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

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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!
Reply
#9

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

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.
Reply
#11

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

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!");

Reply
#13

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)
Reply
#14

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

How is the development of this going?
Reply
#16

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

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
Reply
#18

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
Reply
#19

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.
Reply
#20

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)