Skip to content

Instantly share code, notes, and snippets.

@dennorske
Created February 13, 2013 13:29
Show Gist options
  • Save dennorske/4944598 to your computer and use it in GitHub Desktop.
Save dennorske/4944598 to your computer and use it in GitHub Desktop.
Drug system
///Drug system by Spunky:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <dini>
enum drugInfo
{
seeds,
grams,
plants,
planted,
plantgrams
}
new drugs[MAX_PLAYERS][drugInfo];
stock file(playerid)
{
new file2[48];
format(file2,sizeof(file2), "/DrugSystem/%s", PlayerName(playerid));
return file2;
}
forward drugsoff(playerid);
new drugged[MAX_PLAYERS] = 0;
public OnFilterScriptInit()
{
print("-------------------------------------------");
printf("--------Drug test system- ------ ------- --");
print(" ---> Spunky");
print("--------------------------------------------");
return 1;
}
public OnPlayerConnect(playerid)
{
new connect[48];
format(connect,sizeof(connect), "/DrugSystem/%s", PlayerName(playerid));
if(dini_Exists(connect))
{
drugs[playerid][seeds] = dini_Int(connect, "seeds");
drugs[playerid][plants] = dini_Int(connect, "plants");
drugs[playerid][grams] = dini_Int(connect, "grams");
drugs[playerid][planted] =dini_Int(connect, "planted");
drugs[playerid][plantgrams] =dini_Int(connect, "plantgrams");
}
if(!dini_Exists(connect))
{
dini_Create(connect);
dini_IntSet(connect, "seeds", 0);
dini_IntSet(connect, "plants", 0);
dini_IntSet(connect, "grams", 0);
dini_IntSet(connect, "planted", 0);
dini_IntSet(connect, "plantgrams", 0);
}
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
stock PlayerName(playerid)
{
new pn[MAX_PLAYER_NAME];
GetPlayerName(playerid, pn, sizeof(pn));
return pn;
}
CMD:takedrug(playerid, params[])
{
new connect[48];
if(drugged[playerid] == 1)
return SendClientMessage(playerid, -1, "You are already drugged, and you must wait for the current drug to expire!");
if(drugs[playerid][grams] < 10)
return SendClientMessage(playerid, -1, "You don't have enough drug! (Minimum 10 Grams)");
drugged[playerid] = 1;
ApplyAnimation(playerid, "DEALER", "DEALER_IDLE_02", 4.0,1,0,0,0,-1);
SetTimerEx("drugsoff", 30000, false, "d", playerid);
new Float:health;
GetPlayerHealth(playerid, health);
if(health <= 95)
SetPlayerHealth(playerid, health + 5);
if(health > 95)
SetPlayerHealth(playerid, 100);
SendClientMessage(playerid, -1, "Ahhhh, drugs...I feel better now!");
SendClientMessage(playerid, -1, "Information: You used 10 grams of drug");
//drugs[playerid][grams]-10;
format(connect,sizeof(connect), "/DrugSystem/%s", PlayerName(playerid));
dini_IntSet(connect, "grams", drugs[playerid][grams]);
SendClientMessage(playerid, -1, "Information: You used 10 grams of drug");
return 1;
}
CMD:plant(playerid, params[])
{
new connect[48], Float:x, Float:y, Float:z;
if(drugs[playerid][seeds] == 0)
return SendClientMessage(playerid, -1, "Sorry, you dont have any seeds to plant drugs");
if(drugs[playerid][planted] == 1)
return SendClientMessage(playerid, -1, "You have already planted a drug plant, you can only plant one at a time.");
if(GetPlayerInterior(playerid) > 0 || GetPlayerVirtualWorld(playerid) > 0)
return SendClientMessage(playerid, -1, "You can NOT plant any drugs whilst being here");
if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT)
return SendClientMessage(playerid, -1, "You can't plant any drugs while driving/swimming/flying");
format(connect,sizeof(connect), "/DrugSystem/%s", PlayerName(playerid));
GetPlayerPos(playerid, x,y,z);
SetPlayerCheckpoint(playerid, x,y,z,5);
SetPVarFloat(playerid, "plantx", x);
SetPVarFloat(playerid, "planty", y);
SetPVarFloat(playerid, "plantz", z);
drugs[playerid][planted] = 1;
dini_IntSet(connect, "planted", 1);
dini_IntSet(connect, "plantgrams", 0);
return 1;
}
forward plantgrow(playerid);
public plantgrow(playerid)
{
new connect[48];
format(connect,sizeof(connect), "/DrugSystem/%s", PlayerName(playerid));
if(drugs[playerid][planted] == 0)
return 1;
if(drugs[playerid][plantgrams] == 235)//That value is correct, because that is found before the value is set below in the code... Dont change it! -Spunky-
SendClientMessage(playerid, -1, "[IMPORTANT] -- Your drug plant is 240 grams now, and will die in 1 minute & 30 sec! You must /harvest it as soon as possible!");
if(drugs[playerid][plantgrams] == 240)
SendClientMessage(playerid, -1, "[IMPORTANT] -- Your drug plant is 245 grams now, and will die in 1 minute! You must /harvest it as soon as possible!");
if(drugs[playerid][plantgrams] == 245)
SendClientMessage(playerid, -1, "[IMPORTANT] -- Your drug plant is 250 grams now, and will die in 30 seconds! You must /harvest it as soon as possible!");
if(drugs[playerid][plantgrams] == 250)
{
SendClientMessage(playerid, -1, "[INFORMATION] -- Your drug plant is now dead, and it is removed");
drugs[playerid][plantgrams] = 0;
drugs[playerid][planted] = 0;
dini_IntSet(connect, "plantgrams", 0);
dini_IntSet(connect, "planted", 0);
return 1;
}
if(drugs[playerid][planted] == 1)
{
drugs[playerid][plantgrams] += 5;
dini_IntSet(connect, "plantgrams", drugs[playerid][plantgrams]);
}
return 1;
}
public OnPlayerUpdate(playerid)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, GetPVarFloat(playerid, "plantx"), GetPVarFloat(playerid, "planty"), GetPVarFloat(playerid, "plantz")) && drugs[playerid][planted] == 1 && drugs[playerid][plantgrams] > 50)
ShowPlayerDialog(playerid, 150, DIALOG_STYLE_LIST, "Plant Menu", "Harvest", "ok","");
return 1;
}
public drugsoff(playerid)
{
drugged[playerid] = 0;
SendClientMessage(playerid, -1,"Your aren't drugged anymore");
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 150) // Drug dialog ID
{
if(listitem == 1)
{
new string[190];
drugs[playerid][grams] += drugs[playerid][plantgrams];
format(string, sizeof(string), "You harvested your plant, and you added %d grams into your pocket. In total you have %d grams available",
drugs[playerid][plantgrams], drugs[playerid][grams]);
drugs[playerid][plantgrams] = 0;
drugs[playerid][planted] = 0;
SendClientMessage(playerid, -1, string);
dini_IntSet(file(playerid), "grams", drugs[playerid][grams]);
dini_IntSet(file(playerid), "plantgrams", drugs[playerid][plantgrams]);
}
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment