IsPlayerInRangeOfPoint not work exactly
#1

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:



PHP код:
hook OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
newkeys == KEY_YES)
    {
        for(new 
0i<SpawnedActors+1i++)
        {
            
//for debug 
            
new Float:X,Float:Y,Float:Z;
            
GetPlayerPos(playeridX,Y,Z);
            
            if(
IsPlayerInRangeOfPoint(playerid2.0actInfo[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(playeridIT_WEEDPACK1)) 
                        {
                            
SetPVarInt(playerid"DrugMenu"999);
                            
format(menusizeof(menu), "Cannabis\nMeth");
                           }
                        else
                        {
                            
SetPVarInt(playerid"DrugMenu"1);
                            
format(menusizeof(menu), "Vendi Cannabis (%d)gr",GetItemPlayerAmount(playeridIT_WEEDPACK));
                        }
                        
ShowPlayerDialog(playeridDIALOG_BUY_DRUGSDIALOG_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;

Anyone know how can I solve?

The log is this:

PHP код:
[17:39:24DEBUGOnPlayerKeyStateChange the playerid 0 is not near actor 1
[17:39:24DEBUGOnPlayerKeyStateChange pos of actor: -176.057006,1023.020019,19.742200
[17:39:24DEBUGOnPlayerKeyStateChange pos of player: -41.184658,1178.615112,19.395765 
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
Reply
#2

Where do actGID, actType and actID come from? Are you sure you're handling them fine?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)