Boombox picking issue -
Stanford - 13.06.2013
Alright I place a boombox and everything is cool also it works with music and everything, and when I want to pick it up it says that I picked it up without destroying the boombox and the textlabel, and I even put them in the command here's the codes:
pawn Код:
dcmd_placeboombox(playerid, params[])
{
#pragma unused params
if(PlayerInfo[playerid][pBoomBox] == 0) return SendClientMessage(playerid, COLOR_WHITE, "You don't have a BoomBox");
if(GetPVarType(playerid, "pDynamicBB")) return SendClientMessage(playerid, COLOR_WHITE, "You already have a boombox out, use /pickupboombox.");
if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must get out of your vehicle to place a boombox!.");
foreach(Player, i)
{
if(GetPVarType(i, "pDynamicBB"))
{
if(IsPlayerInRangeOfPoint(playerid, 30.0, GetPVarFloat(i, "pDynamicBBX"), GetPVarFloat(i, "pDynamicBBY"), GetPVarFloat(i, "pDynamicBBZ")))
{
SendClientMessage(playerid, COLOR_WHITE, "You cannot put your boombox in this Radius");
return 1;
}
}
new string[128];
// format(string, sizeof(string), "%s has placed a boombox on the floor!", SenderName(playerid));
// SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
// format(string, sizeof(string), "* %s has placed a boombox on the floor!",GetPlayerNameEx(playerid));
// ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
ApplyAnimation(playerid,"BOMBER","BOM_Plant_Crouch_In", 4.0, 0, 0, 0, 0, 0, 1);
x += (2 * floatsin(-a, degrees));
y += (2 * floatcos(-a, degrees));
z -= 1.0;
SetPVarInt(playerid, "pDynamicBB", CreateDynamicObject(2226, x, y, z, 0.0, 0.0, 0.0, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid)));
SetPVarFloat(playerid, "pDynamicBBX", x); SetPVarFloat(playerid, "pDynamicBBY", y); SetPVarFloat(playerid, "pDynamicBBZ", z);
format(string, sizeof(string), "{00FF00}Boombox Owner:{FFFFFF}%s\n{FF0000}/turnon{FFFFFF} to set your boombox \n{FFFF00}or\n{FF0000}/pickupboombox", SenderName(playerid));
SetPVarInt(playerid, "pDynamicBBLabel", _:CreateDynamic3DTextLabel(string, COLOR_WHITE, x, y, z+0.6, 5.0, .worldid = GetPlayerVirtualWorld(playerid), .interiorid = GetPlayerInterior(playerid)));
SetPVarInt(playerid, "pDynamicBBArea", CreateDynamicSphere(x, y, z, 30.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid)));
SetPVarInt(playerid, "pDynamicBBInt", GetPlayerInterior(playerid));
SetPVarInt(playerid, "pDynamicBBVW", GetPlayerVirtualWorld(playerid));
}
return 1;
}
pawn Код:
dcmd_pickupboombox(playerid, params[])
{
#pragma unused params
if(GetPVarType(playerid, "pDynamicBB"))
{
if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK || !(PlayerInfo[playerid][pTurnedOn] == 0)) return SendClientMessage(playerid, COLOR_WHITE, " You must be crouched or you have not turnned your boombox off!");
if(!IsPlayerInRangeOfPoint(playerid, 3.0, GetPVarFloat(playerid, "pDynamicBBX"), GetPVarFloat(playerid, "pDynamicBBY"), GetPVarFloat(playerid, "pDynamicBBZ"))) return SendClientMessage(playerid, COLOR_WHITE, "You're not near in your BoomBox");
DestroyDynamicObject(GetPVarInt(playerid, "pDynamicBB"));
DestroyDynamic3DTextLabel(Text3D:GetPVarInt(playerid, "pDynamicBBLabel"));
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(playerid, "pDynamicBB"); DeletePVar(playerid, "pDynamicBBStation"); DeletePVar(playerid, "pDynamicBBLabel");
DeletePVar(playerid, "pDynamicBBX"); DeletePVar(playerid, "pDynamicBBY"); DeletePVar(playerid, "pDynamicBBZ");
if(GetPVarType(playerid, "pDynamicBBArea"))
{
new string[128];
// format(string, sizeof(string), "* %s has pickedup their boombox.", SenderName(playerid));
// SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
// format(string, sizeof(string), "* %s has picked up their boombox!",GetPlayerNameEx(playerid));
// ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
foreach(Player, i)
{
if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "pDynamicBBArea")))
{
StopAudioEx(i);
DestroyDynamicObject(GetPVarInt(playerid, "pDynamicBB"));
DestroyDynamic3DTextLabel(Text3D:GetPVarInt(playerid, "pDynamicBBLabel"));
SendClientMessage(i, COLOR_PURPLE, string);
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(i, "pDynamicBB");
DeletePVar(i, "pDynamicBBStation");
DeletePVar(i, "pDynamicBBLabel");
DeletePVar(i, "pDynamicBBX");
DeletePVar(i, "pDynamicBBY");
DeletePVar(i, "pDynamicBBZ");
DeletePVar(i, "pDynamicBBInt");
DeletePVar(i, "pDynamicBBVW");
}
}
DeletePVar(playerid, "pDynamicBBArea");
}
SendClientMessage(playerid, COLOR_WHITE, "You've picked up your boombox!");
DestroyDynamicObject(GetPVarInt(playerid, "pDynamicBB"));
DestroyDynamic3DTextLabel(Text3D:GetPVarInt(playerid, "pDynamicBBLabel"));
}
else
{
foreach(Player, i)
{
if(GetPVarType(i, "pDynamicBB"))
{
if(GetPVarInt(i, "pDynamicBBVW") == GetPlayerVirtualWorld(playerid) && GetPVarInt(i, "pDynamicBBInt") == GetPlayerInterior(playerid) && IsPlayerInRangeOfPoint(playerid, 5.0, GetPVarFloat(i, "pDynamicBBX"), GetPVarFloat(i, "pDynamicBBY"), GetPVarFloat(i, "pDynamicBBZ")))
{
if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) return SendClientMessage(playerid, COLOR_WHITE, " You must be crouched to pick a the boombox.");
if(!IsPlayerInRangeOfPoint(playerid, 3.0, GetPVarFloat(playerid, "pDynamicBBX"), GetPVarFloat(playerid, "pDynamicBBY"), GetPVarFloat(playerid, "pDynamicBBZ"))) return SendClientMessage(playerid, COLOR_WHITE, "You're not near in your BoomBox");
DestroyDynamicObject(GetPVarInt(i, "pDynamicBB"));
DestroyDynamic3DTextLabel(Text3D:GetPVarInt(i, "pDynamicBBLabel"));
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(i, "pDynamicBB");
DeletePVar(i, "pDynamicBBStation");
DeletePVar(i, "pDynamicBBLabel");
DeletePVar(i, "pDynamicBBX");
DeletePVar(i, "pDynamicBBY");
DeletePVar(i, "pDynamicBBZ");
DeletePVar(i, "pDynamicBBInt");
DeletePVar(i, "pDynamicBBVW");
new string[128];
if(GetPVarType(i, "pDynamicBBArea"))
{
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerInDynamicArea(x, GetPVarInt(x, "pDynamicBBArea")))
{
StopAudioEx(x);
SendClientMessage(x, COLOR_PURPLE, string);
}
}
DeletePVar(i, "pDynamicBBArea");
}
return 1;
}
}
}
SendClientMessage(playerid, COLOR_WHITE, "You don't have a boombox or you are not near one to be pickup");
}
return 1;
}
Thanks in advance!.
Re: Boombox picking issue -
Ballu Miaa - 13.06.2013
I guess this should work. Try it mate.
pawn Код:
dcmd_pickupboombox(playerid, params[])
{
#pragma unused params
if(GetPVarType(playerid, "pDynamicBB"))
{
if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK || !(PlayerInfo[playerid][pTurnedOn] == 0)) return SendClientMessage(playerid, COLOR_WHITE, " You must be crouched or you have not turnned your boombox off!");
if(!IsPlayerInRangeOfPoint(playerid, 3.0, GetPVarFloat(playerid, "pDynamicBBX"), GetPVarFloat(playerid, "pDynamicBBY"), GetPVarFloat(playerid, "pDynamicBBZ"))) return SendClientMessage(playerid, COLOR_WHITE, "You're not near in your BoomBox");
DestroyDynamicObject(GetPVarInt(playerid, "pDynamicBB"));
DestroyDynamic3DTextLabel(GetPVarInt(playerid, "pDynamicBBLabel"));
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(playerid, "pDynamicBB"); DeletePVar(playerid, "pDynamicBBStation"); DeletePVar(playerid, "pDynamicBBLabel");
DeletePVar(playerid, "pDynamicBBX"); DeletePVar(playerid, "pDynamicBBY"); DeletePVar(playerid, "pDynamicBBZ");
if(GetPVarType(playerid, "pDynamicBBArea"))
{
new string[128];
// format(string, sizeof(string), "* %s has pickedup their boombox.", SenderName(playerid));
// SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
// format(string, sizeof(string), "* %s has picked up their boombox!",GetPlayerNameEx(playerid));
// ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
foreach(Player, i)
{
if(IsPlayerInDynamicArea(i, GetPVarInt(playerid, "pDynamicBBArea")))
{
StopAudioEx(i);
DestroyDynamicObject(GetPVarInt(playerid, "pDynamicBB"));
DestroyDynamic3DTextLabel(GetPVarInt(playerid, "pDynamicBBLabel"));
SendClientMessage(i, COLOR_PURPLE, string);
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(i, "pDynamicBB");
DeletePVar(i, "pDynamicBBStation");
DeletePVar(i, "pDynamicBBLabel");
DeletePVar(i, "pDynamicBBX");
DeletePVar(i, "pDynamicBBY");
DeletePVar(i, "pDynamicBBZ");
DeletePVar(i, "pDynamicBBInt");
DeletePVar(i, "pDynamicBBVW");
}
}
DeletePVar(playerid, "pDynamicBBArea");
}
SendClientMessage(playerid, COLOR_WHITE, "You've picked up your boombox!");
}
else
{
foreach(Player, i)
{
if(GetPVarType(i, "pDynamicBB"))
{
if(GetPVarInt(i, "pDynamicBBVW") == GetPlayerVirtualWorld(playerid) && GetPVarInt(i, "pDynamicBBInt") == GetPlayerInterior(playerid) && IsPlayerInRangeOfPoint(playerid, 5.0, GetPVarFloat(i, "pDynamicBBX"), GetPVarFloat(i, "pDynamicBBY"), GetPVarFloat(i, "pDynamicBBZ")))
{
if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK) return SendClientMessage(playerid, COLOR_WHITE, " You must be crouched to pick a the boombox.");
if(!IsPlayerInRangeOfPoint(playerid, 3.0, GetPVarFloat(playerid, "pDynamicBBX"), GetPVarFloat(playerid, "pDynamicBBY"), GetPVarFloat(playerid, "pDynamicBBZ"))) return SendClientMessage(playerid, COLOR_WHITE, "You're not near in your BoomBox");
DestroyDynamicObject(GetPVarInt(i, "pDynamicBB"));
DestroyDynamic3DTextLabel(GetPVarInt(i, "pDynamicBBLabel"));
PlayerInfo[playerid][pTurnedOn] = 0;
DeletePVar(i, "pDynamicBB");
DeletePVar(i, "pDynamicBBStation");
DeletePVar(i, "pDynamicBBLabel");
DeletePVar(i, "pDynamicBBX");
DeletePVar(i, "pDynamicBBY");
DeletePVar(i, "pDynamicBBZ");
DeletePVar(i, "pDynamicBBInt");
DeletePVar(i, "pDynamicBBVW");
new string[128];
if(GetPVarType(i, "pDynamicBBArea"))
{
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerInDynamicArea(x, GetPVarInt(x, "pDynamicBBArea")))
{
StopAudioEx(x);
SendClientMessage(x, COLOR_PURPLE, string);
}
}
DeletePVar(i, "pDynamicBBArea");
}
return 1;
}
}
}
SendClientMessage(playerid, COLOR_WHITE, "You don't have a boombox or you are not near one to be pickup");
}
return 1;
}
Re: Boombox picking issue -
Stanford - 13.06.2013
tag mistach warnings appeared on these lines:
pawn Код:
DestroyDynamic3DTextLabel(GetPVarInt(playerid, "pDynamicBBLabel"));
DestroyDynamic3DTextLabel(GetPVarInt(playerid, "pDynamicBBLabel"));
DestroyDynamic3DTextLabel(GetPVarInt(i, "pDynamicBBLabel"));
Re: Boombox picking issue -
Stanford - 13.06.2013
I've fixed the tag mistatch warnings, but I went ingame to test, it didn't work, anybody??
Re: Boombox picking issue -
Pottus - 13.06.2013
You should code it better.
- Don't use pvars they're not needed and don't do any good
https://sampforum.blast.hk/showthread.php?tid=268499
- Avoid multiple returns it can be a pain in the ass to figure out where your code is exiting
- I'd start it over again and add comments of why your doing what your doing this code is ugly right now and that is worst problem
Re: Boombox picking issue -
Stanford - 13.06.2013
Thanks [uL]Pottus, that was so kind from you, thanks in advance
Re: Boombox picking issue -
Stanford - 13.06.2013
Can anyone do it for me, I can't do it I tried several times
Re: Boombox picking issue -
Ballu Miaa - 13.06.2013
I dont have any kind of Compiler else i would have done it for you. I dont want to reinstall for sometime till my exams. So sorry mate. You doing good. You need to code it again. You know what you are doing.
Always remember , In Scripting sometimes the Perfect code you think will run your way , actually turns out to be working the other way. Sometimes the order of codes also effect the execution. Just recode it. Use integers or a particular Global Array for every player in which you can save , read and delete all that info.
Re: Boombox picking issue -
Stanford - 13.06.2013
Thanks buddy I did it, thanks for giving me the hope!