SA-MP Forums Archive
How to make [...] - 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: How to make [...] (/showthread.php?tid=578713)



How to make [...] - Sn4ke2 - 21.06.2015

Hello all, how to make this command can be used only near the car because I can use Command everywhere.
PHP код:
if(strcmp(cmd"/lock1"true) == 0)
    {
        
ShowPlayerDialog(playerid,DIALOG_MASINI,DIALOG_STYLE_LIST,"Masini personale:","1. Masina\n2. Motocicleta\n3. Helicopter","Ok","Close");
        return 
1;
    } 
OnDialogResponse

PHP код:
if(dialogid == DIALOG_MASINI)
        {
            if(
response)
            {
                if(
listitem == 0)
                {
                        new 
query[128];
                        new 
carid PlayerData[playerid][pPcarkey];
                        if(
CarData[carid][cLockk] == 0)
                        {
                            
SendClientMessage(playeridCOLOR_GRAD1"Masina personala a fost incuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 1;
                            
VehLocked[carid+PreVehicle] = 1;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,1,bonnet,boot,objective);
                            
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d",CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                        else
                        {
                            
SendClientMessage(playeridCOLOR_GRAD1"Masina personala a fost descuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 0;
                            
VehLocked[carid+PreVehicle] = 0;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,0,bonnet,boot,objective);
                        
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d"CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                    
                }
                if(
listitem == 1)
                {
                        new 
query[128];
                        new 
carid PlayerData[playerid][pPcarkey2];
                        if(
CarData[carid][cLockk] == 0)
                        {
                            
SendClientMessage(playeridCOLOR_GRAD1"Motocicleta personala a fost incuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 1;
                            
VehLocked[carid+PreVehicle] = 1;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,1,bonnet,boot,objective);
                        
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d"CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                        else
                        {
                           
SendClientMessage(playeridCOLOR_GRAD1"Motocicleta personala a fost descuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 0;
                            
VehLocked[carid+PreVehicle] = 0;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,0,bonnet,boot,objective);
                            
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d"CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                    
                }
                if(
listitem == 2)
                {
                        new 
query[128];
                    
                        new 
carid PlayerData[playerid][pPcarkey3];
                        if(
CarData[carid][cLockk] == 0)
                        {
                        
SendClientMessage(playeridCOLOR_GRAD1"Barca/avionul a fost descuiat/a.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 1;
                            
VehLocked[carid+PreVehicle] = 1;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,1,bonnet,boot,objective);
                                        
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d"CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                        else
                        {
                           
SendClientMessage(playeridCOLOR_GRAD1"Barca/avionul a fost incuiat/a.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarData[carid][cLockk] = 0;
                            
VehLocked[carid+PreVehicle] = 0;
                            
GetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid+PreVehicle,engine,lights,alarm,0,bonnet,boot,objective);
                                        
format(querysizeof(query), "UPDATE cars SET Lockk='%d' WHERE id=%d"CarData[carid][cLockk], carid);
                        
mysql_query(query);
                            return 
1;
                        }
                    
                }
                if(
listitem == 3)
                {
                    
                    
                        new 
carid HireCar[playerid];
                        if(
CarLocked[HireCar[playerid]] == 0)
                        {
                        
SendClientMessage(playeridCOLOR_GRAD1"Masina inchiriata a fost descuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarLocked[HireCar[playerid]] = 1;
                            
VehLocked[carid] = 1;
                            
GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid,engine,lights,alarm,1,bonnet,boot,objective);
                            return 
1;
                        }
                        else
                        {
                                
SendClientMessage(playeridCOLOR_GRAD1"Masina inchiriata a fost incuiata.");
                            
PlayerPlaySound(playerid11450.00.00.0);
                            
CarLocked[HireCar[playerid]] = 0;
                            
VehLocked[carid] = 0;
                            
GetVehicleParamsEx(carid,engine,lights,alarm,doors,bonnet,boot,objective);
                            
SetVehicleParamsEx(carid,engine,lights,alarm,0,bonnet,boot,objective);
                            return 
1;
                        }
                    
                }
            }
        } 
+ REPPPP


Re: How to make [...] - Dusan01 - 21.06.2015

use this:
PHP код:
stock IsPlayerNearVehicle(playeridvehicleidFloat:range)
{
    new 
Float:XFloat:YFloat:Z;
    
GetVehiclePos(vehicleidXYZ);
    if(
IsPlayerInRangeOfPoint(playeridrangeXYZ))return true;
    else return 
false;

and use it like this in dialog:
PHP код:
IsPlayerNearVehicle(playeridcarid+PreVehicle5.0); 



Re: How to make [...] - Crayder - 21.06.2015

@Dusan: No, and what is this?
pawn Код:
new m = GetVehicleModel(vehicleid);
    if(m == 0) return 0;
Haven't you heard of IsValidVehicle? Yes, it's a real thing.

pawn Код:
#define FLOAT_INFINITY (Float:0x7F800000)
native IsValidVehicle(vehicleid);
stock GetPlayerNearestVehicle(playerid)
{
    new v = -1, Float:d = FLOAT_INFINITY, Float:p[6], FLoat:tmp;
    GetPlayerPos(playerid, p[0], p[1], p[2]);
    p[0] -= p[3]; p[1] -= p[4]; p[2] -= p[5];
    for(new i; i < MAX_VEHICLES; i++) if(IsValidVehicle(i)) {
        GetVehiclePos(i, p[3], p[4], p[5]);
        tmp = floatround(floatsqroot((p[0] * p[0]) + (p[1] * p[1]) + (p[2] * p[2])));
        if(tmp < d) {
            d = tmp;
            v = i;
        }
    }
    return IsValidVehicle(v) ? v : INVALID_VEHICLE_ID;
}



Re: How to make [...] - SickAttack - 21.06.2015

I would do it like this:
pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <zcmd>

// NATIVES:

native IsValidVehicle(vehicleid);

// MAIN:

main()
{
    print("Development Mode: closest_vehicle_to_player.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:closestvehicle(playerid, params[])
{
    new string[144], closest_vehicle = GetClosestVehicleToPlayer(playerid);
    if(closest_vehicle == -1)
    {
        strcat(string, "No vehicles have been found.");
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        new Float:x, Float:y, Float:z, Float:distance;
        GetVehiclePos(closest_vehicle, x, y, z);
        distance = GetPlayerDistanceFromPoint(playerid, x, y, z);

        format(string, sizeof(string), "Vehicle with the ID %d is the closest vehicle to you (%0.2f meters).", closest_vehicle, distance);
        SendClientMessage(playerid, -1, string);
    }
    return 1;
}

// FUNCTIONS:

stock GetClosestVehicleToPlayer(playerid)
{
    new Float:x, Float:y, Float:z, closest_vehicle = -1, Float:distance, Float:temp;

    new pool = GetVehiclePoolSize();
    for(new i = 1; i <= pool; i ++)
    {
        if(!IsValidVehicle(i)) continue;

        GetVehiclePos(i, x, y, z);

        if(closest_vehicle != -1)
        {
            temp = GetPlayerDistanceFromPoint(playerid, x, y, z);

            if(temp < distance)
            {
                closest_vehicle = i;
                distance = temp;
            }
        }
        else
        {
            closest_vehicle = i;
            distance = GetPlayerDistanceFromPoint(playerid, x, y, z);
        }
    }
    return closest_vehicle;
}



Re: How to make [...] - Sn4ke2 - 21.06.2015

I'm done! thank you all