SA-MP Forums Archive
Helmet bug - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Helmet bug (/showthread.php?tid=516698)



Helmet bug - Rufio - 01.06.2014

Hello guys,

I am scripting a RP mode from scratch and I made way too much progress on it. But I am stuck in a bug and I want to solve it, /kask is the command which puts helmet on a person when he is on a bike, everything is fine and it puts a helmet but it immediately disappears when it spawns.


Any help is appreciated, thanks !


Re: Helmet bug - Drago987 - 01.06.2014

can you show us the command ? and do you mean that you want to attach a toy to the player's head when he does the command ?


Re: Helmet bug - Rufio - 01.06.2014

pawn Код:
CMD:kask(playerid,params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if(AracMotorsa(vehicleid))
{
if(KaskTakili[playerid] == 0)
{
SetPlayerAttachedObject(playerid, 1, 18977, 2, 0.07, 0, 0, 88, 75, 0);
new string[256];
GetPlayerName(playerid, string,sizeof(string));
format(string,sizeof(string),"*%s kaskını takar.",string);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
KaskTakili[playerid] = 1;
}
else
{
RemovePlayerAttachedObject(playerid, 1);
new string[256];
GetPlayerName(playerid, string,sizeof(string));
format(string,sizeof(string),"*%s kaskını зıkartır.",string);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
KaskTakili[playerid] = 0;
}
}
else
{
SendClientMessage(playerid, COLOR_YELLOW2, "{FF0000}(( {00FF00}[HATA]: {FFFFFF}Bu komut sadece motorlarda ve bisikletlerde зalışır. {FF0000} ))");
}
return 1;
}
This is the command and this is "AracMotorsa" callback:

pawn Код:
forward AracMotorsa(vehicleid);
public AracMotorsa(vehicleid)
{
new a = GetVehicleModel(vehicleid);
if (a == 509 || a == 481 || a == 510 || a == 462 ||a == 448 || a == 581 || a == 522 || a == 461 || a == 521 || a == 523 || a == 463 || a == 586 || a == 468 || a == 471)
{
return 1;
}
return 0;
}
And yeah, I want to attach a toy to the player's head when he does the command, and it actually does but disappears immediately after it appears.


Re: Helmet bug - Drago987 - 01.06.2014

Try this:
pawn Код:
CMD:kask(playerid,params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if(AracMotorsa(vehicleid))
{
if(KaskTakili[playerid] == 0)
{
new string[256];
GetPlayerName(playerid, string,sizeof(string));
format(string,sizeof(string),"*%s kaskını takar.",string);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
KaskTakili[playerid] = 1;
SetPlayerAttachedObject(playerid, 1, 18977, 2, 0.07, 0, 0, 88, 75, 0);
}
else
{
new string[256];
GetPlayerName(playerid, string,sizeof(string));
format(string,sizeof(string),"*%s kaskını зıkartır.",string);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
KaskTakili[playerid] = 0;
RemovePlayerAttachedObject(playerid, 1);
}
}
else
{
SendClientMessage(playerid, COLOR_YELLOW2, "{FF0000}(( {00FF00}[HATA]: {FFFFFF}Bu komut sadece motorlarda ve bisikletlerde зalışır. {FF0000} ))");
}
return 1;
}



Re: Helmet bug - Rufio - 01.06.2014

No, doesn't work again


Re: Helmet bug - Threshold - 01.06.2014

You need to look deeper into your statements. Currently you are doing:
pawn Код:
if(var == 1) //var must be '1' to proceed.
{
    SetPlayerAttachedObject(...
    var = 0; //var is now 0.
}
else //var is NOT '1' at this point to proceed. Because var is now '0', this will now be continued.
{
    RemovePlayerAttachedObject(...
    var = 1; //var is now 1.
}
In order to resolve this, you simply change 'else' to 'else if(var == 0)'. Read here: https://sampwiki.blast.hk/wiki/Control_Structures#else

The correct code:
pawn Код:
CMD:kask(playerid,params[])
{
    if(!AracMotorsa(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid, COLOR_YELLOW2, "{FF0000}(( {00FF00}[HATA]: {FFFFFF}Bu komut sadece motorlarda ve bisikletlerde зalisir. {FF0000} ))");
    new string[50], hname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, hname, sizeof(hname);
    if(!KaskTakili[playerid])
    {
        SetPlayerAttachedObject(playerid, 1, 18977, 2, 0.07, 0, 0, 88, 75, 0);
        format(string,sizeof(string),"*%s kaskini takar.",string);
    }
    else if(KaskTakili[playerid])
    {
        RemovePlayerAttachedObject(playerid, 1);
        format(string,sizeof(string),"*%s kaskini зikartir.",string);
    }
    KaskTakili[playerid] = (KaskTakili[playerid]) ? (0) : (1);
    ProxDetector(30.0, playerid, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    return 1;
}