CMD Proplem !!
#1

Hi ! , i was trying to make a /park CMd , but when im trying it in game , its don't save the vehicle position

PHP код:
CMD:park(playerid,params[])
{
    new 
playerstates GetPlayerState(playerid);
    new 
Float:x,Float:y,Float:z;
    if(
playerstates == PLAYER_STATE_DRIVER)
    {
        new 
storedid GetPlayerVehicleID(playerid);
        for(new 
i=0;i<MAX_PCARS;i++)
        {
            if(
storedid == PlayerVehicles[playerid][i][pCarID])
            {
                
GetPlayerPos(playeridx,y,z);
                new 
Float:arot;
                
GetPlayerFacingAngle(playeridarot);
                
PlayerVehicles[playerid][i][pCarX] = x;
                
PlayerVehicles[playerid][i][pCarY] = y;
                
PlayerVehicles[playerid][i][pCarZ] = z;
                
PlayerVehicles[playerid][i][pCarRot] = arot;
                
SendClientMessage(playeridCOLOR_GREEN"You successfully parked the car in your location!");
                return 
1;
            }
        }
        
SendClientMessage(playeridCOLOR_RED"This is not your car!");
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"You must be the driver of the car!");
        return 
1;
    }
    return 
1;

Reply
#2

. sorry for posting By Wrong !!
Reply
#3

PHP код:
CMD:park(playerid,params[])
{
    new 
playerstates GetPlayerState(playerid);
    new 
Float:xFloat:yFloat:zFloat:rot;
    if(
playerstates == PLAYER_STATE_DRIVER)
    {
        new 
storedid GetPlayerVehicleID(playerid);
        for(new 
i=0;i<MAX_PCARS;i++)
        {
            if(
storedid == PlayerVehicles[playerid][i][pCarID])
            {
                
GetVehiclePos(storedidxyz);
                
GetVehicleZAngle(storedidarot);
                
PlayerVehicles[playerid][i][pCarX] = x;
                
PlayerVehicles[playerid][i][pCarY] = y;
                
PlayerVehicles[playerid][i][pCarZ] = z;
                
PlayerVehicles[playerid][i][pCarRot] = arot;
                
SendClientMessage(playeridCOLOR_GREEN"You successfully parked the car in your location!");
                return 
1;
            }
        }
        
SendClientMessage(playeridCOLOR_RED"This is not your car!");
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"You must be the driver of the car!");
        return 
1;
    }
    return 
1;

Reply
#4

Quote:
Originally Posted by IgorLuiz
Посмотреть сообщение
PHP код:
CMD:park(playerid,params[])
{
    new 
playerstates GetPlayerState(playerid);
    new 
Float:xFloat:yFloat:zFloat:rot;
    if(
playerstates == PLAYER_STATE_DRIVER)
    {
        new 
storedid GetPlayerVehicleID(playerid);
        for(new 
i=0;i<MAX_PCARS;i++)
        {
            if(
storedid == PlayerVehicles[playerid][i][pCarID])
            {
                
GetVehiclePos(storedidxyz);
                
GetVehicleZAngle(storedidarot);
                
PlayerVehicles[playerid][i][pCarX] = x;
                
PlayerVehicles[playerid][i][pCarY] = y;
                
PlayerVehicles[playerid][i][pCarZ] = z;
                
PlayerVehicles[playerid][i][pCarRot] = arot;
                
SendClientMessage(playeridCOLOR_GREEN"You successfully parked the car in your location!");
                return 
1;
            }
        }
        
SendClientMessage(playeridCOLOR_RED"This is not your car!");
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"You must be the driver of the car!");
        return 
1;
    }
    return 
1;

You basically did nothing, but remove the variable "arot", call it "rot", and still use it as "arot".

pawn Код:
CMD:park(playerid,params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid), bool:found = false;
        for(new i = 0; i < MAX_PCARS; i ++)
        {
            if(PlayerVehicles[playerid][i][pCarID] == vehicleid)
            {
                new Float:x, Float:y, Float:z, Float:rot;
                GetVehiclePos(vehicleid, x, y, z);
                GetVehicleZAngle(vehicleid, rot);

                PlayerVehicles[playerid][i][pCarX] = x;
                PlayerVehicles[playerid][i][pCarY] = y;
                PlayerVehicles[playerid][i][pCarZ] = z;
                PlayerVehicles[playerid][i][pCarRot] = rot;

                SendClientMessage(playerid, COLOR_GREEN, "You successfully parked your car at your location.");
               
                found = true;
                break;
            }
        }

        if(!found)
        {
            SendClientMessage(playerid, COLOR_RED, "This is not your car.");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You must be the driver of the car.");
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You basically did nothing, but remove the variable "arot", call it "rot", and still use it as "arot".

pawn Код:
CMD:park(playerid,params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid), bool:found = false;
        for(new i = 0; i < MAX_PCARS; i ++)
        {
            if(PlayerVehicles[playerid][i][pCarID] == vehicleid)
            {
                new Float:x, Float:y, Float:z, Float:rot;
                GetVehiclePos(vehicleid, x, y, z);
                GetVehicleZAngle(vehicleid, rot);

                PlayerVehicles[playerid][i][pCarX] = x;
                PlayerVehicles[playerid][i][pCarY] = y;
                PlayerVehicles[playerid][i][pCarZ] = z;
                PlayerVehicles[playerid][i][pCarRot] = rot;

                SendClientMessage(playerid, COLOR_GREEN, "You successfully parked your car at your location.");
               
                found = true;
                break;
            }
        }

        if(!found)
        {
            SendClientMessage(playerid, COLOR_RED, "This is not your car.");
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You must be the driver of the car.");
    }
    return 1;
}
I did not do nothing? look marked in green

Код:
CMD:park(playerid,params[]) 
{ 
    new playerstates = GetPlayerState(playerid); 
    new Float:x, Float:y, Float:z, Float:rot; 
    if(playerstates == PLAYER_STATE_DRIVER) 
    { 
        new storedid = GetPlayerVehicleID(playerid); 
        for(new i=0;i<MAX_PCARS;i++) 
        { 
            if(storedid == PlayerVehicles[playerid][i][pCarID]) 
            { 
                GetVehiclePos(storedid, x, y, z); 
                GetVehicleZAngle(storedid, arot); 
                PlayerVehicles[playerid][i][pCarX] = x; 
                PlayerVehicles[playerid][i][pCarY] = y; 
                PlayerVehicles[playerid][i][pCarZ] = z; 
                PlayerVehicles[playerid][i][pCarRot] = arot; 
                SendClientMessage(playerid, COLOR_GREEN, "You successfully parked the car in your location!"); 
                return 1; 
            } 
        } 
        SendClientMessage(playerid, COLOR_RED, "This is not your car!"); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_RED, "You must be the driver of the car!"); 
        return 1; 
    } 
    return 1; 
}
Reply
#6

Quote:
Originally Posted by IgorLuiz
Посмотреть сообщение
I did not do nothing? look marked in green

Код:
CMD:park(playerid,params[]) 
{ 
    new playerstates = GetPlayerState(playerid); 
    new Float:x, Float:y, Float:z, Float:rot; 
    if(playerstates == PLAYER_STATE_DRIVER) 
    { 
        new storedid = GetPlayerVehicleID(playerid); 
        for(new i=0;i<MAX_PCARS;i++) 
        { 
            if(storedid == PlayerVehicles[playerid][i][pCarID]) 
            { 
                GetVehiclePos(storedid, x, y, z); 
                GetVehicleZAngle(storedid, arot); 
                PlayerVehicles[playerid][i][pCarX] = x; 
                PlayerVehicles[playerid][i][pCarY] = y; 
                PlayerVehicles[playerid][i][pCarZ] = z; 
                PlayerVehicles[playerid][i][pCarRot] = arot; 
                SendClientMessage(playerid, COLOR_GREEN, "You successfully parked the car in your location!"); 
                return 1; 
            } 
        } 
        SendClientMessage(playerid, COLOR_RED, "This is not your car!"); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_RED, "You must be the driver of the car!"); 
        return 1; 
    } 
    return 1; 
}
Код:
CMD:park(playerid,params[]) 
{ 
    new playerstates = GetPlayerState(playerid); 
    new Float:x, Float:y, Float:z, Float:rot; 
    if(playerstates == PLAYER_STATE_DRIVER) 
    { 
        new storedid = GetPlayerVehicleID(playerid); 
        for(new i=0;i<MAX_PCARS;i++) 
        { 
            if(storedid == PlayerVehicles[playerid][i][pCarID]) 
            { 
                GetVehiclePos(storedid, x, y, z); 
                GetVehicleZAngle(storedid, arot);
                PlayerVehicles[playerid][i][pCarX] = x; 
                PlayerVehicles[playerid][i][pCarY] = y; 
                PlayerVehicles[playerid][i][pCarZ] = z; 
                PlayerVehicles[playerid][i][pCarRot] = arot; 
                SendClientMessage(playerid, COLOR_GREEN, "You successfully parked the car in your location!"); 
                return 1; 
            } 
        } 
        SendClientMessage(playerid, COLOR_RED, "This is not your car!"); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_RED, "You must be the driver of the car!"); 
        return 1; 
    } 
    return 1; 
}
  • Different names.
  • You should break the loop, instead of returning a value.
  • Creating unnecessary variables (you do not need them initialized if they aren't going to be used).
  • An unnecessary return.
  • Grammar issues.
  • Abusing whitespaces, damn...
Reply
#7

Try this code you can customize it the way you want.


PHP код:
CMD:park(playeridparams[])
{
    if(
PlayerInfo[playerid][pVehicleKeysFrom] != INVALID_PLAYER_ID)
    {
        new 
ownerid PlayerInfo[playerid][pVehicleKeysFrom];
        if(
IsPlayerConnected(ownerid))
        {
            new 
PlayerInfo[playerid][pVehicleKeys];
            if(
IsPlayerInVehicle(playeridPlayerVehicleInfo[ownerid][d][pvId]))
            {
                if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playeridCOLOR_GREY"You must be in the driver seat.");
                new 
Float:xFloat:yFloat:zFloat:angleFloat:health;
                
GetVehicleHealth(PlayerVehicleInfo[ownerid][d][pvId], health);
                if(
health 800) return SendClientMessage(playeridCOLOR_GREY" Your vehicle is too damaged to park it.");
                if(
PlayerInfo[playerid][pLockCar] == GetPlayerVehicleID(playerid)) PlayerInfo[playerid][pLockCar] = INVALID_VEHICLE_ID;
                if(
IsARC(GetPlayerVehicleID(playerid))) // RC Vehicles
                
{
                    new 
Float:vehPos[3];
                    
GetVehiclePos(GetPlayerVehicleID(playerid),vehPos[0], vehPos[1], vehPos[2]);
                    
SetPlayerPos(playerid,vehPos[0], vehPos[1]+0.5vehPos[2]+0.5);
                }
                if(
IsValidDynamicObject(GetPVarInt(PlayerVehicleInfo[ownerid][d][pvId], "neon2")) && GetPVarInt(PlayerVehicleInfo[ownerid][d][pvId], "neon3")) {
                     
DestroyDynamicObject(GetPVarInt(PlayerVehicleInfo[ownerid][d][pvId], "neon2")); DestroyDynamicObject(GetPVarInt(PlayerVehicleInfo[ownerid][d][pvId], "neon3"));
                   }
                
GetVehiclePos(PlayerVehicleInfo[ownerid][d][pvId], xyz);
                
GetVehicleZAngle(PlayerVehicleInfo[ownerid][d][pvId], angle);
                
SurfingCheck(GetPlayerVehicleID(playerid));
                
PlayerVehicleInfo[ownerid][d][pvVirtualWorld] = GetPlayerVirtualWorld(playerid);
                  
PlayerVehicleInfo[ownerid][d][pvInterior] = GetPlayerInterior(playerid);
                
UpdatePlayerVehicleParkPosition(owneriddxyzanglehealth);
                
PutPlayerInVehicle(playeridGetPlayerVehicleID(playerid), 0);
                 
SetPlayerArmedWeapon(playerid0);
                new 
string[29 + (MAX_PLAYER_NAME 2)];
                
format(stringsizeof(string), "* %s has parked %s's vehicle."GetPlayerNameEx(playerid), GetPlayerNameEx(ownerid));
                
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                return 
1;
            }
        }
    }
    for(new 
MAX_PLAYERVEHICLESd++)
    {
        if(
IsPlayerInVehicle(playeridPlayerVehicleInfo[playerid][d][pvId]))
        {
            new 
Float:xFloat:yFloat:zFloat:angleFloat:health;
            
GetVehicleHealth(PlayerVehicleInfo[playerid][d][pvId], health);
            if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playeridCOLOR_GREY"You must be in the driver seat.");
            if(
health 800) return SendClientMessage(playeridCOLOR_GREY" Your vehicle is too damaged to park it.");
            if(
PlayerInfo[playerid][pLockCar] == GetPlayerVehicleID(playerid)) PlayerInfo[playerid][pLockCar] = INVALID_VEHICLE_ID;
            if(
IsValidDynamicObject(GetPVarInt(PlayerVehicleInfo[playerid][d][pvId], "neon2")) && GetPVarInt(PlayerVehicleInfo[playerid][d][pvId], "neon3")) {
                
DestroyDynamicObject(GetPVarInt(PlayerVehicleInfo[playerid][d][pvId], "neon2")); DestroyDynamicObject(GetPVarInt(PlayerVehicleInfo[playerid][d][pvId], "neon3"));
            }
            
GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], xyz);
            
GetVehicleZAngle(PlayerVehicleInfo[playerid][d][pvId], angle);
            
SurfingCheck(GetPlayerVehicleID(playerid));
            
PlayerVehicleInfo[playerid][d][pvVirtualWorld] = GetPlayerVirtualWorld(playerid);
            
PlayerVehicleInfo[playerid][d][pvInterior] = GetPlayerInterior(playerid);
            
UpdatePlayerVehicleParkPosition(playeriddxyzanglehealth);
            
PutPlayerInVehicle(playeridPlayerVehicleInfo[playerid][d][pvId], 0);
            
SetPlayerArmedWeapon(playerid0);
            new 
string[30 + (MAX_PLAYER_NAME 2)];
            
format(stringsizeof(string), "* %s has parked their vehicle."GetPlayerNameEx(playerid));
            
ProxDetector(30.0playeridstringCOLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            return 
1;
        }
    }
    
SendClientMessage(playeridCOLOR_GREY"You need to be inside a vehicle that you own.");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)