Guest User

Untitled

a guest
Sep 11th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <sstream>
  8.  
  9. #include <sampgdk/a_players.h>
  10. #include <sampgdk/a_samp.h>
  11. #include <sampgdk/core.h>
  12. #include <sampgdk/plugin.h>
  13.  
  14. #include "gmDefines.h"
  15. #include "IniFile.cpp"
  16. #include "0cmdpp.hpp"
  17.  
  18. static ThisPlugin gm1;
  19.  
  20.  
  21. #define MOD_VERSION "0.0.1"
  22. #define MOD_NAME "RPG-LIFE"
  23. #define SYS_MAX_BUSINESS 4
  24.  
  25. /* Spalvos */
  26. #define COLOR_GREEN 0x33AA33AA
  27. #define COLOR_RED 0xAA3333FF
  28. #define COLOR_YELLOW 0xFFFF00AA
  29. #define COLOR_WHITE 0xFFFFFFAA
  30. #define COLOR_BLUE 0x0000BBAA
  31. #define COLOR_LIGHTBLUE 0x33CCFFAA
  32. #define COLOR_ORANGE 0xFF9900AA
  33. #define COLOR_RED 0xAA3333FF
  34.  
  35. int totalBusiness = -1;
  36. /* Bizniai */
  37. bool LoadBusiness();
  38.  
  39. struct Bizniai
  40. {
  41. std::string bPavadinimas, bSavininkas;
  42. float bX, bY, bZ;
  43. int bKaina, bLabel, failoID;
  44. };
  45.  
  46. Bizniai bdb[ SYS_MAX_BUSINESS ];
  47.  
  48. using namespace std;
  49.  
  50. class Zaidejas
  51. {
  52. public:
  53. bool Save(int playerid);
  54. bool Load(int playerid);
  55. bool arZaidzia[ MAX_PLAYERS ];
  56. bool arNaujokas[ MAX_PLAYERS ];
  57. };
  58. bool fileExist(char filename[]);
  59.  
  60. bool fexists(const char *filename)
  61. {
  62. std::ifstream ifile(filename);
  63. return !!ifile;
  64. }
  65. template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
  66.  
  67. bool Zaidejas::Save(int playerid)
  68. {
  69. char vardas[30];
  70. GetPlayerName( playerid, vardas );
  71. char pilnasFailas[50];
  72. sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
  73. CIniFile failas;
  74. if(!fexists(pilnasFailas))
  75. {
  76. failas.Create(pilnasFailas);
  77. }
  78. failas.SetValue("Pinigai", to_string(GetPlayerMoney(playerid)), "Main", pilnasFailas);
  79. float x, y, z;
  80. GetPlayerPos( playerid, &x, &y, &z );
  81.  
  82. failas.SetValue("posX", tostr( x ), "Main", pilnasFailas);
  83. failas.SetValue("posY", tostr( y ), "Main", pilnasFailas);
  84. failas.SetValue("posZ", tostr( z ), "Main", pilnasFailas);
  85. return true;
  86. }
  87.  
  88. int toint( string str )
  89. {
  90. int rezult;
  91. stringstream( str ) >> rezult;
  92. return rezult;
  93. }
  94.  
  95. bool Zaidejas::Load( int playerid )
  96. {
  97. char vardas[30];
  98. GetPlayerName( playerid, vardas );
  99. char pilnasFailas[50];
  100. sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
  101. CIniFile failas;
  102. if(!fexists(pilnasFailas))
  103. {
  104. failas.Create(pilnasFailas);
  105. }
  106. GivePlayerMoney( playerid, toint( failas.GetValue("Pinigai", "Main", pilnasFailas) ) );
  107. float x, y, z;
  108. x = (float)atof(failas.GetValue( "posX", "Main", pilnasFailas ).c_str());
  109. y = (float)atof(failas.GetValue( "posY", "Main", pilnasFailas ).c_str());
  110. z = (float)atof(failas.GetValue( "posZ", "Main", pilnasFailas ).c_str());
  111. SetPlayerPos( playerid, x, y, z );
  112. return true;
  113. }
  114.  
  115. Zaidejas zaidejas;
  116.  
  117.  
  118. PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
  119. SetGameModeText(""MOD_NAME" v"MOD_VERSION"");
  120. AddPlayerClass(0, 1958.3783f, 1343.1572f, 15.3746f, 269.1425f, 0, 0, 0, 0, 0, 0);
  121.  
  122. ServerLog::Printf("------------------------------------------\n");
  123. ServerLog::Printf(" %s v%s loaded \n", MOD_NAME, MOD_VERSION);
  124. ServerLog::Printf("------------------------------------------\n");
  125. ServerLog::Printf("BIZNIAI");
  126. LoadBusiness();
  127. cout << "Bizniai baigti" << endl;
  128. cout << "Biznio id 1 savininkas " << bdb[1].bSavininkas << endl;
  129. cout << "Biznio id 2 savininkas " << bdb[2].bSavininkas << endl;
  130. return true;
  131. }
  132.  
  133.  
  134. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid) {
  135. SendClientMessage(playerid, 0xFFFFFFFF, "Sveiki atvyke į RPG-LIFE serverį!");
  136. zaidejas.arZaidzia[ playerid ] = true;
  137. char vardas[30];
  138. GetPlayerName( playerid, vardas );
  139. char pilnasFailas[50];
  140. sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
  141. if(!fexists(pilnasFailas))
  142. {
  143. ShowPlayerDialog( playerid, 1, DIALOG_STYLE_PASSWORD, "[] Registracija", "Norėdami tęsti žaidimą šiame serveryje privalote susikūrti sąskaita", "Registruotis", "Išeiti");
  144. }
  145. else
  146. {
  147. ShowPlayerDialog( playerid, 2, DIALOG_STYLE_PASSWORD, "[] Prisijungimas", "Jūsų sąskaita buvo rastą, norėdami tęsti - prisijunkite", "Jungtis", "Išeiti");
  148. }
  149. return true;
  150. }
  151.  
  152. ZERO_COMMAND(s)
  153. {
  154.  
  155. return true;
  156. }
  157.  
  158. bool OnPlayerCommandReceived(int playerid,std::string command, std::string params)
  159. {
  160. return true;
  161. }
  162. void OnPlayerCommandExecuted(int playerid, std::string, std::string params, bool success)
  163. {
  164.  
  165. }
  166.  
  167. bool OnUnknownCommand(int playerid, std::string command, std::string params)
  168. {
  169. return true;
  170. }
  171.  
  172. PLUGIN_EXPORT bool PLUGIN_CALL OnDialogResponse(int playerid, int dialogid, int response, int listitem, const char * inputtext)
  173. {
  174. if( dialogid == 2 )
  175. {
  176. if( response )
  177. {
  178. char vardas[30];
  179. GetPlayerName( playerid, vardas );
  180. char pilnasFailas[50];
  181. sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
  182. CIniFile failas;
  183. char slaptazodis[ 60 ];
  184. sprintf_s( slaptazodis, 60, "%s", failas.GetValue( "Slaptazodis", "Main", pilnasFailas ));
  185. if(strcmp(strdup(failas.GetValue( "Slaptazodis", "Main", pilnasFailas ).c_str()), inputtext) == 0)
  186. {
  187. SendClientMessage( playerid, -1, "Prisijungėte sėkmingai!" );
  188. zaidejas.arNaujokas[ playerid ] = false;
  189. }
  190. else
  191. {
  192. SendClientMessage( playerid, -1, inputtext );
  193. SendClientMessage( playerid, -1, strdup(failas.GetValue( "Slaptazodis", "Main", pilnasFailas ).c_str()) );
  194. SendClientMessage( playerid, -1, "Prisijungimas nepavyko!" );
  195. ShowPlayerDialog( playerid, 2, DIALOG_STYLE_PASSWORD, "[] Prisijungimas", "Jūsų sąskaita buvo rastą, norėdami tęsti - prisijunkite", "Jungtis", "Išeiti");
  196. }
  197. }
  198. return true;
  199. }
  200. if( dialogid == 1 )
  201. {
  202. if(response)
  203. {
  204. char vardas[30];
  205. GetPlayerName( playerid, vardas );
  206. char pilnasFailas[50];
  207. sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
  208. CIniFile failas;
  209. failas.Create( pilnasFailas );
  210. failas.SetValue( "Slaptazodis", inputtext, "Main", pilnasFailas );
  211. char zinute[128];
  212. sprintf_s( zinute, 128, "Registracija sėkminga, jūsų slaptažodis: %s", inputtext );
  213. SendClientMessage( playerid, -1, zinute );
  214. zaidejas.arNaujokas[ playerid ] = true;
  215. return true;
  216. }
  217. else if( !response )
  218. {
  219. Kick( playerid );
  220. }
  221. return true;
  222. }
  223. return true;
  224. }
  225.  
  226. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerDisconnect( int playerid, int reason )
  227. {
  228. if( zaidejas.arZaidzia[ playerid ] )
  229. {
  230. zaidejas.Save( playerid );
  231. }
  232. zaidejas.arZaidzia[ playerid ] = false;
  233. return true;
  234. }
  235.  
  236. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerSpawn( int playerid )
  237. {
  238. if( !zaidejas.arNaujokas[ playerid ] )
  239. {
  240. zaidejas.Load(playerid);
  241. }
  242. else
  243. {
  244. SendClientMessage( playerid, -1, "Sveikas naujoke" );
  245. }
  246. return true;
  247. }
  248.  
  249. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int playerid, int classid) {
  250. SetPlayerPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
  251. SetPlayerCameraPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
  252. SetPlayerCameraLookAt(playerid, 1958.3783f, 1343.1572f, 15.3746f, CAMERA_CUT);
  253. return true;
  254. }
  255.  
  256. PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext)
  257. {
  258. if( strcmp(cmdtext, "/s") == 0 )
  259. {
  260. string zinute;
  261. if( sscanf( cmdtext, "s", zinute ) )
  262. {
  263. SendClientMessage( playerid, COLOR_RED, "Naudojimas /s [ zinute ]" );
  264. return true;
  265. }
  266. SendClientMessageToAll( COLOR_RED, zinute.c_str() );
  267. return true;
  268. }
  269. if( strcmp(cmdtext, "/biznis") == 0 )
  270. {
  271. int biznis = -1;
  272. for( int b = 0; b < SYS_MAX_BUSINESS; b++ )
  273. {
  274. if( IsPlayerInRangeOfPoint( playerid, 3.0f, bdb[ b ].bX, bdb[ b ].bY, bdb[ b ].bZ ) )
  275. {
  276. biznis = b;
  277. break;
  278. }
  279. }
  280. if( biznis != -1 )
  281. {
  282. if(!bdb[biznis].bSavininkas.compare("nera"))
  283. {
  284. char dialogFormat[ 400 ];
  285. sprintf( dialogFormat, " \n {ff0000}BIZNIS %s\n {ffffff}> Savininko {66cc00}nėra\n {ffffff}> Kaina: {ff6600}%i", bdb[biznis].bPavadinimas.c_str(), bdb[biznis].bKaina );
  286. ShowPlayerDialog( playerid, 3, DIALOG_STYLE_LIST, " >> Biznis", dialogFormat, "Rinktis", "Atgal" );
  287. }
  288. else
  289. {
  290. char dialogFormat[ 400 ];
  291. sprintf( dialogFormat, " \n {ff0000}BIZNIS %s\n {ffffff}> Savininkas {f00000}%s", bdb[biznis].bPavadinimas.c_str(), bdb[biznis].bSavininkas.c_str() );
  292. ShowPlayerDialog( playerid, 10, DIALOG_STYLE_LIST, " >> Biznis", dialogFormat, "Rinktis", "Atgal" );
  293. }
  294. }
  295. else
  296. {
  297. SendClientMessage( playerid, COLOR_RED, "Jus neesate prie biznio" );
  298. }
  299. return true;
  300. }
  301.  
  302. if(strcmp(cmdtext, "/pinigai") == 0)
  303. {
  304. GivePlayerMoney( playerid, 5000 );
  305. return true;
  306. }
  307. if (std::strcmp(cmdtext, "/hello") == 0)
  308. {
  309. char name[MAX_PLAYER_NAME];
  310. GetPlayerName(playerid, name);
  311. char message[128];
  312. sprintf_s(message, "Hello, %s!", name);
  313. SendClientMessage(playerid, 0x00FF00FF, message);
  314. return true;
  315. }
  316.  
  317. if (std::strcmp(cmdtext, "/pos") == 0)
  318. {
  319. float x, y, z;
  320. GetPlayerPos(playerid, &x, &y, &z);
  321. char message[128];
  322. sprintf_s(message, "You are at (%f, %f, %f)", x, y, z);
  323. SendClientMessage(playerid, 0xFFFFFFFF, message);
  324. return true;
  325. }
  326.  
  327. return false;
  328. }
  329.  
  330. PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
  331. return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;
  332. }
  333.  
  334. PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
  335. return gm1.Load(ppData) >= 0;
  336. }
  337.  
  338. PLUGIN_EXPORT void PLUGIN_CALL Unload() {
  339. gm1.Unload();
  340. }
  341.  
  342. PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
  343. gm1.ProcessTimers();
  344. }
  345.  
  346. bool fileExist(char filename[])
  347. {
  348. FILE *failas;
  349. bool egzistuoja;
  350. failas = fopen(filename,"r");
  351. if( failas == NULL )
  352. {
  353. egzistuoja = false;
  354. }
  355. else
  356. {
  357. egzistuoja = true;
  358. fclose( failas );
  359. }
  360. return egzistuoja;
  361. }
  362.  
  363. bool LoadBusiness()
  364. {
  365. char pilnasFailas[50];
  366.  
  367. for( int biznis = 0; biznis < SYS_MAX_BUSINESS; biznis++ )
  368. {
  369. totalBusiness ++;
  370. sprintf_s(pilnasFailas, "data/business/%i.ini", biznis);
  371. if( !fexists( pilnasFailas ) ) continue;
  372. CIniFile failas;
  373. float x, y, z;
  374. x = (float)atof(failas.GetValue( "bX", "Business", pilnasFailas ).c_str());
  375. bdb[ totalBusiness ].bX = x;
  376. y = (float)atof(failas.GetValue( "bY", "Business", pilnasFailas ).c_str());
  377. bdb[ totalBusiness ].bY = y;
  378. z = (float)atof(failas.GetValue( "bZ", "Business", pilnasFailas ).c_str());
  379. bdb[ totalBusiness ].bZ = z;
  380. cout << failas.GetValue( "bKaina", "Business", pilnasFailas ).c_str() << endl;
  381. bdb[ totalBusiness ].bKaina = atol( failas.GetValue("bKaina", "Business", pilnasFailas).c_str() );
  382. char bName[ 150 ];
  383. sprintf_s( bName, "%s", failas.GetValue( "bName", "Business", pilnasFailas ).c_str() );
  384. cout << bName << endl;
  385. bdb[ totalBusiness ].bPavadinimas = failas.GetValue( "bName", "Business", pilnasFailas );
  386. cout << bdb[ totalBusiness ].bPavadinimas << endl;
  387. bdb[ totalBusiness ].bSavininkas = failas.GetValue( "Savininkas", "Business", pilnasFailas );
  388. bdb[ totalBusiness ].failoID = biznis;
  389. cout << "Savininkas yra " << bdb[ totalBusiness ].bSavininkas << endl;
  390. cout << "Biznio ID: " << totalBusiness << endl;
  391. cout << bdb[ totalBusiness ].bKaina << endl;
  392. char lTekstas[ 250 ];
  393. sprintf_s( lTekstas, "{ff0000}%s\n{ffffff}Savininkas: {ff0000}%s\n{ffffff}Kaina: {ff0000}%i", bdb[ totalBusiness ].bPavadinimas.c_str(), bdb[ totalBusiness ].bSavininkas.c_str(), bdb[ totalBusiness ].bKaina );
  394. bdb[ totalBusiness ].bLabel = Create3DTextLabel( lTekstas, COLOR_RED, x, y, z, 10.0f, 0, 1 );
  395. }
  396. return true;
  397. }
Advertisement
Add Comment
Please, Sign In to add comment