enum biz_Lists
{
biz_T,
biz_N[50],
}
new BizTypeList[][biz_Lists] = {
{BUSINESS_TYPE_BANK, "Bank"},
{BUSINESS_TYPE_247, "Grocery Store"},
BizTypeList[biz_T] = bizType;
format(iStr, sizeof(iStr), "%s", BizTypeList[biz_T][biz_N]);
Hey guys, been trying to use enums for database storing purposes, anywho here's the enum(some of it):
PHP код:
PHP код:
would love for some help! Thanks :> |
#include <a_samp>
/*enum biz_Lists
{
biz_T,
biz_N[50],
}*/
enum bizType
{
BUSINESS_TYPE_BANK,
BUSINESS_TYPE_247
}
new BizTypeList[2][] =
{
"Bank",
"Grocery Store"
};
new biz[bizType];
main()
{
printf("%s %s", BizTypeList[0][0], BizTypeList[1][0]);
}
enum biz_Lists
{
biz_T,
biz_N[50],
}
new BizTypeList[10][biz_Lists]; //We make this to 10...so u can max create 10 Biz (index: 0-9)
new biz_index; //We will need this to accsess everytime the Variable
//To Create one Biz we do sth like this
if(biz_index >= sizeof(BizTypeList)) return SendClientMessage(playerid,-1,"Biz is full!"); //PS: sizeof(BizTypeList) = 10
BizTypeList[biz_index][biz_T] = BUSINESS_TYPE_BANK; //For example
format(BizTypeList[biz_index][biz_N],50, "Bank"); //So we set this
biz_index++; //we count this up...so the next one we insert is an index above
/*
To read this stuff out...you need an index
In my example the Bank is at index 0. Cause the Variable biz_index was zero.
*/
//So we do sth like this:
new string[50],type;
format(string,50,BizTypeList[0][biz_N]); //Now string equals Bank
type = BizTypeList[0][biz_T]; //And type equals BUSINESS_TYPE_BANK
The problem is you need an index for that.
For example: PHP код:
|
COMMAND:checkbiztype(playerid, params[])
{
new iBiz;
if( sscanf ( params, "d", iBiz)) return SCP(playerid, "[BizID]");
new BizTypeID = BusinessInfo[iBiz][bType];
new iTypeName = BizTypeList[BizTypeID][biz_N];
format(iStr, sizeof(iStr), "String: %s || Int: %d", iTypeName, iTypeName);
SendClientMessage(playerid, COLOR_WHITE, iStr);
return 1;
}
COMMAND:checkbiztype(playerid, params[])
{
new index,string[128]; //Use this..you should avoid global strings...
if( sscanf ( params, "d", index)) return SCP(playerid, "[BizID]");
if(index < 0 || index >= sizeof(BusinessInfo)) return SCP(playerid,"Index out of Bounds!");
format(string, sizeof(string), "String: %s || Int: %d", getBizName(BusinessInfo[index][bType]), BusinessInfo[index][bType]);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
stock getBizName(index)
{
new name[50];
switch(index)
{
case BUSINESS_TYPE_BANK: name="Bank";
case BUSINESS_TYPE_247: name="Grocery Store";
}
return name;
}
//Edit:
Oh god...now i see what you wanna do... Just make it like this: PHP код:
|
stock CreateBusiness(bizOwner[], bizType, Float:bizX, Float:bizY, Float:bizZ, Interior, VirtualWorld)
{
// Missing codelines ---> bizType is an int which refers to the ID of a biz type, which is used to create business from the BizTypeList..
new iTypeName = BizTypeList[bizType][biz_N];
mysql_format(MySQLPipeline, iQuery, sizeof(iQuery), "INSERT INTO `businessinfo` (`ID`, `Owner`, `Type`, `TypeName`, `X`, `Y`, `Z`, `CompsFlag`, `Interior`, `VirtualWorld`, `Street`) VALUES (%d, '%e', %d, '%e', %f, %f, %f, %d, %d, %d, '%e')", businessid, bizOwner, bizType, iTypeName, bizX, bizY, bizZ, compsF, Interior, VirtualWorld, zone);
mysql_tquery(MySQLPipeline, iQuery);
// global:
new const BizTypeList[][] =
{
"Bank",
"Grocery Store",
"Casino",
"Gas Station",
"Hardware Store",
"Night club",
"Pub",
"Strip Club",
"Gun Store",
"Pizza Stack",
"Burger Shot",
"Cluckin' Bell",
"Cafe",
"Clothes Store",
"Restaurant",
"Pay 'N' Spray",
"Drug Factory",
"Government Tax Income",
"Refinary Income",
"Airport",
"Taxi Station",
"Vehicle Rent",
"Driver Business",
"Stadium Business",
"Paintball",
"Advertisement Tower",
"Phone Provider",
"Vehicle Exports",
"Drug Store",
"Bike Dealership",
"Heavy Dealership",
"Car Dealership",
"Luxus Dealership",
"Noobie Dealership",
"Air Dealership",
"Boat Dealership",
"Job Dealership",
"Wheel Mod Shop",
"Toy Store",
"Appartment Complex",
"Hotel",
"Vehicle Register"
}
BizTypeList[biz_type_here]
You only need the strings then and the type is the index of the array:
PHP код:
pawn Код:
|
Tho I still need the Businesses_Type_Bank(etc) defines as I'm using these in the biz system. I just need a function to extract the string from the enum :S
|