12.09.2018, 15:50
Hello everyone I have a problem, I'm creating a script to interact with the actors: when a player is near one of them pressing the Y key should show a dialogue, but it does not happen, I should have a problem with the for loop: not part from 0 to check the actor with that id, this is my script:
Anyone know how can I solve?
The log is this:
it does not start from the control of the actor with id 0, but starts from the one with id 1 and obviously the position is not compared
PHP код:
hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_YES)
{
for(new i = 0; i<SpawnedActors+1; i++)
{
//for debug
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid, X,Y,Z);
if(IsPlayerInRangeOfPoint(playerid, 2.0, actInfo[i][actX],actInfo[i][actY],actInfo[i][actZ]))
{
SetPVarInt(playerid, "NearActor", actInfo[i][actID]);
SetPVarInt(playerid, "NearActorGame", actInfo[i][actGID]);
new menu[512];
switch(actInfo[i][actType])
{
case 1: //SPACCIATORI
{
if(!IsItemInInventory(playerid, IT_WEEDPACK, 1))
{
SetPVarInt(playerid, "DrugMenu", 999);
format(menu, sizeof(menu), "Cannabis\nMeth");
}
else
{
SetPVarInt(playerid, "DrugMenu", 1);
format(menu, sizeof(menu), "Vendi Cannabis (%d)gr",GetItemPlayerAmount(playerid, IT_WEEDPACK));
}
ShowPlayerDialog(playerid, DIALOG_BUY_DRUGS, DIALOG_STYLE_LIST, "Stupefacente", menu,"Ok","Esci");
}
case 255: //invalid
{
return 0;
}
}
}
else
{
printf("DEBUG: OnPlayerKeyStateChange the playerid %d is not near actor %d",playerid,i);
printf("DEBUG: OnPlayerKeyStateChange pos of actor: %f,%f,%f",actInfo[i][actX],actInfo[i][actY],actInfo[i][actZ]);
printf("DEBUG: OnPlayerKeyStateChange pos of player: %f,%f,%f",X,Y,Z);
}
}
}
return true;
}
The log is this:
PHP код:
[17:39:24] DEBUG: OnPlayerKeyStateChange the playerid 0 is not near actor 1
[17:39:24] DEBUG: OnPlayerKeyStateChange pos of actor: -176.057006,1023.020019,19.742200
[17:39:24] DEBUG: OnPlayerKeyStateChange pos of player: -41.184658,1178.615112,19.395765