09.03.2014, 17:21
So when an admin spawns a giftbox, via the command /giftbox, a player would want to grab the giftbox of course. This is done by the command /getgift, but when a player does /getgift it says they already received one within the hour or whatever, even though that's not true. It's happening to me and others although we've never gotten a gift. What's the issue with the code, is it a timer messing up?
That's /getgift and then this is /giftbox (If it's even needed)
PHP код:
if(strcmp(cmd, "/getgift", true) == 0)
{
if(giftsenabled)
{
if(gifttimer[playerid]) return SendClientMessage(playerid, GREY, "You must wait an hour before getting another gift.");
new Float:x, Float:y, Float:z;
GetDynamicObjectPos(dynamicgift, x, y, z);
if(gettinggift[playerid]) return 1;
if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
{
gettinggift[playerid] = 1;
format(string, sizeof(string), "* %s reaches inside the box with their eyes closed and grabs something.", PlayerName(playerid));
ProxDetector(30.0, playerid, string, PURPLE, PURPLE, PURPLE, PURPLE, PURPLE);
SetTimerEx("Gift", 1000, false, "i", playerid);
return 1;
}
else
{
SendClientMessage(playerid, GREY, "You are not near a gift box.");
return 1;
}
}
else
{
SendClientMessage(playerid, GREY, "Gifts are disabled. Try again later.");
}
return 1;
}
if(strcmp(cmd, "/open", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pGiftBoxes] > 0)
{
if (GetPVarInt(playerid, "GiftWait") == 0)
{
PlayerInfo[playerid][pGiftBoxes]--;
GiftPlayer(playerid);
SetPVarInt(playerid, "GiftWait", 3);
return 1;
}
else return SendClientMessage(playerid, GREY, "You must wait 3 seconds before opening another gift.");
}
else
{
SendClientMessage(playerid, GREY, "You don't have any gifts to open.");
return 1;
}
}
return 1;
}
PHP код:
if(strcmp(cmd, "/giftbox", true) == 0)
{
if(PlayerInfo[playerid][pAdmin] >= 5)
{
if(!giftsenabled)
{
new randbox = random(6);
switch(randbox)
{
case 0: randbox = 19058;
case 1: randbox = 19056;
case 2: randbox = 19055;
case 3: randbox = 19057;
case 4: randbox = 19054;
case 5, 6: randbox = 19056;
}
new Float:x, Float:y, Float:z, Float:a, location[MAX_ZONE_NAME];
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
dynamicgift = CreateDynamicObject(randbox, x, y, z-0.4, 0.0, 0.0, a, -1, -1, -1, 200.0);
dynamicgift3DText = CreateStreamed3DTextLabel("/getgift",LIGHTBLUE, x, y, z+0.25,8.0,GetPlayerVirtualWorld(playerid));
SetPlayerPosEx(playerid, x, y, z+3);
giftsenabled = 1;
Get2DZone(location, MAX_ZONE_NAME, x, y, z);
format(string, sizeof(string), "{FF6347}%s has enabled gifts @ %s (%f, %f, %f)",PlayerName(playerid), location, x, y, z);
ABroadCast(RED, string, 5);
format(string, sizeof(string), "* %s would like you to come to %s to receive free gifts and to enjoy yourself.", PlayerName(playerid), location);
SendClientMessageToAll(LIGHTBLUE, string);
return 1;
}
else
{
new Float:x, Float:y, Float:z, location[MAX_ZONE_NAME];
GetPlayerPos(playerid, x, y, z);
Get2DZone(location, MAX_ZONE_NAME, x, y, z);
giftsenabled = 0;
DestroyDynamicObject(dynamicgift);
DestroyDynamic3DTextLabel(dynamicgift3DText);
format(string, sizeof(string), "{FF6347}%s has disabled the gift box.",PlayerName(playerid));
ABroadCast(RED, string, 5);
format(string, sizeof(string), "* Gifts at %s are now over. Enjoy your gift!", location);
SendClientMessageToAll(LIGHTBLUE, string);
}
return 1;
}
else
{
SendClientMessage(playerid, GREY, "You are not authorized to use that command.");
}
return 1;
}