31.10.2014, 21:20
(
Последний раз редактировалось Capua; 01.11.2014 в 14:46.
)
Introduction
This tutorial covers up how to load object from MySQL (fast solution) instead of from scriptfiles or your gamemode.
Note: If you haven't set up your MySQL and Apache server yet, take a U-turn and find your way to MySQL tutorials. This tutorial is not aimed at persons with poor knowledge of MySQL.
What is required?
Let's get started!
We'll add this to the top of our gamemode script:
I assume you have "mySQL_init();" inside OnGameModeInit, so under mySQL_init line add the following:
Then the biggest part:
Halfway through! Coding in your gamemode part is finished and you can compile.
Next step is to create a SQL table. It can be done with notepad etc etc, but I use Pawno.
So here's the code:
Change "changeme" to whatever your database name is.
I've used 2 objects as example on how to place them in the code.
Now save the file as "objects.sql" and import it from phpMyAdmin into your already existing database. A new table named "objects" will appear in your database, inside "objects" there will be those 2 example objects, unless you changed them.
Congratulations! You have fully set up a fully functioning table for dynamic objects!
A tip:
If you have much objects you'd like to add, it would be time consuming to add them one by one. So copy & paste your object code, for example: CreateDynamicObject(14407, 1121.00830, -1194.85254, 27.83070, 0.00000, 0.00000, 90.26003); - then simply (if you use Pawno) press CTRL + H. First we need to replace CreateDynamicObject with nothing, so leave "Replace with:" empty. That was fast. Now for the part on the right, you could fully remove the "Comment" value to save time, or just suffer a bit and start editing with Replace function. I would do it like this: Replace ); with ), 'changeme'), - REMEMBER, the last line must have a semicolon in the end, every other object line has just a comma ( , ) in the ending.
Credits goes to [HiC]TheKiller for his in-game Object Maker
This tutorial covers up how to load object from MySQL (fast solution) instead of from scriptfiles or your gamemode.
Note: If you haven't set up your MySQL and Apache server yet, take a U-turn and find your way to MySQL tutorials. This tutorial is not aimed at persons with poor knowledge of MySQL.
What is required?
- BlueG's MySQL R7 plugin
- Have your server connected to MySQL
- Access to phpMyAdmin
Let's get started!
We'll add this to the top of our gamemode script:
pawn Код:
enum oInfo
{
ScriptID,
ModelID,
Float:X,
Float:Y,
Float:Z,
Float:rX,
Float:rY,
Float:rZ
};
new object[2000][oInfo];
I assume you have "mySQL_init();" inside OnGameModeInit, so under mySQL_init line add the following:
pawn Код:
print("**Now loading CreateDynamicObject SQL**");
mysql_function_query(1, "SELECT * FROM `objects`", true, "LoadObjects", "i", sizeof(object));
Then the biggest part:
pawn Код:
forward LoadObjects(limit);
public LoadObjects(limit)
{
new count, rows, fields, data[50];
cache_get_data(rows, fields);
for(new i; i < rows; i++)
{
if(count > limit)
{
printf("Number of objects exceeded limit!");
break;
}
for(new h; h < sizeof(object); h++)
{
if(object[h][ScriptID] == 0)
{
cache_get_field_content(i, "ScriptID", data); object[h][ScriptID] = strval(data);
cache_get_field_content(i, "ModelID", data); object[h][ModelID] = strval(data);
cache_get_field_content(i, "X", data); object[h][X] = floatstr(data);
cache_get_field_content(i, "Y", data); object[h][Y] = floatstr(data);
cache_get_field_content(i, "Z", data); object[h][Z] = floatstr(data);
cache_get_field_content(i, "rX", data); object[h][rX] = floatstr(data);
cache_get_field_content(i, "rY", data); object[h][rY] = floatstr(data);
cache_get_field_content(i, "rZ", data); object[h][rZ] = floatstr(data);
CreateDynamicObject(object[h][ModelID], object[h][X], object[h][Y], object[h][Z], object[h][rX], object[h][rY], object[h][rZ]);
count++;
break;
}
}
}
printf("Current objects on the server: %d",CountDynamicObjects());
return 1;
}
Halfway through! Coding in your gamemode part is finished and you can compile.
Next step is to create a SQL table. It can be done with notepad etc etc, but I use Pawno.
So here's the code:
PHP код:
-- phpMyAdmin SQL Dump
-- version 4.2.7.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 31, 2014 at 08:49 PM
-- Server version: 5.6.20
-- PHP Version: 5.5.15
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `changeme`
--
-- --------------------------------------------------------
--
-- Table structure for table `objects`
--
CREATE TABLE IF NOT EXISTS `objects` (
`ScriptID` int(10) NOT NULL,
`ModelID` int(10) NOT NULL,
`X` float NOT NULL,
`Y` float NOT NULL,
`Z` float NOT NULL,
`rX` float NOT NULL,
`rY` float NOT NULL,
`rZ` float NOT NULL,
`Comment` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=38 ;
INSERT INTO `objects` (`ScriptID`, `ModelID`, `X`, `Y`, `Z`, `rX`, `rY`, `rZ`, `Comment`) VALUES
(985, 777.942, -1330.18, 14.2512, 0, 0, -1, 'Chicago Outfit'),
(19410, 771.941, -1339.76, 14.2527, 0, 0, 90, 'Chicago Outfit');
I've used 2 objects as example on how to place them in the code.
Now save the file as "objects.sql" and import it from phpMyAdmin into your already existing database. A new table named "objects" will appear in your database, inside "objects" there will be those 2 example objects, unless you changed them.
Congratulations! You have fully set up a fully functioning table for dynamic objects!
A tip:
If you have much objects you'd like to add, it would be time consuming to add them one by one. So copy & paste your object code, for example: CreateDynamicObject(14407, 1121.00830, -1194.85254, 27.83070, 0.00000, 0.00000, 90.26003); - then simply (if you use Pawno) press CTRL + H. First we need to replace CreateDynamicObject with nothing, so leave "Replace with:" empty. That was fast. Now for the part on the right, you could fully remove the "Comment" value to save time, or just suffer a bit and start editing with Replace function. I would do it like this: Replace ); with ), 'changeme'), - REMEMBER, the last line must have a semicolon in the end, every other object line has just a comma ( , ) in the ending.
Credits goes to [HiC]TheKiller for his in-game Object Maker