Why wouldn't you just put all data into the enum instead?
Code:
new DrugTimer[MAX_PLAYERS];
new StonedTimer[MAX_PLAYERS];
new UsedDrug[MAX_PLAYERS];
enum pInfo{
pCannabis,
pCocaine
}
You only need to do this once either in OnPlayerConnect() or OnPlayerDisconnect() choose one not both.
Code:
public OnPlayerConnect(playerid)
{
DrugTimer[playerid] = 0;
StonedTimer[playerid] = 0;
UsedDrug[playerid] = 0;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
DrugTimer[playerid] = 0;
StonedTimer[playerid] = 0;
UsedDrug[playerid] = 0;
return 1;
}
You really need to work on your logic structures or you are going to run into trouble
Code:
if(strcmp(option, "cannabis", true) == 0)
{
if(gettime() < (DrugTimer[playerid] + 5))
{
format(str, sizeof(str), "You have to wait %d seconds before you can use /usedrug cannabis again!", (DrugTimer[playerid] + 5) - gettime());
SendClientMessage(playerid, COLOR_GREY, str);
return 1;
}
if(gettime() < (StonedTimer[playerid] + 120))
{
format(str, sizeof(str), "You have to wait %d seconds before you can use /usedrug cannabis again!", (StonedTimer[playerid] + 120) - gettime());
SendClientMessage(playerid, COLOR_GREY, str);
return 1;
}
GetPlayerHealth(playerid, Float:HP);
if(PlayerInfo[playerid][pCannabis] < 1) return SendClientMessage(playerid, COLOR_GREY, "You do not have that much of Cannabis.");
if(HP >= 100) return SendClientMessage(playerid, COLOR_GREY, "Your HP is already full!");
if(HP >= 90)
{
SetPlayerHealth(playerid, 100);
}
else if(HP < 90)
{
SetPlayerHealth(playerid, HP+15);
}
SendClientMessage(playerid, COLOR_GREY, "You've used 2 grams of cannabis and recived +15 health");
SetPlayerWeather(playerid, 2009);
SetPlayerDrunkLevel(playerid, 9000);
PlayerInfo[playerid][pCannabis] -=1;
DrugTimer[playerid] = gettime();
UsedDrug[playerid] ++;
if(UsedDrug[playerid] >= 3)
{
SetTimerEx("RemoveDrugEffect", 60000*2, false, "i", playerid);
UsedDrug[playerid] = 0;
StonedTimer[playerid] = gettime();
}
return 1;
}
Becomes
Code:
if(strcmp(option, "cannabis", true) == 0)
{
if(gettime() < (DrugTimer[playerid] + 5))
{
format(str, sizeof(str), "You have to wait %d seconds before you can use /usedrug cannabis again!", (DrugTimer[playerid] + 5) - gettime());
SendClientMessage(playerid, COLOR_GREY, str);
}
else if(gettime() < (StonedTimer[playerid] + 120))
{
format(str, sizeof(str), "You have to wait %d seconds before you can use /usedrug cannabis again!", (StonedTimer[playerid] + 120) - gettime());
SendClientMessage(playerid, COLOR_GREY, str);
}
else
{
if(PlayerInfo[playerid][pCannabis] < 1)
SendClientMessage(playerid, COLOR_GREY, "You do not have that much of Cannabis.");
else
{
GetPlayerHealth(playerid, Float:HP);
if(HP >= 100)
SendClientMessage(playerid, COLOR_GREY, "Your HP is already full!");
else
{
if(HP >= 90)
SetPlayerHealth(playerid, 100);
else if(HP < 90)
SetPlayerHealth(playerid, HP+15);
SendClientMessage(playerid, COLOR_GREY, "You've used 2 grams of cannabis and recived +15 health");
SetPlayerWeather(playerid, 2009);
SetPlayerDrunkLevel(playerid, 9000);
PlayerInfo[playerid][pCannabis] -=1;
DrugTimer[playerid] = gettime();
UsedDrug[playerid] ++;
if(UsedDrug[playerid] >= 3)
{
SetTimerEx("RemoveDrugEffect", 60000*2, false, "i", playerid);
UsedDrug[playerid] = 0;
StonedTimer[playerid] = gettime();
}
}
}
}
}
You just need to expand your code a bit more and build logic structures that can be followed. Using shitloads of returns is a horrible practice.
What is this horseshit? Did you even test this script? How the hell do you expect that to do anything?
Code:
new option[200], id, amount, str[100], Float:x, Float:y, Float:z;
GetPlayerPos(id, Float:x, Float:y, Float:z);
Just had to point out the end of this script.
Code:
return 1;
}
return 1;
}
You used return 35 times in this script! 35 times! There should only be 9 definitely a problem with your "return happy" ways.
This would normally be a 2-3 star script but it is incomplete! 1-Star in it's current state this is not a release fix it.