SA-MP Forums Archive
Moving Gate Help - 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: Moving Gate Help (/showthread.php?tid=499394)



Moving Gate Help - ChuckyBabe - 08.03.2014

PHP Code:
#include a_samp
#include zcmd
#include Dini
#define MAX_GATES                       20
#define GATE_OBJECT                     980
#define GATE_STATE_CLOSED       0
#define GATE_STATE_OPEN         1
enum fs_gates
{
        
gCreated,
        
Float:gX,
        
Float:gY,
        
Float:gZ,
        
Float:gA,
        
gObject,
        
gPlacedBy[24],
        
gStatus,
        
gPassword
}
new 
GateInfo[MAX_GATES][fs_gates];
CMD:placegateplayeridparams[] )
{
        if( 
isnullparams) )
            return 
SendClientMessageplayerid, -1"Syntax: /placegate [password]" );
        if( !
strvalparams ) )
            return 
SendClientMessageplayerid, -1"You need to input numbers." );
        if( 
IsPlayerInAnyVehicleplayerid ) )
            return 
SendClientMessageplayerid, -1"You need to exit your vehicle." );
        new 
Float:pPos[4];
        
GetPlayerPosplayeridpPos[0], pPos[1], pPos[2] );
        
GetPlayerFacingAngleplayeridpPos[3] );
        
CreateGateplayeridstrvalparams ), pPos[0], pPos[1], pPos[2], pPos[3] );
        
SendClientMessageplayerid, -1"You succesfully created a movable gate. Use /gopen or /gclose." );
        return 
1;
}
CMD:gopenplayeridparams[] )
{
        if( 
isnullparams ) )
            return 
SendClientMessageplayerid, -1"Syntax: /gopen [password]" );
        new 
szName[24], gate = -1;
        
GetPlayerNameplayeridszName24 );
        for( new 
0!= MAX_GATESi++ )
                if( 
GateInfo[i][gCreated] == )
                        if( 
strvalparams ) == GateInfo[i][gPassword] )
                                { 
gate i; break; }
        if( 
gate != -)
        {
            if( !
IsObjectMovingGateInfo[gate][gObject] ) )
            {
                if( 
IsPlayerInRangeOfPointplayerid10.0GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
                        {
                                if( 
GateInfo[gate][gStatus] == GATE_STATE_CLOSED )
                        {
                                    
MoveObjectGateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]-5.37.0 );
                                        
SendClientMessageplayerid, -1"You opened the gate." );
                                }
                                else
                                return 
SendClientMessageplayerid, -1"The gate is already open." );
                        }
                        else
                        return 
SendClientMessageplayerid, -1"You're not near any gate." );
        }
        else
                return 
SendClientMessageplayerid, -1"You must wait untill the gate has moved." );
        }
        else
            return 
SendClientMessageplayerid, -1"Invalid password." );
        return 
1;
}
CMD:gcloseplayeridparams[] )
{
        if( 
isnullparams ) )
            return 
SendClientMessageplayerid, -1"Syntax: /gclose [password]" );
        new 
szName[24], gate = -1;
        
GetPlayerNameplayeridszName24 );
        for( new 
0!= MAX_GATESi++ )
                if( 
GateInfo[i][gCreated] == )
                        if( 
strvalparams ) == GateInfo[i][gPassword] )
                                { 
gate i; break; }
        if( 
gate != -)
        {
            if( !
IsObjectMovingGateInfo[gate][gObject] ) )
            {
                if( 
IsPlayerInRangeOfPointplayerid10.0GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
                        {
                                if( 
GateInfo[gate][gStatus] == GATE_STATE_OPEN )
                        {
                                    
MoveObjectGateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]+5.37.0 );
                                        
SendClientMessageplayerid, -1"You closed the gate." );
                                }
                                else
                                return 
SendClientMessageplayerid, -1"The gate is already closed." );
                        }
                        else
                                return 
SendClientMessageplayerid, -1"You're not near any gate." );
        }
        else
                return 
SendClientMessageplayerid, -1"You must wait untill the gate has moved." );
        }
        else
            return 
SendClientMessageplayerid, -1"Invalid password." );
        return 
1;
}
CMD:removegateplayeridparams[] )
{
        for( new 
0!= MAX_GATESi++ )
        {
                if( 
GateInfo[i][gCreated] == )
                {
                    if( 
IsPlayerInRangeOfPointplayerid10.0GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
                        {
                                new 
szName[24];
                                
GetPlayerNameplayeridszName24 );
                                if( !
strcmpszNameGateInfo[i][gPlacedBy], true ) || IsPlayerAdminplayerid ) )
                                {
                                        
DestroyObjectGateInfo[i][gObject] );
                                        
formatGateInfo[i][gPlacedBy], 24"None" );
                                
GateInfo[i][gCreated] = 0;
                                
GateInfo[i][gX] = 0.0;
                                
GateInfo[i][gY] = 0.0;
                                
GateInfo[i][gZ] = 0.0;
                                
GateInfo[i][gA] = 0.0;
                                
GateInfo[i][gPassword] = 0;
                                
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
                                
SendClientMessageplayerid, -1"You removed the gate." );
                                        new 
file[32];
                                        
formatfile32"Gates/gate_%d.ini");
                                        if( 
dini_Existsfile ) )
                                        
dini_Removefile );
                                        break;
                }
                                else
                                        return 
SendClientMessageplayerid, -1"You don't own this gate." );
                        }
                        else
                                return 
SendClientMessageplayerid, -1"You're not near any gate." );
        }
    }
        return 
1;
}
CMD:gateinfoplayeridparams[] )
{
        if( 
IsPlayerAdminplayerid ) )
        {
                for( new 
0!= MAX_GATESi++ )
                {
                        if( 
GateInfo[i][gCreated] == )
                        {
                            if( 
IsPlayerInRangeOfPointplayerid5.0GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
                                {
                                        new 
szString[128];
                                        
formatszString128"Gate Info( Placed by: %s | Password: %d)"GateInfo[i][gPlacedBy], GateInfo[i][gPassword] );
                                        
SendClientMessageplayerid, -1szString );
                                        return 
1;
                                }
                                else
                                        return 
SendClientMessageplayerid, -1"You're not near any gate." );
                }
            }
    }
        else
                return 
SendClientMessageplayerid, -1"You're not an admin." );
        return 
1;
}
public 
OnFilterScriptInit( )
{
        for( new 
0!= MAX_GATESi++ )
        {
            if( 
GateInfo[i][gCreated] == )
            {
                        new 
file[64];
                        
formatfile64"Gates/gate_%d.ini");
                        if( 
fexistfile ) )
                        {
                            
GateInfo[i][gCreated] = 1;
                                
GateInfo[i][gX] = dini_Floatfile"X" );
                                
GateInfo[i][gY] = dini_Floatfile"Y" );
                                
GateInfo[i][gZ] = dini_Floatfile"Z" );
                                
GateInfo[i][gA] = dini_Floatfile"A" );
                                
GateInfo[i][gStatus] = dini_Intfile"Status" );
                                
GateInfo[i][gPassword] = dini_Intfile"Password" );
                                
formatGateInfo[i][gPlacedBy], 24dini_Getfile"PlacedBy" ) );
                                
GateInfo[i][gObject] = CreateObjectGATE_OBJECTGateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ], 00GateInfo[i][gA] );
            }
        }
    }
        return 
1;
}
public 
OnFilterScriptExit( )
{
        for( new 
0!= MAX_GATESi++ )
        {
            if( 
GateInfo[i][gCreated] == )
            {
                        new 
file[64];
                        
formatfile64"Gates/gate_%d.ini");
                        if( 
fexistfile ) )
                        {
                                
dini_IntSetfile"Object"GateInfo[i][gObject] );
                                
dini_FloatSetfile"X"GateInfo[i][gX] );
                                
dini_FloatSetfile"Y"GateInfo[i][gY] );
                                
dini_FloatSetfile"Z"GateInfo[i][gZ] );
                                
dini_FloatSetfile"A"GateInfo[i][gA] );
                                
dini_IntSetfile"Status"GateInfo[i][gStatus] );
                                
dini_IntSetfile"Password"GateInfo[i][gPassword] );
                                
dini_Setfile"PlacedBy"GateInfo[i][gPlacedBy] );
                                
DestroyObjectGateInfo[i][gObject] );
                                
formatGateInfo[i][gPlacedBy], 24"None" );
                        
GateInfo[i][gCreated] = 0;
                        
GateInfo[i][gX] = 0.0;
                        
GateInfo[i][gY] = 0.0;
                        
GateInfo[i][gZ] = 0.0;
                        
GateInfo[i][gA] = 0.0;
                        
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
            }
        }
    }
        return 
1;
}
public 
OnObjectMovedobjectid )
{
        for( new 
0!= MAX_GATESi++ )
        {
            if( 
GateInfo[i][gCreated] == )
            {
                if( 
GateInfo[i][gObject] == objectid )
                {
                    if( 
GateInfo[i][gStatus] == GATE_STATE_CLOSED )
                        
GateInfo[i][gStatus] = GATE_STATE_OPEN;
                                else if( 
GateInfo[i][gStatus] == GATE_STATE_OPEN )
                                    
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
                                
// Update the variables.
                                
new Float:oPos[3];
                                
GetObjectPosobjectidoPos[0], oPos[1], oPos[2] );
                                
GateInfo[i][gX] = oPos[0];
                        
GateInfo[i][gY] = oPos[1];
                        
GateInfo[i][gZ] = oPos[2];
                                break;
            }
        }
    }
    return 
1;
}
stock CreateGateplayeridpasswordFloat:xFloat:yFloat:zFloat:)
{
        for( new 
0!= MAX_GATESi++ )
        {
            if( 
GateInfo[i][gCreated] == )
            {
                        new 
szName[24];
                        
GetPlayerNameplayeridszName24 );
                        
GateInfo[i][gObject] = CreateObjectGATE_OBJECTxyz+1.500);
                        
formatGateInfo[i][gPlacedBy], 24"%s"szName );
                
GateInfo[i][gCreated] = 1;
                
GateInfo[i][gX] = x;
                
GateInfo[i][gY] = y;
                
GateInfo[i][gZ] = z+1.5// comment the +1.5 if you're not using object 980.
                
GateInfo[i][gA] = a;
                        
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
                        
GateInfo[i][gPassword] = password;
                        
SetPlayerPosplayeridx+1y+1);
                        new 
file[64];
                        
formatfile64"Gates/gate_%d.ini");
                        if( !
fexistfile ) )
                        {
                            
dini_Createfile );
                                
dini_IntSetfile"Object"GateInfo[i][gObject] );
                                
dini_FloatSetfile"X"GateInfo[i][gX] );
                                
dini_FloatSetfile"Y"GateInfo[i][gY] );
                                
dini_FloatSetfile"Z"GateInfo[i][gZ] );
                                
dini_FloatSetfile"A"GateInfo[i][gA] );
                                
dini_IntSetfile"Status"GateInfo[i][gStatus] );
                                
dini_Setfile"PlacedBy"GateInfo[i][gPlacedBy] );
            }
                        break;
        }
    }

So this is code i see it here in samp

so all i want to do it only admin lvl 6 can use this [pAdmin]
All of cmd given by me !

thanks in advance ! i will give you +rep


Re: Moving Gate Help - Keyhead - 08.03.2014

Just add this at the start of the CMD.
pawn Code:
if(Player[playerid][pAdmin] >= 6)



Re: Moving Gate Help - ChuckyBabe - 08.03.2014

Where ?

example
if(Player[playerid][pAdmin] >= 6)
CMDlacegate ?


Re: Moving Gate Help - ChuckyBabe - 08.03.2014

Can you modify this ? give an example


Re: Moving Gate Help - ChuckyBabe - 08.03.2014

Modify this only
for level 6 admin
can only use

cmd : placegate
and cmd : deletegate


Re: Moving Gate Help - Pottus - 08.03.2014

Ask the person who made the script, scripting help is for people who know how to script already not so people can write code for you especially considering how simple this is read some tutorials or something.