Код:
//==============================================================================
//==============================================================================
//====== ======= ============= ================
//========== ============ ====================== =========================
//========== ============ ====================== =========================
//========== ============ ================= ====================
//========== ============ ====================== =========================
//========== ============ ====================== =========================
//========== ============ ============= =============
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//******************************************************************************
// *TDynamic Business System*
//******************************************************************************
//Hello SA-MP members. As you all know I am Tee. This Dynamic Business system was
//made by me because I wanted an easier way to create business on my server than
//to save the positions, create checkpoints, and edit it all in the script.
//I decided to make this filterscript and it worked so I wanted you all to have
//it. Here it is.
//I don't really know what to call it so I named it,"TDynamic Business System".
//Please do not take credit for it.
// |------Creadits:----|
// | Zeex - Zcmd |
// | Darco - Dini |
// | ****** - Sscanf2 |
// | Tee - The FS |
// Incognito- Streamer plugin.
// |-------------------|
// *****ADVERTISMENT*****
//------------------------------------------------------------------------------
// Majestic - Gaming Roleplay
// 213.5.176.158:7781
//------------------------------------------------------------------------------
#include <a_samp>
#include <zcmd>
#include <sscanf>
#include <dini>
#include <streamer>
#define PAYDAY_TIME 1800000
#define MAX_BUSS 100
#define NO_OWNER "INVALID_PLAYER_ID"
#define CASE_SENSETIVE true
#define White 0xFFFFFFFF
#define Yellow 0xFFFF00FF
#define Grey 0xC0C0C0FF
#define Red 0xFF0000AA
#define Green 0x45E01FFF
new cpid[32];
new String[200];
new file[128];
new Name[MAX_PLAYER_NAME];
new Float:X,Float:Y,Float:Z;
new Label[128];
enum Business
{
CP,
Text3D:bLabel,
Cost,
Payout,
bName[128],
}
new BusinessInfo[MAX_BUSS][Business];
forward Payday();
public OnFilterScriptInit()
{
print("___________________________");
print("--Dynamic Business Loaded--");
print(" --Made by: Tee-- ");
print("___________________________");
LoadBusinesses();
SetTimer("Payday",PAYDAY_TIME,true);
return 1;
}
public OnFilterScriptExit()
{
UnloadBusinesses();
return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
for(new i = 0;i<MAX_BUSS;i++)
{
if(checkpointid == BusinessInfo[i][CP])
{
cpid[playerid] = i;
format(file,sizeof(file),"Business/%i.ini",i);
if(dini_Int(file, "HasOwner") == 0)
{
ShowPlayerDialog(playerid,219,DIALOG_STYLE_MSGBOX,"Buy Business","Do you want to buy this businesses?","Buy","Cancel");
}
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 219)
{
if(response == 1)
{
format(file,sizeof(file),"Business/%i.ini",cpid[playerid]);
if(GetPlayerBusinessID(playerid) > -1)return SendClientMessage(playerid,Red,"You already own a business");
if(dini_Int(file,"Cost") > GetPlayerMoney(playerid))return SendClientMessage(playerid,Red,"You do not have enough cash to buy this business.");
GivePlayerMoney(playerid, -dini_Int(file,"Cost"));
GetPlayerName(playerid,Name,sizeof(Name));
dini_Set(file, "Owner",Name);
dini_IntSet(file, "OwnedBus",1);
dini_IntSet(file, "HasOwner",1);
format(Label, sizeof(Label), "Business Name: %s\nOwner: %s\nCost: $%i\nPayout: $%i",dini_Get(file, "Name"),dini_Get(file, "Owner"),dini_Int(file, "Cost"),dini_Int(file, "Payout"));
Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
format(String,sizeof(String),"You have successfully purchased the %s.",dini_Get(file, "Name"));
SendClientMessage(playerid,Green,String);
}
if(response == 0)
{
SendClientMessage(playerid,Yellow,"You chose not to buy this business");
}
}
if(dialogid == 220)
{
if(response == 1)
{
GetPlayerName(playerid,Name,sizeof(Name));
format(file,sizeof(file),"Business/%i.ini",GetPlayerBusinessID(playerid));
format(Label, sizeof(Label), "Business Name: %s\nOwner: No Owner\nCost: $%i\nPayout: $%i",dini_Get(file, "Name"),dini_Int(file, "Cost"),dini_Int(file, "Payout"));
Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
dini_Set(String, "Owner","No Owner");
dini_IntSet(file, "Cost",dini_Int(file, "Cost"));
dini_IntSet(file, "Payout",dini_Int(file, "Payout"));
dini_IntSet(file, "OwnedBus",0);
dini_IntSet(file, "HasOwner",0);
GivePlayerMoney(playerid,dini_Int(file, "Cost")/4);
SendClientMessage(playerid,Green,"You have sold your business and recieved 25 percent of the price.");
}
}
return 1;
}
// This command is used to create the business.
COMMAND:createbus(playerid, params[])
{
new busid,cost,payout,name[128];
if(!IsPlayerAdmin(playerid))return 0;
if(sscanf(params,"iiis",busid,cost,payout,name))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /createbus [busid] [cost] [payout] [name]");
format(file,sizeof(file),"Business/%i.ini",busid);
if(busid < 0)return SendClientMessage(playerid,Red,"Business IDs cannot be less than 0.");
if(dini_Exists(String))return SendClientMessage(playerid,Red,"That business ID is already in use.");
BusinessInfo[busid][bName] = name;
BusinessInfo[busid][Cost] = cost;
BusinessInfo[busid][Payout] = payout;
GetPlayerPos(playerid, X, Y, Z);
dini_Create(file);
dini_Set(file, "Name", name);
dini_Set(file, "Owner","No Owner");
dini_IntSet(file, "Cost",cost);
dini_IntSet(file, "Payout",payout);
dini_FloatSet(file, "BusX", X);
dini_FloatSet(file, "BusY", Y);
dini_FloatSet(file, "BusZ", Z);
dini_IntSet(file, "World",GetPlayerVirtualWorld(playerid));
dini_IntSet(file, "Interior",GetPlayerInterior(playerid));
dini_IntSet(file, "OwnedBus",0);
dini_IntSet(file, "HasOwner",0);
BusinessInfo[busid][CP] = CreateDynamicCP(X,Y,Z,1.0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),-1,50.0);
format(Label, sizeof(Label), "Business Name: %s\nOwner: No Owner\nCost: $%i\nPayout: $%i", name,cost,payout);
BusinessInfo[busid][bLabel] = Create3DTextLabel(Label,White,X,Y,Z,100.0,GetPlayerVirtualWorld(playerid),1);
format(String,sizeof(String),"BusinessCreated. Name: %s | Cost: $%i | Payout: $%i | Owner: No Owner",name,cost,payout);
SendClientMessage(playerid,Green,String);
return 1;
}
//This command is used to delete a business.
COMMAND:deletebusiness(playerid, params[])
{
new busid;
if(!IsPlayerAdmin(playerid)) return 0;
if(sscanf(params, "i", busid)) return SendClientMessage(playerid,0xC0C0C0FF,"Usage: /deletebusiness [busid]");
format(file,sizeof(file),"Business/%i.ini",busid);
if(!dini_Exists(file))return SendClientMessage(playerid,Red,"That businessid does not exists.");
format(String,sizeof(String),"You have successfully deleted a business. ID: %i.",busid);
SendClientMessage(playerid,Yellow,String);
DestroyDynamicCP(BusinessInfo[busid][CP]);
Delete3DTextLabel(BusinessInfo[busid][bLabel]);
dini_Remove(file);
return 1;
}
//This command is used to sell a business (only owners can use it).
COMMAND:sellbus(playerid, params[])
{
if(GetPlayerBusinessID(playerid) == -1)return SendClientMessage(playerid,Red,"You do not own a business.");
ShowPlayerDialog(playerid,220,DIALOG_STYLE_MSGBOX,"Sell Business","Do you want to sell your businesses?","Sell","Cancel");
return 1;
}
//This function gets the owner of a specific business.
stock GetBusOwner(bussid)
{
new owner[MAX_PLAYER_NAME];
format(owner, MAX_PLAYER_NAME, NO_OWNER);
format(String, sizeof(String), "Business/%i.ini", bussid);
if(dini_Exists(String))
{
format(owner, MAX_PLAYER_NAME, "%s", dini_Get(String, "Owner"));
return owner;
}
return owner;
}
//This function gets a business ID (it also tells if a player owns a business or not).
stock GetPlayerBusinessID(playerid)
{
for(new i = 0;i<MAX_BUSS;i++)
{
format(String,sizeof(String),"Business/%i.ini",i);
if(dini_Exists(String))
{
GetPlayerName(playerid,Name,sizeof(Name));
if(strcmp(Name,dini_Get(String,"Owner"),false) == 0)
{
return i;
}
}
}
return -1;
}
//This command removes a player from owning a business.
COMMAND:debus(playerid, params[])
{
new id;
if(!IsPlayerAdmin(playerid))return 0;
if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /debus [id]");
if(GetPlayerBusinessID(id) == -1)return SendClientMessage(playerid,Red,"That player does not own a business.");
format(String,sizeof(String),"Business/%i.ini",GetPlayerBusinessID(id));
format(Label, sizeof(Label), "Business Name: %s\nOwner: No Owner\nCost: $%i\nPayout: $%i",dini_Get(String, "Name"),dini_Int(String, "Cost"),dini_Int(String, "Payout"));
Update3DTextLabelText(BusinessInfo[GetPlayerBusinessID(id)][bLabel],White,Label);
dini_Set(String, "Owner","No Owner");
dini_IntSet(String, "Cost",dini_Int(String, "Cost"));
dini_IntSet(String, "Payout",dini_Int(String, "Payout"));
dini_IntSet(String, "OwnedBus",0);
dini_IntSet(String, "HasOwner",0);
GivePlayerMoney(id,dini_Int(String, "Cost")/4);
format(String, sizeof(String), "You have removed %s as the owner of his/her business.",Name);
SendClientMessage(playerid,Red, String);
return 1;
}
//This function loads every business.
stock LoadBusinesses()
{
new count = 0;
for(new i=0; i<MAX_BUSS; i++)
{
format(String,sizeof(String),"Business/%i.ini",i);
if(dini_Exists(String))
{
BusinessInfo[i][CP] = CreateDynamicCP(dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ"),1.0,dini_Int(String, "World"),dini_Int(String, "Interior"),-1,100.0);
if(!strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
{
format(Label, sizeof(Label), "Business Name: %s\nOwner: No Owner\nCost: $%i\nPayout: $%i",dini_Get(String, "Name"),dini_Int(String, "Cost"),dini_Int(String, "Payout"));
BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
}
if(strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
{
format(Label, sizeof(Label), "Business Name: %s\nOwner: %s\nCost: $%i\nPayout: $%i",dini_Get(String, "Name"), dini_Get(String, "Owner"),dini_Int(String, "Cost"),dini_Int(String, "Payout"));
BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
}
count++;
}
}
return printf("Total Businesses Loaded: %i",count);
}
//This function gets the last bused business ID.
stock GetLastBusinessID()
{
new count = 0;
for(new i=0; i<MAX_BUSS; i++)
{
format(String,sizeof(String),"Business/%i.ini",i);
{
count++;
}
}
return count;
}
//This function unloads every business.
stock UnloadBusinesses()
{
for(new i=0; i<MAX_BUSS; i++)
{
Delete3DTextLabel(BusinessInfo[i][bLabel]);
DestroyDynamicCP(BusinessInfo[i][CP]);
}
return 1;
}
//This is used by RCON admins. Either to debug or to force a payday.
COMMAND:forcepayday(playerid,params[])
{
if(!IsPlayerAdmin(playerid))return 0;
SendClientMessage(playerid,Grey,"You have forced a payday.");
Payday();
return 1;
}
//This function is the payday (to pay the owners).
public Payday()
{
new id[32];
new Owner[258];// I know it's huge but if it goes lower than this then you'll get an error.
Owner = dini_Get(String,"Owner");
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
id[i] = Owner[i];
format(String,sizeof(String),"Business/%i.ini",i);
{
SendClientMessage(Owner[i],Yellow,"[Businees Update] You have earned from your business");
GivePlayerMoney(Owner[i],dini_Int(String,"Payout"));
}
}
}
}
Each command I'm using in server [FROM FS] doesnt work , And if thats important : I'm using - zcmd iclude...