SA-MP Forums Archive
[ZCMD] strange bug, with commands processor. - 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: [ZCMD] strange bug, with commands processor. (/showthread.php?tid=550679)



[ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Hey, i have this two commands.

pawn Код:
CMD:pcar(playerid,params[]){

    for(new i=0; i < MAX_HOUSES_PER_PLAYER; i++){

        if(!IsPlayerInRangeOfPoint(playerid,8.0,hinfo[pinfo[playerid][houses][i]][enter_pos_x],hinfo[pinfo[playerid][houses][i]][enter_pos_y],hinfo[pinfo[playerid][houses][i]][enter_pos_z]))continue;

        GetPlayerPos(playerid,hinfo[pinfo[playerid][houses][i]][cpark_pos_x],hinfo[pinfo[playerid][houses][i]][cpark_pos_y],hinfo[pinfo[playerid][houses][i]][cpark_pos_z]);

        new query[300];
        mysql_format(db_connect,query,sizeof(query),"UPDATE samp_tabella_houses SET cpark_x ='%f', cpark_y ='%f', cpark_z='%f' WHERE ID ='%i'",hinfo[pinfo[playerid][houses][i]][cpark_pos_x],hinfo[pinfo[playerid][houses][i]][cpark_pos_y],hinfo[pinfo[playerid][houses][i]][cpark_pos_z],pinfo[playerid][houses][i]);
        SendClientMessage(playerid,-1,"{FF0000}//{FFFFFF}system: You have parked your vehicle near your house");
    }
   
    return 1;
}

CMD:scar(playerid,params[]){

    if(tmp_car_house_spawned[playerid]!=1){

        for(new i=0; i<MAX_HOUSES_PER_PLAYER;i++){

            if(!IsPlayerInRangeOfPoint(playerid,10.0,hinfo[pinfo[playerid][houses][i]][enter_pos_x],hinfo[pinfo[playerid][houses][i]][enter_pos_y],hinfo[pinfo[playerid][houses][i]][enter_pos_z]))continue;
            AddStaticVehicleEx(pinfo[playerid][vehicle_id][0],hinfo[pinfo[playerid][houses][i]][cpark_pos_x],hinfo[pinfo[playerid][houses][i]][cpark_pos_y],hinfo[pinfo[playerid][houses][i]][cpark_pos_z],0.0,0,0,10);
            tmp_car_house_spawned[playerid]=1;
            break;
        }
    }
    return 1;
}
when i callback they with the command in server, it respond Unknow Command, why?


Re: [ZCMD] strange bug, with commands processor. - Ox1gEN - 14.12.2014

Sometimes OnPlayerCommandText and zcmd encounter eachother, make sure you deleted the OnPlayerCommandText call-back, that should do.


Re: [ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Quote:
Originally Posted by Ox1gEN
Посмотреть сообщение
Sometimes OnPlayerCommandText and zcmd encounter eachother, make sure you deleted the OnPlayerCommandText call-back, that should do.
I have already deleted.


Re: [ZCMD] strange bug, with commands processor. - zT KiNgKoNg - 14.12.2014

By any chance do all your other commands work excluding these two you have provided for us to help you with?

Note: It may be caused by the loops in your command, I ran into a problem doing it like you have before so i just put them into a stock and ran it from there, Check the example below.


pawn Код:
stock GetFreeBankSlot(playerid)
{
    for(new i = 0; i < MAX_BANK_ACCOUNTS; i++)
    {
        if(BankInformation[playerid][i][BankSlotUsed])
            continue;
        else
            return i;
    }
    return -1;
}



Re: [ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Quote:
Originally Posted by zT KiNgKoNg
Посмотреть сообщение
By any chance do all your other commands work excluding these two you have provided for us to help you with?

Note: It may be caused by the loops in your command, I ran into a problem doing it like you have before so i just put them into a stock and ran it from there, Check the example below.


pawn Код:
stock GetFreeBankSlot(playerid)
{
    for(new i = 0; i < MAX_BANK_ACCOUNTS; i++)
    {
        if(BankInformation[playerid][i][BankSlotUsed])
            continue;
        else
            return i;
    }
    return -1;
}
You mean something like this:
pawn Код:
forward scar(playerid);
public scar(playerid){
    if(tmp_car_house_spawned[playerid]!=1){

        for(new i=0; i<MAX_HOUSES_PER_PLAYER;i++){

            if(!IsPlayerInRangeOfPoint(playerid,10.0,hinfo[pinfo[playerid][houses][i]][enter_pos_x],hinfo[pinfo[playerid][houses][i]][enter_pos_y],hinfo[pinfo[playerid][houses][i]][enter_pos_z]))continue;
            AddStaticVehicleEx(pinfo[playerid][vehicle_id][0],hinfo[pinfo[playerid][houses][i]][cpark_pos_x],hinfo[pinfo[playerid][houses][i]][cpark_pos_y],hinfo[pinfo[playerid][houses][i]][cpark_pos_z],0.0,0,0,10);
            tmp_car_house_spawned[playerid]=1;
            break;
        }
    }
    return 1;
}

CMD:scar(playerid,params[]){
    scar(playerid);
    return 1;
}



Re: [ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Nobody can help me?


Re: [ZCMD] strange bug, with commands processor. - Pottus - 14.12.2014

The likely explanation if that code is running is some kind of OOB error on your array this is a very common problem and usually very easy to fix make sure you have crashdetect plugin that will let you know if it really is the problem. Also don't use the stock modifier when creating functions that is used generally when making libraries where a function may or may not be used and serves no purpose but to obfuscate your code.

https://sampforum.blast.hk/showthread.php?tid=262796

My hunch at this time is an OOB here hinfo[pinfo[playerid][houses][i]] you probably have a default value in that array which is causing an OOB.


Re: [ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Quote:
Originally Posted by Pottus
Посмотреть сообщение
The likely explanation if that code is running is some kind of OOB error on your array this is a very common problem and usually very easy to fix make sure you have crashdetect plugin that will let you know if it really is the problem. Also don't use the stock modifier when creating functions that is used generally when making libraries where a function may or may not be used and serves no purpose but to obfuscate your code.

https://sampforum.blast.hk/showthread.php?tid=262796

My hunch at this time is an OOB here hinfo[pinfo[playerid][houses][i]] you probably have a default value in that array which is causing an OOB.
when i type my command the crashdectect give me this server's log.

Код:
[22:54:39] [debug] Run time error 4: "Array index out of bounds"
[22:54:39] [debug]  Accessing element at negative index -1
[22:54:39] [debug] AMX backtrace:
[22:54:39] [debug] #0 00026aec in public cmd_pcar (0, 8479092) from testproject.amx
[22:54:39] [debug] #1 native CallLocalFunction () from samp-server.exe
[22:54:39] [debug] #2 0000619c in public OnPlayerCommandText (0, 8479068) from testproject.amx



Re: [ZCMD] strange bug, with commands processor. - Pottus - 14.12.2014

Because you need to do this in your loop.

pawn Код:
if(pinfo[playerid][houses][i] == -1) continue;



Re: [ZCMD] strange bug, with commands processor. - Galletziz - 14.12.2014

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Because you need to do this in your loop.

pawn Код:
if(pinfo[playerid][houses][i] == -1) continue;
Azz... You are so right, thanks for your help pottus. Infact i set this variable to -1 if the player havn't house in any slot of houses array in enum player_info.

Thanks, +rep.