05.07.2012, 07:27
(
Последний раз редактировалось Kindred; 08.07.2012 в 07:06.
)
Well, my business system is not working. I was wondering if you guys could take a look at it, fix it, and/or tell me what is wrong with it.
Like I said in my other posts, I am a newb with mysql. The problem is that the business is not saving, and I get an error in the console when I type the command /createbusiness:
This is the code:
Thanks, help is appreciated.
Like I said in my other posts, I am a newb with mysql. The problem is that the business is not saving, and I get an error in the console when I type the command /createbusiness:
This is the code:
pawn Код:
// _____ _ _ _ _ __ _
/// ___| (_) | | | | | | / / | |
//\ `--. ___ _ __ _ _ __ | |_ | |__ _ _ | |/ / _ _ _ __| |_
// `--. \/ __| '__| | '_ \| __| | '_ \| | | | | \| | | | '__| __|
///\__/ / (__| | | | |_) | |_ | |_) | |_| | | |\ \ |_| | | | |_
//\____/ \___|_| |_| .__/ \__| |_.__/ \__, | \_| \_/\__,_|_| \__/
// | | __/ |
// |_| |___/
//------------------------------------------------------------------[ Includes ]
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <svAddons>
#include <svCheats>
#include <YSI\y_timers>
//--------------------------------------------------------------------[ Colors ]
#define Black "{000000}"
#define White "{FFFFFF}"
#define Grey "{BFBFBF}"
#define Red "{FF0000}"
#define Orange "{FFA500}"
#define Yellow "{FFFF00}"
#define Green "{008000}"
#define Blue "{0000FF}"
#define Purple "{800080}"
#define Teal "{008080}"
#define COLOR_BLACK 0x000000FF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_GREY 0xBFBFBFFF
#define COLOR_RED 0xFF0000FF
#define COLOR_ORANGE 0xFFA500FF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_GREEN 0x008000FF
#define COLOR_BLUE 0x0000FFFF
#define COLOR_PURPLE 0x800080FF
#define COLOR_TEAL 0x008080FF
//-----------------------------------------------------------------[Limits]
#undef MAX_PLAYERS
#define MAX_PLAYERS 10
#define MAX_BUSINESSES 150
//--------------------------------------------------------------[ Milliseconds ]
#define Year 31536000000 // Day x 365
#define Month 2592000000 // Day x 30
#define Week 604800000 // Day x 7
#define Day 86400000 // Hour x 24
#define Hour 3600000 // Minute x 60
#define Minute 60000 // Second x 60
#define Second 1000 // Millisecond x 1000
//---------------------------------------------------------------[MYSQL Defines]
#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password ""
#define mysql_database "roleplay"
//-----------------------------------------------------------------[ Arrays ]
new RandMessages[][] =
{
{"HINT: The server is still in beta, so it will be missing some key features."},
{"HINT: Looking to earn some money? Get a job! /help."},
{"HINT: In need of a family? Roleplay with their leaders! /families. ((DON'T MG))"},
{"HINT: Don't forget to sign up for the forums and join the teamspeak! /information."},
{"HINT: Need a car? Steal one, or buy one from a dealership!"},
{"HINT: If you are caught avoiding RP or powergaming, there will be consiquences!"}
};
//-----------------------------------------------------------------[ Variables ]
enum PlayerInfo
{
Username[24],
Admin,
Cash,
PlayHours,
PlayMinutes,
Paycheck,
Float:Pos[4],
Interior,
World,
Kills,
Deaths,
Level
};
new pInfo[MAX_PLAYERS][PlayerInfo];
enum BusinessInfo
{
ID,
Price,
Float:EnterX,
Float:EnterY,
Float:EnterZ,
Float:ExitX,
Float:ExitY,
Float:ExitZ,
Interior,
World,
Pickup,
Text3D:Label,
Text[24],
Owner[24],
Minutes,
Money
};
new bInfo[MAX_BUSINESSES][BusinessInfo];
new IsRegistered[MAX_PLAYERS];
new Logged[MAX_PLAYERS];
new IsCharacter[MAX_PLAYERS];
new MoneyGiven[MAX_PLAYERS];
new CharacterInfo[MAX_PLAYERS][5][24];
//--------------------------------------------------------------------[ Unused ]
main() {}
//--------------------------------------------------------------------[ Timers ]
//----------------------------------------------------------[ Custom Functions ]
//---------------------------------------------------------[ Default Callbacks ]
public OnGameModeInit()
{
mysql_debug(1);
LoadBusinesses();
SetTimer("RandomMessageTimer", 300000, 1);
SetGameModeText("TestRP 1.0");
mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
mysql_query("CREATE TABLE IF NOT EXISTS Accounts(Username VARCHAR(24), Password VARCHAR(100), Character1 VARCHAR(24), Character2 VARCHAR(24), Character3 VARCHAR(24), Character4 VARCHAR(24), Character5 VARCHAR(24), Adminlevel INT(2), IP VARCHAR(16) )");
mysql_query("CREATE TABLE IF NOT EXISTS playerdata(name VARCHAR(24), Username VARCHAR(24), Cash INT(10), PlayHours INT(10), PlayMinutes INT(2), PositionX FLOAT(20), PositionY FLOAT(20), PositionZ FLOAT(20), Angle FLOAT(20), Interior INT(2), World INT(4), Kills INT(4), Deaths INT(4), Level INT(3) )");
mysql_query("CREATE TABLE IF NOT EXISTS businessdata(BusinessID INT(3), Price Int(10), EnterX FLOAT(20), EnterY FLOAT(20), EnterZ FLOAT(20), ExitX FLOAT(20), ExitY FLOAT(20), ExitZ FLOAT(20), Interior INT(2), World INT(4), Text VARCHAR(24), Owner VARCHAR(24), Minutes INT(2), Money INT(5) )");
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
MoneyGiven[playerid] = -1;
new query[200], pname[24];
pname = GetName(playerid);
format(query, sizeof(query), "SELECT IP FROM `Accounts` WHERE Username = '%s' LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
pInfo[playerid][Username] = GetName(playerid);
Logged[playerid] = 0; IsCharacter[playerid] = 0;
if(!rows)
{
ShowDialog(playerid, 1);
}
if(rows == 1)
{
ShowDialog(playerid, 2);
IsRegistered[playerid] = 1;
}
mysql_free_result();
TogglePlayerSpectating(playerid, 1);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveCharacter(playerid);
SavePlayerCharacters(playerid);
return 1;
}
//---------------------[Commands]
CMD:stats(playerid, params[])
{
if(IsPlayerConnected(playerid) && IsPlayerLoggedIn(playerid))
{
new string[128];
format(string, sizeof(string), "[-------------------[%s]-------------------]", GetRPName(playerid));
SendClientMessageEx(playerid, COLOR_GREEN, string);
format(string, sizeof(string), "| Kills = %i; Deaths = %i; PlayHours = %i; |", pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][PlayHours]);
SendClientMessageEx(playerid, COLOR_WHITE, string);
SendClientMessageEx(playerid, COLOR_GREEN, "--------------------------------------------");
}
return 1;
}
CMD:paycheck(playerid, params[])
{
if(IsPlayerConnected(playerid) && IsPlayerLoggedIn(playerid))
{
new string[128];
format(string, sizeof(string), "Time left until paycheck: %i", 60 - pInfo[playerid][PlayMinutes]);
SendClientMessageEx(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "Paycheck amount: %i", pInfo[playerid][Paycheck]);
SendClientMessageEx(playerid, COLOR_YELLOW, string);
}
return 1;
}
CMD:setpaycheck(playerid, params[])
{
if(IsPlayerConnected(playerid) && IsPlayerLoggedIn(playerid))
{
new targetid, amount, string[128];
if(sscanf(params, "ui", targetid, amount)) return SendClientMessageEx(playerid, COLOR_GREY, "Usage: /setpaycheck [playerid/partofname] [amount]");
if(!IsPlayerConnected(targetid)) return SendClientMessageEx(playerid, COLOR_GREY, "That player is not connected!");
pInfo[targetid][Paycheck] = amount;
format(string, sizeof(string), "%s's paycheck has been set to %i", GetName(targetid), amount);
}
return 1;
}
CMD:cmds(playerid, params[])
{
if(IsPlayerConnected(playerid) && IsPlayerLoggedIn(playerid))
{
SendClientMessageEx(playerid, COLOR_YELLOW, "SGRP Command List");
SendClientMessageEx(playerid, COLOR_YELLOW, "/stats, /paycheck, /setpaycheck");
}
return 1;
}
//Business commands [Admins]
CMD:createbusiness(playerid, params[])
{
if(IsPlayerLoggedIn(playerid) && pInfo[playerid][Admin] >= 3)
{
new bizid, bizprice, bizeX, bizeY, bizeZ, bizexX, bizexY, bizexZ, bizint, bizworld = random(9999), biztext[24];
if(sscanf(params, "iiffffffis[24]", bizid, bizprice, bizeX, bizeY, bizeZ, bizexX, bizexY, bizexZ, bizint, biztext))
return SendClientMessage(playerid, COLOR_GREY, "Usage: /createbusiness [business id][price][entrancex][entrancey][entrancez][exitx][exity][exitz][interior][name]");
if(bizint > 99) return SendClientMessage(playerid, COLOR_GREY, "Business interior: 1-99");
if(IsBusinessCreated(bizid)) return SendClientMessage(playerid, COLOR_GREY, "That business is already created!");
if(strlen(biztext) > 24) return SendClientMessage(playerid, COLOR_GREY, "The business name can only be 24 characters!");
CreateBusiness(bizid, bizprice, bizeX, bizeY, bizeZ, bizexX, bizexY, bizexZ, bizint, bizworld, biztext);
}
return 1;
}
CMD:deletebusiness(playerid, params[])
{
if(IsPlayerLoggedIn(playerid) && pInfo[playerid][Admin] >= 3)
{
new bizid;
if(!IsBusinessCreated(bizid)) return SendClientMessage(playerid, COLOR_GREY, "That business is not created!");
DeleteBusiness(bizid);
}
return 1;
}
CMD:reloadbusinesses(playerid, params[])
{
if(IsPlayerLoggedIn(playerid) && pInfo[playerid][Admin] >= 3)
{
ReloadBusinesses();
}
return 1;
}
//Business commands [Players]
CMD:enter(playerid, params[])
{
if(IsPlayerLoggedIn(playerid))
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ]))
{
SetPlayerPos(playerid, bInfo[i][ExitX], bInfo[i][ExitY], bInfo[i][ExitZ]);
}
}
}
return 1;
}
CMD:exit(playerid, params[])
{
if(IsPlayerLoggedIn(playerid))
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, bInfo[i][ExitX], bInfo[i][ExitY], bInfo[i][ExitZ]))
{
SetPlayerPos(playerid, bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ]);
}
}
}
return 1;
}
CMD:buybusiness(playerid, params[])
{
if(IsPlayerLoggedIn(playerid))
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ]))
{
if(!IsBusinessOwned(i))
{
if(GetPlayerMoney(playerid) < bInfo[i][Price]) return SendClientMessage(playerid, COLOR_GREY, "You do not have enough money to buy that business!");
UpdateBusinessOwner(i, GetName(playerid));
}
}
else SendClientMessageEx(playerid, COLOR_WHITE, "You are not near a business!");
}
}
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
pInfo[playerid][Deaths] ++;
pInfo[killerid][Kills] ++;
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
if(IsPlayerLoggedIn(playerid))
{
new string[128];
format(string, sizeof(string), "%s says: %s", GetRPName(playerid), text);
SendLocalMessage(playerid,COLOR_WHITE,string,7);
}
else return SendClientMessage(playerid, COLOR_GREY, "You are restricted from typing, because you are not logged in / playing as a character");
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(IsPlayerConnected(playerid) && IsPlayerLoggedIn(playerid))
{
return SendClientMessageEx(playerid, COLOR_GREY, "The command you entered is not in the server's database!");
}
else return SendClientMessage(playerid, COLOR_GREY, "You are restricted from typing, because you are not logged in / playing as a character");
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnEnterExitModShop(playerid, enterexit, interiorid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
return 1;
}
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_SECONDARY_ATTACK)
{
if(IsPlayerLoggedIn(playerid))
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ]))
{
SetPlayerPos(playerid, bInfo[i][ExitX], bInfo[i][ExitY], bInfo[i][ExitZ]);
}
else if(IsPlayerInRangeOfPoint(playerid, 3.0, bInfo[i][ExitX], bInfo[i][ExitY], bInfo[i][ExitZ]))
{
SetPlayerPos(playerid,bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ]);
}
}
}
}
return 1;
}
public OnRconLoginAttempt(ip[], password[], success )
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case 1:
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 100)
{
SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-100 characters!");
ShowDialog(playerid, 1);
}
else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
RegisterAccount(playerid, escpass);
}
}
if(!response)
{
SendClientMessage(playerid, COLOR_GREY, "You decided to cancel your registration, you will now be kicked!");
Kick(playerid);
}
}
case 2:
{
if(!response)
{
SendClientMessage(playerid, COLOR_GREY, "You decided to cancel logging in, you will now be kicked!");
Kick(playerid);
}
if(response)
{
new query[200], pname[24], escapepass[100];
pname = GetName(playerid);
mysql_real_escape_string(inputtext, escapepass);
format(query, sizeof(query), "SELECT `UserName` FROM Accounts WHERE UserName = '%s' AND password = SHA1('%s')", pname, escapepass);
mysql_query(query);
mysql_store_result();
new numrows = mysql_num_rows();
if(numrows == 1) LoginAccount(playerid);
if(!numrows)
{
ShowDialog(playerid, 2);
SendClientMessage(playerid, 0xFF0000, "Incorrect password!");
}
mysql_free_result();
}
}
case 3:
{
if(!response)
{
SendClientMessage(playerid, COLOR_GREY, "You decided to cancel, you will now be kicked!");
Kick(playerid);
}
if(response)
{
switch(listitem)
{
case 0:
{
if(!strcmp(CharacterInfo[playerid][0], "None", false))
{
ShowDialog(playerid, 4);
}
else
{
LoginCharacter(playerid, 1);
}
}
case 1:
{
if(!strcmp(CharacterInfo[playerid][1], "None", false))
{
ShowDialog(playerid, 4);
}
else
{
LoginCharacter(playerid, 2);
}
}
case 2:
{
if(!strcmp(CharacterInfo[playerid][2], "None", false))
{
ShowDialog(playerid, 4);
}
else
{
LoginCharacter(playerid, 3);
}
}
case 3:
{
if(!strcmp(CharacterInfo[playerid][3], "None", false))
{
ShowDialog(playerid, 4);
}
else
{
LoginCharacter(playerid, 4);
}
}
case 4:
{
if(!strcmp(CharacterInfo[playerid][4], "None", false))
{
ShowDialog(playerid, 4);
}
else
{
LoginCharacter(playerid, 5);
}
}
}
}
}
case 4:
{
if(strlen(inputtext) > 0 && strlen(inputtext) < 24)
{
new CName[24];
mysql_real_escape_string(inputtext, CName);
if(IsRPName(CName))
{
RegisterCharacter(playerid, CName);
}
else
{
SendClientMessage(playerid, COLOR_GREY, "That is a non-rp name! Please use a valid Firstname_Lastname format.");
ShowDialog(playerid, 4);
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Character length can only go up to 24!");
}
}
case 5:
{
if(!strcmp(inputtext, "Roleplay", true) || !strcmp(inputtext, "Roleplaying", true))
{
SendClientMessage(playerid, COLOR_GREEN, "Correct!");
ShowDialog(playerid, 6);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Incorrect! You've now been kicked.");
Kick(playerid);
}
}
case 6:
{
if(!strcmp(inputtext, "Metagame", true) || !strcmp(inputtext, "Metagaming", true))
{
SendClientMessage(playerid, COLOR_GREEN, "Correct!");
ShowDialog(playerid, 7);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Incorrect! You've now been kicked.");
Kick(playerid);
}
}
case 7:
{
if(!strcmp(inputtext, "Powergame", true) || !strcmp(inputtext, "Powergaming", true))
{
SendClientMessage(playerid, COLOR_GREEN, "Correct!");
ShowDialog(playerid, 8);
}
else
{
SendClientMessage(playerid, COLOR_RED, "Incorrect! You've now been kicked.");
Kick(playerid);
}
}
case 8:
{
switch(listitem)
{
case 0, 2:
{
SendClientMessage(playerid, COLOR_RED, "Incorrect! You've now been kicked.");
Kick(playerid);
}
case 1:
{
SendClientMessage(playerid, COLOR_GREEN, "Correct!");
ShowDialog(playerid, 9);
}
}
}
case 9:
{
switch(listitem)
{
case 0, 1:
{
SendClientMessage(playerid, COLOR_RED, "Incorrect! You've now been kicked.");
Kick(playerid);
}
case 2:
{
SendClientMessage(playerid, COLOR_GREEN, "Correct!");
SendClientMessage(playerid, COLOR_WHITE, "You completed the tutorial, you will now be spawned");
ShowDialog(playerid, 3);
}
}
}
}
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
return 1;
}
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
return 1;
}
public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
{
return 1;
}
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
return 1;
}
public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
{
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ )
{
return 1;
}
public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ )
{
return 1;
}
public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
{
return 1;
}
//------------------------------------------------------------------------[ Timers ]
forward RandomMessageTimer();
public RandomMessageTimer()
{
SendClientMessageToAll(COLOR_GREEN, RandMessages[random(sizeof(RandMessages))]);
return 1;
}
//---------------------[Main Loop - Loops every minute]
task SyncServer[60000]()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerLoggedIn(i))
{
pInfo[i][PlayMinutes] ++;
}
if(pInfo[i][PlayMinutes] >= 60)
{
pInfo[i][PlayHours] ++;
pInfo[i][PlayMinutes] = 0;
GivePaycheck(i);
}
}
}
//---------------------[Business Loop - Loops every minute]
task SyncBusinesses[60000]()
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
if(IsBusinessCreated(i) && IsBusinessOwned(i))
{
bInfo[i][Minutes] ++;
}
if(bInfo[i][Minutes] >= 60 && bInfo[i][Money] < 21000)
{
bInfo[i][Money] += 3500;
}
}
}
//------------------------------------------------------------------------[ Stocks ]
stock GetName(playerid)
{
new pName[24];
GetPlayerName(playerid, pName, sizeof(pName));
return pName;
}
stock RegisterAccount(playerid, passwordstring[])
{
new query[300], pname[24], IP[16];
GetPlayerName(playerid, pname, 24);
GetPlayerIp(playerid, IP, 16);
format(query, sizeof(query), "INSERT INTO Accounts (Username, Password, Character1, Character2, Character3, Character4, Character5, IP) VALUES('%s', SHA1('%s'), 'None', 'None', 'None', 'None', 'None', '%s')", pname, passwordstring, IP);
mysql_query(query);
SendClientMessage(playerid, -1, "You have been registered on this server!");
Logged[playerid] = 1;
for(new i = 0; i < 5; i++)
{
CharacterInfo[playerid][i] = "None";
}
ShowDialog(playerid, 5);
return 1;
}
stock RegisterCharacter(playerid, charactername[24])
{
new query[300];
if(!strcmp(CharacterInfo[playerid][0], "None", false)) CharacterInfo[playerid][0] = charactername;
else if(!strcmp(CharacterInfo[playerid][1], "None", false)) CharacterInfo[playerid][1] = charactername;
else if(!strcmp(CharacterInfo[playerid][2], "None", false)) CharacterInfo[playerid][2] = charactername;
else if(!strcmp(CharacterInfo[playerid][3], "None", false)) CharacterInfo[playerid][3] = charactername;
else if(!strcmp(CharacterInfo[playerid][4], "None", false)) CharacterInfo[playerid][4] = charactername;
format(query, sizeof(query), "INSERT INTO playerdata(name, Username, Cash, PlayHours, PlayMinutes, PositionX, PositionY, PositionZ, Angle, Interior, World, Kills, Deaths, Level) VALUES('%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)", charactername, pInfo[playerid][Username]);
mysql_query(query);
pInfo[playerid][Level] = 1;
SavePlayerCharacters(playerid);
ShowDialog(playerid, 3);
return 1;
}
stock LoginAccount(playerid)
{
new query[300], pname[24], savingstring[24];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT * FROM Accounts WHERE Username = '%s'", pname);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "Character1"); format(CharacterInfo[playerid][0], 24, "%s", savingstring);
mysql_fetch_field_row(savingstring, "Character2"); format(CharacterInfo[playerid][1], 24, "%s", savingstring);
mysql_fetch_field_row(savingstring, "Character3"); format(CharacterInfo[playerid][2], 24, "%s", savingstring);
mysql_fetch_field_row(savingstring, "Character4"); format(CharacterInfo[playerid][3], 24, "%s", savingstring);
mysql_fetch_field_row(savingstring, "Character5"); format(CharacterInfo[playerid][4], 24, "%s", savingstring);
mysql_fetch_field_row(savingstring, "Adminlevel"); pInfo[playerid][Admin] = strval(savingstring);
}
mysql_free_result();
SendClientMessage(playerid, -1, "You have been logged in!");
Logged[playerid] = 1;
ShowDialog(playerid, 3);
return 1;
}
stock LoginCharacter(playerid, characterid)
{
TogglePlayerSpectating(playerid, 0);
new query[300], pname[24], savingstring[20], string[128];
pname = CharacterInfo[playerid][characterid - 1];
format(query, sizeof(query), "SELECT * FROM playerdata WHERE name = '%s'", pname);
mysql_query(query);
mysql_store_result();
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "Cash"); pInfo[playerid][Cash] = strval(savingstring);
mysql_fetch_field_row(savingstring, "PlayHours"); pInfo[playerid][PlayHours] = strval(savingstring);
mysql_fetch_field_row(savingstring, "PlayMinutes"); pInfo[playerid][PlayMinutes] = strval(savingstring);
mysql_fetch_field_row(savingstring, "PositionX"); pInfo[playerid][Pos][0] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "PositionY"); pInfo[playerid][Pos][1] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "PositionZ"); pInfo[playerid][Pos][2] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "Angle"); pInfo[playerid][Pos][3] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "Interior"); pInfo[playerid][Interior] = strval(savingstring);
mysql_fetch_field_row(savingstring, "World"); pInfo[playerid][World] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Kills"); pInfo[playerid][Kills] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Deaths"); pInfo[playerid][Deaths] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Level"); pInfo[playerid][Level] = strval(savingstring);
}
mysql_free_result();
SetPlayerName(playerid, pname);
SetPlayerColor(playerid, COLOR_WHITE);
format(string, sizeof(string), "%s has logged in!", GetRPName(playerid));
SendClientMessageToAllEx(COLOR_RED, string);
SetSpawnInfo(playerid, 0, 0, pInfo[playerid][Pos][0], pInfo[playerid][Pos][1], pInfo[playerid][Pos][2], pInfo[playerid][Pos][3], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
IsCharacter[playerid] = 1;
if(pInfo[playerid][Admin] >= 1)
{
format(string, sizeof(string), "You logged in as a level %i admin!", pInfo[playerid][Admin]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
return 1;
}
stock SavePlayerCharacters(playerid)
{
if(Logged[playerid] == 1)
{
new query[200];
format(query, sizeof(query), "UPDATE Accounts SET Character1='%s', Character2='%s', Character3='%s', Character4='%s', Character5='%s', Adminlevel=%i WHERE Username='%s'", \
CharacterInfo[playerid][0], CharacterInfo[playerid][1], CharacterInfo[playerid][2], CharacterInfo[playerid][3], CharacterInfo[playerid][4], pInfo[playerid][Admin], pInfo[playerid][Username]);
mysql_query(query);
}
return 1;
}
stock SaveCharacter(playerid)
{
if(Logged[playerid] == 1)
{
new query[300], pname[24], string[300];
pname = GetName(playerid);
format(query, sizeof(query), "UPDATE playerdata SET Cash=%i, PlayHours=%i, PlayMinutes=%i, PositionX=%f, PositionY=%f, PositionZ=%f, Angle=%f, ", pInfo[playerid][Cash], pInfo[playerid][PlayHours],pInfo[playerid][PlayMinutes], pInfo[playerid][Pos][0], pInfo[playerid][Pos][1], pInfo[playerid][Pos][2], pInfo[playerid][Pos][3]);
format(string, sizeof(string), "Interior=%i, World=%i, Kills=%i, Deaths=%i, Level=%i WHERE name='%s'", pInfo[playerid][Interior], pInfo[playerid][World], pInfo[playerid][Kills], pInfo[playerid][Deaths], pInfo[playerid][Level], pname);
strcat(query, string);
mysql_query(query);
}
return 1;
}
stock ShowDialog(playerid, dialogid)
{
new string[128];
switch(dialogid)
{
case 1:
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!","Register","Cancel");
}
case 2:
{
ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD, "Login","Your user is {FF0000}registered{FFFFFF}! Please {0000FF}login{FFFFFF} with your password below!","Login","Cancel");
}
case 3:
{
format(string, sizeof(string), "%s\n%s\n%s\n%s\n%s", CharacterInfo[playerid][0],CharacterInfo[playerid][1],CharacterInfo[playerid][2],CharacterInfo[playerid][3],CharacterInfo[playerid][4]);
ShowPlayerDialog(playerid, 3, DIALOG_STYLE_LIST, "Load Character", string, "Select", "Cancel");
}
case 4:
{
ShowPlayerDialog(playerid, 4, DIALOG_STYLE_INPUT, "Character Creation","Please type the name of the character you want to create below!","Create","Cancel");
}
case 5:
{
ShowPlayerDialog(playerid, 5, DIALOG_STYLE_INPUT, "Tutorial - Part 1", "What does RP stand for? ((Do not use a space))", "Continue", "Cancel");
}
case 6:
{
ShowPlayerDialog(playerid, 6, DIALOG_STYLE_INPUT, "Tutorial - Part 2", "What does MG stand for? ((Do not use a space))", "Continue", "Cancel");
}
case 7:
{
ShowPlayerDialog(playerid, 7, DIALOG_STYLE_INPUT, "Tutorial - Part 3", "What does PG stand for? ((Do not use a space))", "Continue", "Cancel");
}
case 8:
{
ShowPlayerDialog(playerid, 8, DIALOG_STYLE_LIST, "What is the correct way to take out a gun?", "/me reaches into his asshole, retreiving a minigun\n* Kindred reaches into his back pocket, removing a shiny new deagle\n* Kindred asspulls a gun and shoots","Answer", "Cancel");
}
case 9:
{
ShowPlayerDialog(playerid, 9, DIALOG_STYLE_LIST, "What is the correct use of /do?", "/do takes out a weapon and reloads it\n/do Dude, what the hell?\n/do The cigarette drops on the floor", "Continue", "Cancel");
}
}
return 1;
}
stock IsRPName(const name[], max_underscores = 1)
{
new underscores = 0;
if (name[0] < 'A' || name[0] > 'Z') return false; // First letter is not capital
for(new i = 1; i < strlen(name); i++)
{
if(name[i] != '_' && (name[i] < 'A' || name[i] > 'Z') && (name[i] < 'a' || name[i] > 'z')) return false; // a-zA-Z_
if( (name[i] >= 'A' && name[i] <= 'Z') && (name[i - 1] != '_') ) return false; // unneeded capital letter
if(name[i] == '_')
{
underscores++;
if(underscores > max_underscores || i == strlen(name)) return false; // More underlines than limit, or underline at the last pos
if(name[i + 1] < 'A' || name[i + 1] > 'Z') return false; // Not a capital letter after underline
}
}
if (underscores == 0) return false; // No underline detected
return true;
}
stock GivePaycheck(playerid)
{
new string[128];
SendClientMessageEx(playerid, COLOR_YELLOW, "You recieved a paycheck!");
format(string, sizeof(string), "Name: %s, Paycheck: %i", GetName(playerid), pInfo[playerid][Paycheck] + 700 * pInfo[playerid][Level]);
pInfo[playerid][Cash] = pInfo[playerid][Paycheck];
GivePlayerMoney(playerid, pInfo[playerid][Paycheck] + 700 * pInfo[playerid][Level]);
pInfo[playerid][Paycheck] = 0;
return 1;
}
stock GetRPName(playerid)
{
new playersName[MAX_PLAYER_NAME];
playersName = GetName(playerid);
strreplace(playersName, '_', ' ');
return playersName;
}
stock strreplace(string[], oldchar, newchar)
{
for(new i = 0; i < strlen(string); i++)
{
if(string[i] == oldchar)
{
string[i] = newchar;
}
}
}
stock SendClientMessageEx(playerid, color, msg[])
{
if(Logged[playerid] == 1 && IsCharacter[playerid] == 1)
{
SendClientMessage(playerid, color, msg);
}
return 1;
}
stock SendClientMessageToAllEx(color, msg[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(Logged[i] == 1 && IsCharacter[i] == 1)
{
SendClientMessage(i, color, msg);
}
}
return 1;
}
stock IsPlayerLoggedIn(playerid)
{
if(Logged[playerid] == 1 && IsCharacter[playerid] == 1)
{
return true;
}
else return false;
}
stock SendLocalMessage(playerid,color,msg[],Float:radius)
{
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i,radius,x,y,z)) SendClientMessageEx(i,color,msg);
}
return 1;
}
stock UpdateBusinessOwner(BizID, BizOwner[])
{
new query[150];
format(query, sizeof(query), "UPDATE businessdata SET Owner='%s' WHERE BusinessID=%i", BizOwner, bInfo[BizID][ID]);
mysql_query(query);
UpdateBusiness(BizID);
return 1;
}
stock UpdateBusiness(BizID)
{
new query[300], string[128];
format(query, sizeof(query), "UPDATE businessdata SET Price=%i, EnterX=%f, EnterY=%f, EnterZ=%f, ExitX=%f, ExitY=%f, ExitZ=%f, Interior=%i, World=%i, ", bInfo[BizID][Price], bInfo[BizID][EnterX], bInfo[BizID][EnterY], bInfo[BizID][EnterZ], bInfo[BizID][ExitX], bInfo[BizID][ExitY], bInfo[BizID][ExitZ], bInfo[BizID][Interior], bInfo[BizID][World]);
format(string, sizeof(string), "Text='%s', Owner='%s', Minutes=%i, Money=%i WHERE BusinessID=%i", bInfo[BizID][Text], bInfo[BizID][Owner], bInfo[BizID][Minutes], bInfo[BizID][Money], bInfo[BizID][ID]);
strcat(query, string);
mysql_query(query);
ReloadBusinesses();
return 1;
}
stock CreateBusiness(BizID, BizPrice, BizEnterX, BizEnterY, BizEnterZ, BizExitX, BizExitY, BizExitZ, BizInterior, BizWorld, BizText[])
{
new query[300];
format(query, sizeof(query), "INSERT INTO businessdata (BusinessID, Price, EnterX, EnterY, EnterZ, ExitX, ExitY, ExitZ, Interior, World, Text, Owner, Minutes, Money) VALUES(%i, %i, %f, %f, %f, %f, %f, %f, %i, %i, '%s', 'None', 0, 0)", BizID, BizPrice, BizEnterX, BizEnterY, BizEnterZ, BizExitX, BizExitY, BizExitZ, BizInterior, BizWorld, BizText);
mysql_query(query);
ReloadBusinesses();
return 1;
}
stock ReloadBusinesses()
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
DestroyDynamic3DTextLabel(bInfo[i][Label]);
DestroyDynamicPickup(bInfo[i][Pickup]);
}
LoadBusinesses();
return 1;
}
stock LoadBusinesses()
{
for(new i = 0; i < MAX_BUSINESSES; i++)
{
new query[600], savingstring[24], string[128];
format(query, sizeof(query), "SELECT * FROM businessdata WHERE BusinessID = %i", i);
mysql_query(query);
while(mysql_fetch_row_format(query,"|"))
{
mysql_fetch_field_row(savingstring, "BusinessID"); bInfo[i][ID] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Price"); bInfo[i][Price] = strval(savingstring);
mysql_fetch_field_row(savingstring, "EnterX"); bInfo[i][EnterX] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "EnterY"); bInfo[i][EnterY] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "EnterZ"); bInfo[i][EnterZ] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "ExitX"); bInfo[i][ExitX] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "ExitY"); bInfo[i][ExitY] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "ExitZ"); bInfo[i][ExitZ] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "Interior"); bInfo[i][Interior] = strval(savingstring);
mysql_fetch_field_row(savingstring, "World"); bInfo[i][World] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Text"); bInfo[i][Text] = savingstring;
mysql_fetch_field_row(savingstring, "Owner"); bInfo[i][Owner] = savingstring;
mysql_fetch_field_row(savingstring, "Minutes"); bInfo[i][Minutes] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Money"); bInfo[i][Money] = strval(savingstring);
}
new BizName[24]; format(BizName, 24, "%s", bInfo[i][Text]);
strreplace(BizName, '_', ' ');
if(!strcmp(bInfo[i][Owner], "None", false)) format(string, sizeof(string), "%s [Unowned]\nPrice: %i\nType /enter or push f to enter the building", BizName, bInfo[i][Price]);
else format(string, sizeof(string), "%s [Owner]: %s\nType /enter or push f to enter the building", bInfo[i][Text], bInfo[i][Owner]);
bInfo[i][Label] = CreateDynamic3DTextLabel(string, COLOR_YELLOW, bInfo[i][EnterX],bInfo[i][EnterY], bInfo[i][EnterZ], 12, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1);
bInfo[i][Pickup] = CreateDynamicPickup(1272, 1, bInfo[i][EnterX], bInfo[i][EnterY], bInfo[i][EnterZ], 0);
if(IsBusinessOwned(i)) printf("Business ID %i has loaded; Named: %s", i, bInfo[i][Text]);
}
return 1;
}
stock DeleteBusiness(businessid)
{
new query[100];
format(query, sizeof(query), "DELETE FROM businessdata WHERE BusinessID = %i", businessid);
mysql_query(query);
ReloadBusinesses();
return 1;
}
stock IsBusinessCreated(businessid)
{
new query[200];
format(query, sizeof(query), "SELECT * FROM `businessdata` WHERE BusinessID = %i", businessid);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
mysql_free_result();
if(!rows) return false;
else return true;
}
stock IsBusinessOwned(businessid)
{
new query[200];
format(query, sizeof(query), "SELECT Owner FROM 'businessdata' WHERE BusinessID = %i", businessid);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
mysql_free_result();
if(!rows) return false;
else return true;
}