Skip to content

Instantly share code, notes, and snippets.

@earlwlkr
Last active August 29, 2015 14:13
Show Gist options
  • Save earlwlkr/22da8e46dc48f6a58177 to your computer and use it in GitHub Desktop.
Save earlwlkr/22da8e46dc48f6a58177 to your computer and use it in GitHub Desktop.
/*
Vehicle Shop Filterscript - By Mark
Commands:
- /vehshop: hien shop xe
Huong dan:
* Cai dat:
- Tai include mSelection
- Copy tu dong 25 den dong 47 bo vao gamemode chinh
- Compile filterscript va them ten FS vao server.cfg
* Them/ Sua bang gia xe:
- Trong mang vehshop_price_list (co dang {ID, gia})
*/
#include <a_samp>
#include <YSI\y_commands>
#include <YSI\y_iterate>
#include <YSI\y_colours>
#include <mSelection>
// Copy tu dong 25 den dong 47 bo vao gamemode chinh
/*
forward UpdateCoin(playerid, new_amount);
public UpdateCoin(playerid, new_amount)
{
if (IsPlayerConnected(playerid))
{
// Thay 'pCoin' bang ten bien chua so luong coin.
PlayerInfo[playerid][pCoin] = new_amount;
}
return 1;
}
forward GetPlayerCoin(playerid);
public GetPlayerCoin(playerid)
{
return PlayerInfo[playerid][pCoin];
}
forward AddPlayerVehicle(playerid, modelid, Float: x, Float: y, Float: z, Float: angle, color1, color2, price);
public AddPlayerVehicle(playerid, modelid, Float: x, Float: y, Float: z, Float: angle, color1, color2, price)
{
CreatePlayerVehicle(playerid, GetPlayerFreeVehicleId(playerid), modelid, x, y, z, angle, color1, color2, price);
return 1;
}
*/
// Ten column chua so coin cua nguoi choi.
#define COIN_COLUMN_NAME "Coin"
// Ten table chua column coin.
#define COIN_TABLE_NAME "accounts"
// Ten file luu thong tin ket noi MySQL.
#define MYSQL_CONFIG_FILE "mysql.cfg"
// Gia tien mac dinh cua phuong tien (neu khong co trong price list).
#define DEFAULT_VEHICLE_PRICE 500
#define VEHICLESHOP_MENU 1
enum VEHSHOP_DATA
{
VD_VEH_ID,
VD_PRICE
};
// Bang gia xe.
new vehshop_price_list[][VEHSHOP_DATA] = {
// Theo dang: {ID, gia_tien}
{401, 500},
{408, 500},
{418, 500},
{422, 500},
{424, 500},
{429, 500},
{434, 500},
{439, 500},
{442, 500},
{451, 500},
{458, 500},
{470, 500},
{539, 500},
{477, 500},
{483, 500},
{481, 500},
{489, 500},
{495, 500},
{491, 500},
{494, 500},
{502, 500},
{503, 500},
{496, 500},
{504, 500},
{506, 500},
{510, 500},
{565, 500},
{516, 500},
{527, 500},
{533, 500},
{534, 500},
{535, 500},
{568, 500},
{541, 500},
{559, 500},
{560, 500},
{562, 500},
{587, 500},
{603, 500},
{522, 500},
{461, 500},
{462, 500},
{463, 500},
{468, 500},
{521, 500}
};
#define GetVehicleNameByModelID(%1) \
pure_unpack(VehicleName[%1 - 400])
new const
VehicleName[212][24 char] =
{
!"Landstalker", !"Bravura", !"Buffalo", !"Linerunner", !"Perennial", !"Sentinel",
!"Dumper", !"Firetruck" , !"Trashmaster" , !"Stretch", !"Manana", !"Infernus",
!"Voodoo", !"Pony", !"Mule", !"Cheetah", !"Ambulance", !"Leviathan", !"Moonbeam",
!"Esperanto", !"Taxi", !"Washington", !"Bobcat", !"Mr Whoopee", !"BF Injection",
!"Hunter", !"Premier", !"Enforcer", !"Securicar", !"Banshee", !"Predator", !"Bus",
!"Rhino", !"Barracks", !"Hotknife", !"Trailer", !"Previon", !"Coach", !"Cabbie",
!"Stallion", !"Rumpo", !"RC Bandit", !"Romero", !"Packer", !"Monster", !"Admiral",
!"Squalo", !"Seasparrow", !"Pizzaboy", !"Tram", !"Trailer", !"Turismo", !"Speeder",
!"Reefer", !"Tropic", !"Flatbed", !"Yankee", !"Caddy", !"Solair", !"Berkley's RC Van",
!"Skimmer", !"PCJ-600", !"Faggio", !"Freeway", !"RC Baron", !"RC Raider", !"Glendale",
!"Oceanic", !"Sanchez", !"Sparrow", !"Patriot", !"Quad", !"Coastguard", !"Dinghy",
!"Hermes", !"Sabre", !"Rustler", !"ZR-350", !"Walton", !"Regina", !"Comet", !"BMX",
!"Burrito", !"Camper", !"Marquis", !"Baggage", !"Dozer", !"Maverick", !"News Chopper",
!"Rancher", !"FBI Rancher", !"Virgo", !"Greenwood", !"Jetmax", !"Hotring", !"Sandking",
!"Blista Compact", !"Police Maverick", !"Boxville", !"Benson", !"Mesa", !"RC Goblin",
!"Hotring Racer", !"Hotring Racer", !"Bloodring Banger", !"Rancher", !"Super GT",
!"Elegant", !"Journey", !"Bike", !"Mountain Bike", !"Beagle", !"Cropdust", !"Stunt",
!"Tanker", !"RoadTrain", !"Nebula", !"Majestic", !"Buccaneer", !"Shamal", !"Hydra",
!"FCR-900", !"NRG-500", !"HPV1000", !"Cement Truck", !"Tow Truck", !"Fortune", !"Cadrona",
!"FBI Truck", !"Willard", !"Forklift", !"Tractor", !"Combine", !"Feltzer", !"Remington",
!"Slamvan", !"Blade", !"Freight", !"Streak", !"Vortex", !"Vincent", !"Bullet", !"Clover",
!"Sadler", !"Firetruck", !"Hustler", !"Intruder", !"Primo", !"Cargobob", !"Tampa",
!"Sunrise", !"Merit", !"Utility Truck", !"Nevada", !"Yosemite", !"Windsor", !"Monster",
!"Monster", !"Uranus", !"Jester", !"Sultan", !"Stratum", !"Elegy", !"Raindance", !"RCTiger",
!"Flash", !"Tahoma", !"Savanna", !"Bandito", !"Freight", !"Trailer", !"Kart", !"Mower",
!"Dune", !"Sweeper", !"Broadway", !"Tornado", !"AT-400", !"DFT-30", !"Huntley",
!"Stafford", !"BF-400", !"Newsvan", !"Tug", !"Trailer", !"Emperor", !"Wayfarer", !"Euros",
!"Hotdog", !"Club", !"Trailer", !"Trailer", !"Andromada", !"Dodo", !"RC Cam", !"Launch",
!"Police Car LSPD", !"Police Car SFPD", !"Police Car LVPD", !"Police Ranger",
!"Picador", !"S.W.A.T. Van", !"Alpha", !"Phoenix", !"Glendale", !"Sadler",
!"Luggage Trailer", !"Luggage Trailer", !"Stair Trailer", !"Boxville", !"Farm Plow",
!"Utility Trailer"
};
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Vehicle Shop by Mark loaded");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
print("\n--------------------------------------");
print(" Vehicle Shop by Mark unloaded");
print("--------------------------------------\n");
return 1;
}
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
// Xu ly khi nguoi choi nhap chon xe tu bang shop.
if (extraid == VEHICLESHOP_MENU)
{
if (response)
{
new
player_coins = load_player_coin(playerid),
name[MAX_PLAYER_NAME],
price,
Float: pos[4],
message[84];
// Lay gia tien cua phuong tien (mac dinh 500 coin).
price = get_vehicle_price(modelid);
if (player_coins < price)
{
format(message, sizeof (message), "<!> Ban khong co du tien (gia: %d coin).", price);
return SendClientMessage(playerid, X11_LIGHT_GREY, message);
}
// Tru gia tien vao so coin cua nguoi choi.
player_coins -= price;
// Lay tien va vi tri nguoi choi.
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
GetPlayerFacingAngle(playerid, pos[3]);
// Goi ham da bo vao trong gamemode de tao xe trong mode chinh.
CallRemoteFunction("AddPlayerVehicle", "iiffffiii", playerid, modelid, pos[0], pos[1], pos[2], pos[3], 1, 1, 2000000);
// In thong bao cho nguoi choi.
format(message, sizeof (message), "Ban da mua thanh cong chiec xe %s voi gia %d coin.", GetVehicleNameByModelID(modelid), price);
SendClientMessage(playerid, X11_WHITE, message);
// Luu log.
format(message, sizeof (message), "[VEHSHOP] %s da mua %s (%i) voi gia %d coin.", name, GetVehicleNameByModelID(modelid), modelid, price);
save_log("logs/vehshop.log", message);
// Update so coin trong mode chinh.
CallRemoteFunction("UpdateCoin", "ii", playerid, player_coins);
}
else SendClientMessage(playerid, X11_WHEAT, "Ban da tat menu shop xe.");
}
return 1;
}
YCMD:vehshop(playerid, params[], help)
{
new vehicle_list[100], length = sizeof (vehshop_price_list);
for (new i = 0; i != length; i++)
{
vehicle_list[i] = vehshop_price_list[i][VD_VEH_ID];
}
ShowModelSelectionMenuEx(playerid, vehicle_list, length, "VEHICLE SHOP", VEHICLESHOP_MENU, 16.0, 0.0, -55.0);
return 1;
}
stock load_player_coin(playerid)
{
return CallRemoteFunction("GetPlayerCoin", "i", playerid);
}
stock get_vehicle_price(modelid)
{
for (new i = 0; i != sizeof (vehshop_price_list); i++)
{
if (vehshop_price_list[i][VD_VEH_ID] == modelid)
return vehshop_price_list[i][VD_PRICE];
}
return DEFAULT_VEHICLE_PRICE;
}
stock pure_unpack(const str[])
{
new
ret[32];
strunpack(ret, str);
return ret;
}
stock save_log(file_name[], text[])
{
new
File: log_file,
log_entry[164],
i_dateTime[2][3];
gettime(i_dateTime[0][0], i_dateTime[0][1], i_dateTime[0][2]);
getdate(i_dateTime[1][0], i_dateTime[1][1], i_dateTime[1][2]);
format(log_entry, sizeof (log_entry), "[%i/%i/%i - %i:%i:%i] %s\r\n", i_dateTime[1][0], i_dateTime[1][1], i_dateTime[1][2], i_dateTime[0][0], i_dateTime[0][1], i_dateTime[0][2], text);
if (!fexist(file_name)) log_file = fopen(file_name, io_write);
else log_file = fopen(file_name, io_append);
if (log_file)
{
fwrite(log_file, log_entry);
fclose(log_file);
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment