SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/05/2016, 04:08 PM   #1
_Application_
Big Clucker
 
Join Date: Apr 2012
Posts: 142
Reputation: 1
Default i'ts not work good

i'ts not work good,

PHP Code:
     new File:file fopen("IsPlayerInArea.ini"io_read);
        if (!
file) return 0;
        new 
line[MAX_AREAS],
            
Float:Pos[6];
 
        while (
fread(fileline))
        {
            
sscanf(line"p<,>ffffff"Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
            
printf("%f, %f, %f, %f, %f, %f"Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
            if(
IsPlayerInArea(playeridPos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]))
            {
                
SendClientMessage(playerid0xFF0000FF"You in area!");
            }
        }
 
        
fclose(file); 
_Application_ is offline   Reply With Quote
Old 23/05/2016, 05:01 PM   #2
Sithis
Gangsta
 
Join Date: Mar 2013
Location: the Netherlands
Posts: 887
Reputation: 79
Default Re: i'ts not work good... =/ help please!

What's not working well? Do you get any errors? Does the file exist and contain the right values? You really must be more specific!
__________________
Developer and owner of https://trinityrpg.com
Sithis is offline   Reply With Quote
Old 23/05/2016, 05:12 PM   #3
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,196
Reputation: 229
Default Re: i'ts not work good... =/ help please!

Code looks fine, nothing wrong with it (except IsPlayerInArea function but that is custom so its probably fine)

Please how us IsPlayerInArea function (how its defined). And file format how you save that coordinates (what each one is representing)
DRIFT_HUNTER is offline   Reply With Quote
Old 23/05/2016, 06:28 PM   #4
_Application_
Big Clucker
 
Join Date: Apr 2012
Posts: 142
Reputation: 1
Default Re: i'ts not work good... =/ help please!

Quote:
Originally Posted by DRIFT_HUNTER View Post
Code looks fine, nothing wrong with it (except IsPlayerInArea function but that is custom so its probably fine)

Please how us IsPlayerInArea function (how its defined). And file format how you save that coordinates (what each one is representing)
IsPlayerInArea(playerid, Float:MinX, Float:MinY, Float:MinZ,Float:MaxX, Float:MaxY,Float:MaxZ)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
return (X >= MinX && X <= MaxX && Y >= MinY && Y <= MaxY && Z >= MinZ && Z <= MaxZ) ? 1 : 0;
}


i'ts fine, umm the problem it's , The first line identifies the area well, and the rest is not accurate..
_Application_ is offline   Reply With Quote
Old 23/05/2016, 09:39 PM   #5
AdrianG
Big Clucker
 
AdrianG's Avatar
 
Join Date: Mar 2016
Location: Austria
Posts: 50
Reputation: 7
Default Re: i'ts not work good... =/ help please!

have you tried to print the Pos array, in order to see where is the problem..!? try to print it in the while loop.
__________________
[EN]: If I helped you, please follow me on YouTube: Click Here
[RO]: Daca ti-am fost de ajutor, urmareste-ma si pe YouTube: Click Aici
AdrianG is offline   Reply With Quote
Old 24/05/2016, 01:40 PM   #6
_Application_
Big Clucker
 
Join Date: Apr 2012
Posts: 142
Reputation: 1
Default Re: i'ts not work good... =/ help please!

Quote:
Originally Posted by AdrianG View Post
have you tried to print the Pos array, in order to see where is the problem..!? try to print it in the while loop.
Quote:
Originally Posted by DRIFT_HUNTER View Post
Code looks fine, nothing wrong with it (except IsPlayerInArea function but that is custom so its probably fine)

Please how us IsPlayerInArea function (how its defined). And file format how you save that coordinates (what each one is representing)

Quote:
Originally Posted by Sithis View Post
What's not working well? Do you get any errors? Does the file exist and contain the right values? You really must be more specific!
PHP Code:
new
    
Float:AreaInfo[6];

YCMD:areaweapon(playeridparams[], help)
{
    
#pragma unused params, help
    
return ShowPlayerDialog(playeridDIALOG_IPIA_MAKERDIALOG_STYLE_LIST"יוצר אזורים דינאמי""שמירת קצה ראשון\nשמירת קצה שני\n{F58282}שמירת אזור במערכת\nאיפוס שמירת קצוות""בחירה""יציאה"), 1;
}

public 
OnFilterScriptInit()
{
    
SetTimer("InAreaCheck"200true);
    return 
1;
}

function 
InAreaCheck()
{
    new 
File:file fopen("IsPlayerInArea.ini"io_read);
    if (!
file) return 0;
    new 
line[MAX_AREAS],
        
Float:Pos[6];

    while (
fread(fileline))
    {
        
sscanf(line"p<,>ffffff"Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);
        
printf("%f, %f, %f, %f, %f, %f"Pos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]);

        for(new 
i<MAX_PLAYERSi++) if(IsPlayerConnected(i) && IsPlayerInArea(iPos[0], Pos[1], Pos[2], Pos[3], Pos[4], Pos[5]))
        {
            
SendClientMessage(i0xFF0000FF".!אתה נמצא באזור זה");
        }
    }
    
fclose(file);
    return 
1;
}

public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch (
dialogid)
    {
        case 
DIALOG_IPIA_MAKER:
        {
            if(!
response) return 0;
            switch(
listitem)
            {
                case 
0:
                {
                    
GetPlayerPos(playeridAreaInfo[0], AreaInfo[1], AreaInfo[2]);
                    
SendClientMessage(playerid0xCC9900FF"[Area Dynamic]: .קצה ראשון נשמר בהצלחה");
                }
                case 
1:
                {
                    
GetPlayerPos(playeridAreaInfo[3], AreaInfo[4], AreaInfo[5]);
                    
SendClientMessage(playerid0xCC9900FF"[Area Dynamic]: .קצה שני נשמר בהצלחה");
                }
                case 
2:
                {
                    if(!
response) return ShowPlayerDialog(playeridDIALOG_IPIA_MAKERDIALOG_STYLE_LIST"יוצר אזורים דינאמי""שמירת קצה ראשון\nשמירת קצה שני\n{F58282}שמירת אזור במערכת\nאיפוס שמירת קצוות""בחירה""יציאה"), 1;
                    if(!
IsUseOne() && !IsUseTwo()) return SendClientMessage(playerid0xFF0000FF"[Area Dynamic]: .עלייך לשמור שני קצוות");
                    new 
string[128];
                    
format(stringsizeof(string), "%f, %f, %f, %f, %f, %f\r\n",
                        (
AreaInfo[0] < AreaInfo[3]) ? AreaInfo[0] : AreaInfo[3],
                        (
AreaInfo[1] < AreaInfo[4]) ? AreaInfo[1] : AreaInfo[4],
                        (
AreaInfo[2] < AreaInfo[5]) ? AreaInfo[2] : AreaInfo[5],
                        (
AreaInfo[0] > AreaInfo[3]) ? AreaInfo[0] : AreaInfo[3],
                        (
AreaInfo[1] > AreaInfo[4]) ? AreaInfo[1] : AreaInfo[4],
                        (
AreaInfo[2] > AreaInfo[5]) ? AreaInfo[2] : AreaInfo[5]
                    );

                    new 
File:pos=fopen("IsPlayerInArea.ini"io_append);
                    
fwrite(posstring);
                    
fclose(pos);

                    new 
dialogstring[128];
                    
format(dialogstringsizeof(dialogstring), "\nIsPlayerInArea saved under the name {F58282}IsPlayerInArea_%s.ini {a9c4e4}inside the scriptfiles folder!\n"inputtext);
                    
ShowPlayerDialog(playerid206DIALOG_STYLE_MSGBOX" "dialogstring"Exit""");
                    
ResetAll();
                }
                default:
                {
                    if(!
IsUseOne() && !IsUseTwo()) return SendClientMessage(playerid0xFF0000FF"[Area Dynamic]: .עלייך לשמור שני קצוות");

                    
ResetAll();
                    
SendClientMessage(playerid0xCC9900FF"[Area Dynamic]: .שמירת הקצוות אופסו בהצלחה");
                }
            }
        }
    }
    return 
1;
}

IsUseOne()
    return 
AreaInfo[0] != 0.0 true:false;
    
IsUseTwo()
    return 
AreaInfo[3] != 0.0 true:false;

IsPlayerInArea(playeridFloat:MinXFloat:MinYFloat:MinZ,Float:MaxXFloat:MaxY,Float:MaxZ)
{
    new 
Float:XFloat:YFloat:Z;
    
GetPlayerPos(playeridXYZ);
    return (
>= MinX && <= MaxX && >= MinY && <= MaxY  && >= MinZ && <= MaxZ) ? 0;

i'ts all code, please help me fix the problem ...
_Application_ is offline   Reply With Quote
Old 24/05/2016, 02:32 PM   #7
JasperM
Big Clucker
 
JasperM's Avatar
 
Join Date: May 2014
Location: Eindhoven, The Netherlands
Posts: 183
Reputation: 29
Default Re: i'ts not work good... =/ help please!

I bet opening and closing a file 5 times a second is not very optimized, lol. Why not load all the areas in an array in OnGameModeInit?
__________________
i5-4460 @ 3.2 GHz + MSI R9 380 GAMING 4Gb
JasperM is offline   Reply With Quote
Old 25/05/2016, 06:51 AM   #8
_Application_
Big Clucker
 
Join Date: Apr 2012
Posts: 142
Reputation: 1
Default Re: i'ts not work good... =/ help please!

Quote:
Originally Posted by JasperM View Post
I bet opening and closing a file 5 times a second is not very optimized, lol. Why not load all the areas in an array in OnGameModeInit?
Please fix the code for me...
_Application_ is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is my PS cc work good? Glossy42O Everything and Nothing 16 01/01/2015 10:06 AM
Portforward won't work with the good settings NicholasA Server Support 1 01/05/2013 09:35 PM
command doesnt work good (+rep for helper) GTAItsMe Scripting Help 18 04/01/2013 09:03 PM
Good scripter needed to work out my ideas jurtes Help Archive 0 19/07/2011 12:05 PM
Looking for a good scripter to do some paid work James Help Archive 7 23/12/2010 07:22 PM


All times are GMT. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.