Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <sampgdk/a_players.h>
- #include <sampgdk/a_samp.h>
- #include <sampgdk/core.h>
- #include <sampgdk/plugin.h>
- #include "gmDefines.h"
- #include "IniFile.cpp"
- #include "0cmdpp.hpp"
- static ThisPlugin gm1;
- #define MOD_VERSION "0.0.1"
- #define MOD_NAME "RPG-LIFE"
- #define SYS_MAX_BUSINESS 4
- /* Spalvos */
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xAA3333FF
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFAA
- #define COLOR_BLUE 0x0000BBAA
- #define COLOR_LIGHTBLUE 0x33CCFFAA
- #define COLOR_ORANGE 0xFF9900AA
- #define COLOR_RED 0xAA3333FF
- int totalBusiness = -1;
- /* Bizniai */
- bool LoadBusiness();
- struct Bizniai
- {
- std::string bPavadinimas, bSavininkas;
- float bX, bY, bZ;
- int bKaina, bLabel, failoID;
- };
- Bizniai bdb[ SYS_MAX_BUSINESS ];
- using namespace std;
- class Zaidejas
- {
- public:
- bool Save(int playerid);
- bool Load(int playerid);
- bool arZaidzia[ MAX_PLAYERS ];
- bool arNaujokas[ MAX_PLAYERS ];
- };
- bool fileExist(char filename[]);
- bool fexists(const char *filename)
- {
- std::ifstream ifile(filename);
- return !!ifile;
- }
- template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
- bool Zaidejas::Save(int playerid)
- {
- char vardas[30];
- GetPlayerName( playerid, vardas );
- char pilnasFailas[50];
- sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
- CIniFile failas;
- if(!fexists(pilnasFailas))
- {
- failas.Create(pilnasFailas);
- }
- failas.SetValue("Pinigai", to_string(GetPlayerMoney(playerid)), "Main", pilnasFailas);
- float x, y, z;
- GetPlayerPos( playerid, &x, &y, &z );
- failas.SetValue("posX", tostr( x ), "Main", pilnasFailas);
- failas.SetValue("posY", tostr( y ), "Main", pilnasFailas);
- failas.SetValue("posZ", tostr( z ), "Main", pilnasFailas);
- return true;
- }
- int toint( string str )
- {
- int rezult;
- stringstream( str ) >> rezult;
- return rezult;
- }
- bool Zaidejas::Load( int playerid )
- {
- char vardas[30];
- GetPlayerName( playerid, vardas );
- char pilnasFailas[50];
- sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
- CIniFile failas;
- if(!fexists(pilnasFailas))
- {
- failas.Create(pilnasFailas);
- }
- GivePlayerMoney( playerid, toint( failas.GetValue("Pinigai", "Main", pilnasFailas) ) );
- float x, y, z;
- x = (float)atof(failas.GetValue( "posX", "Main", pilnasFailas ).c_str());
- y = (float)atof(failas.GetValue( "posY", "Main", pilnasFailas ).c_str());
- z = (float)atof(failas.GetValue( "posZ", "Main", pilnasFailas ).c_str());
- SetPlayerPos( playerid, x, y, z );
- return true;
- }
- Zaidejas zaidejas;
- PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit() {
- SetGameModeText(""MOD_NAME" v"MOD_VERSION"");
- AddPlayerClass(0, 1958.3783f, 1343.1572f, 15.3746f, 269.1425f, 0, 0, 0, 0, 0, 0);
- ServerLog::Printf("------------------------------------------\n");
- ServerLog::Printf(" %s v%s loaded \n", MOD_NAME, MOD_VERSION);
- ServerLog::Printf("------------------------------------------\n");
- ServerLog::Printf("BIZNIAI");
- LoadBusiness();
- cout << "Bizniai baigti" << endl;
- cout << "Biznio id 1 savininkas " << bdb[1].bSavininkas << endl;
- cout << "Biznio id 2 savininkas " << bdb[2].bSavininkas << endl;
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerConnect(int playerid) {
- SendClientMessage(playerid, 0xFFFFFFFF, "Sveiki atvyke į RPG-LIFE serverį!");
- zaidejas.arZaidzia[ playerid ] = true;
- char vardas[30];
- GetPlayerName( playerid, vardas );
- char pilnasFailas[50];
- sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
- if(!fexists(pilnasFailas))
- {
- ShowPlayerDialog( playerid, 1, DIALOG_STYLE_PASSWORD, "[] Registracija", "Norėdami tęsti žaidimą šiame serveryje privalote susikūrti sąskaita", "Registruotis", "Išeiti");
- }
- else
- {
- ShowPlayerDialog( playerid, 2, DIALOG_STYLE_PASSWORD, "[] Prisijungimas", "Jūsų sąskaita buvo rastą, norėdami tęsti - prisijunkite", "Jungtis", "Išeiti");
- }
- return true;
- }
- ZERO_COMMAND(s)
- {
- return true;
- }
- bool OnPlayerCommandReceived(int playerid,std::string command, std::string params)
- {
- return true;
- }
- void OnPlayerCommandExecuted(int playerid, std::string, std::string params, bool success)
- {
- }
- bool OnUnknownCommand(int playerid, std::string command, std::string params)
- {
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnDialogResponse(int playerid, int dialogid, int response, int listitem, const char * inputtext)
- {
- if( dialogid == 2 )
- {
- if( response )
- {
- char vardas[30];
- GetPlayerName( playerid, vardas );
- char pilnasFailas[50];
- sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
- CIniFile failas;
- char slaptazodis[ 60 ];
- sprintf_s( slaptazodis, 60, "%s", failas.GetValue( "Slaptazodis", "Main", pilnasFailas ));
- if(strcmp(strdup(failas.GetValue( "Slaptazodis", "Main", pilnasFailas ).c_str()), inputtext) == 0)
- {
- SendClientMessage( playerid, -1, "Prisijungėte sėkmingai!" );
- zaidejas.arNaujokas[ playerid ] = false;
- }
- else
- {
- SendClientMessage( playerid, -1, inputtext );
- SendClientMessage( playerid, -1, strdup(failas.GetValue( "Slaptazodis", "Main", pilnasFailas ).c_str()) );
- SendClientMessage( playerid, -1, "Prisijungimas nepavyko!" );
- ShowPlayerDialog( playerid, 2, DIALOG_STYLE_PASSWORD, "[] Prisijungimas", "Jūsų sąskaita buvo rastą, norėdami tęsti - prisijunkite", "Jungtis", "Išeiti");
- }
- }
- return true;
- }
- if( dialogid == 1 )
- {
- if(response)
- {
- char vardas[30];
- GetPlayerName( playerid, vardas );
- char pilnasFailas[50];
- sprintf_s(pilnasFailas, "data/users/%s.ini", vardas);
- CIniFile failas;
- failas.Create( pilnasFailas );
- failas.SetValue( "Slaptazodis", inputtext, "Main", pilnasFailas );
- char zinute[128];
- sprintf_s( zinute, 128, "Registracija sėkminga, jūsų slaptažodis: %s", inputtext );
- SendClientMessage( playerid, -1, zinute );
- zaidejas.arNaujokas[ playerid ] = true;
- return true;
- }
- else if( !response )
- {
- Kick( playerid );
- }
- return true;
- }
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerDisconnect( int playerid, int reason )
- {
- if( zaidejas.arZaidzia[ playerid ] )
- {
- zaidejas.Save( playerid );
- }
- zaidejas.arZaidzia[ playerid ] = false;
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerSpawn( int playerid )
- {
- if( !zaidejas.arNaujokas[ playerid ] )
- {
- zaidejas.Load(playerid);
- }
- else
- {
- SendClientMessage( playerid, -1, "Sveikas naujoke" );
- }
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerRequestClass(int playerid, int classid) {
- SetPlayerPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
- SetPlayerCameraPos(playerid, 1958.3783f, 1343.1572f, 15.3746f);
- SetPlayerCameraLookAt(playerid, 1958.3783f, 1343.1572f, 15.3746f, CAMERA_CUT);
- return true;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext)
- {
- if( strcmp(cmdtext, "/s") == 0 )
- {
- string zinute;
- if( sscanf( cmdtext, "s", zinute ) )
- {
- SendClientMessage( playerid, COLOR_RED, "Naudojimas /s [ zinute ]" );
- return true;
- }
- SendClientMessageToAll( COLOR_RED, zinute.c_str() );
- return true;
- }
- if( strcmp(cmdtext, "/biznis") == 0 )
- {
- int biznis = -1;
- for( int b = 0; b < SYS_MAX_BUSINESS; b++ )
- {
- if( IsPlayerInRangeOfPoint( playerid, 3.0f, bdb[ b ].bX, bdb[ b ].bY, bdb[ b ].bZ ) )
- {
- biznis = b;
- break;
- }
- }
- if( biznis != -1 )
- {
- if(!bdb[biznis].bSavininkas.compare("nera"))
- {
- char dialogFormat[ 400 ];
- 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 );
- ShowPlayerDialog( playerid, 3, DIALOG_STYLE_LIST, " >> Biznis", dialogFormat, "Rinktis", "Atgal" );
- }
- else
- {
- char dialogFormat[ 400 ];
- sprintf( dialogFormat, " \n {ff0000}BIZNIS %s\n {ffffff}> Savininkas {f00000}%s", bdb[biznis].bPavadinimas.c_str(), bdb[biznis].bSavininkas.c_str() );
- ShowPlayerDialog( playerid, 10, DIALOG_STYLE_LIST, " >> Biznis", dialogFormat, "Rinktis", "Atgal" );
- }
- }
- else
- {
- SendClientMessage( playerid, COLOR_RED, "Jus neesate prie biznio" );
- }
- return true;
- }
- if(strcmp(cmdtext, "/pinigai") == 0)
- {
- GivePlayerMoney( playerid, 5000 );
- return true;
- }
- if (std::strcmp(cmdtext, "/hello") == 0)
- {
- char name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name);
- char message[128];
- sprintf_s(message, "Hello, %s!", name);
- SendClientMessage(playerid, 0x00FF00FF, message);
- return true;
- }
- if (std::strcmp(cmdtext, "/pos") == 0)
- {
- float x, y, z;
- GetPlayerPos(playerid, &x, &y, &z);
- char message[128];
- sprintf_s(message, "You are at (%f, %f, %f)", x, y, z);
- SendClientMessage(playerid, 0xFFFFFFFF, message);
- return true;
- }
- return false;
- }
- PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() {
- return SUPPORTS_VERSION | SUPPORTS_PROCESS_TICK;
- }
- PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) {
- return gm1.Load(ppData) >= 0;
- }
- PLUGIN_EXPORT void PLUGIN_CALL Unload() {
- gm1.Unload();
- }
- PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() {
- gm1.ProcessTimers();
- }
- bool fileExist(char filename[])
- {
- FILE *failas;
- bool egzistuoja;
- failas = fopen(filename,"r");
- if( failas == NULL )
- {
- egzistuoja = false;
- }
- else
- {
- egzistuoja = true;
- fclose( failas );
- }
- return egzistuoja;
- }
- bool LoadBusiness()
- {
- char pilnasFailas[50];
- for( int biznis = 0; biznis < SYS_MAX_BUSINESS; biznis++ )
- {
- totalBusiness ++;
- sprintf_s(pilnasFailas, "data/business/%i.ini", biznis);
- if( !fexists( pilnasFailas ) ) continue;
- CIniFile failas;
- float x, y, z;
- x = (float)atof(failas.GetValue( "bX", "Business", pilnasFailas ).c_str());
- bdb[ totalBusiness ].bX = x;
- y = (float)atof(failas.GetValue( "bY", "Business", pilnasFailas ).c_str());
- bdb[ totalBusiness ].bY = y;
- z = (float)atof(failas.GetValue( "bZ", "Business", pilnasFailas ).c_str());
- bdb[ totalBusiness ].bZ = z;
- cout << failas.GetValue( "bKaina", "Business", pilnasFailas ).c_str() << endl;
- bdb[ totalBusiness ].bKaina = atol( failas.GetValue("bKaina", "Business", pilnasFailas).c_str() );
- char bName[ 150 ];
- sprintf_s( bName, "%s", failas.GetValue( "bName", "Business", pilnasFailas ).c_str() );
- cout << bName << endl;
- bdb[ totalBusiness ].bPavadinimas = failas.GetValue( "bName", "Business", pilnasFailas );
- cout << bdb[ totalBusiness ].bPavadinimas << endl;
- bdb[ totalBusiness ].bSavininkas = failas.GetValue( "Savininkas", "Business", pilnasFailas );
- bdb[ totalBusiness ].failoID = biznis;
- cout << "Savininkas yra " << bdb[ totalBusiness ].bSavininkas << endl;
- cout << "Biznio ID: " << totalBusiness << endl;
- cout << bdb[ totalBusiness ].bKaina << endl;
- char lTekstas[ 250 ];
- 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 );
- bdb[ totalBusiness ].bLabel = Create3DTextLabel( lTekstas, COLOR_RED, x, y, z, 10.0f, 0, 1 );
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment