[HELP] I made a CMD /park
#1

I made a /park command that should allow players to Re-Park their cars as they want...
butt eh thing is when i do /park it Removes all the cars I have on the cars file and saves only the car i /parke...
here is the pastebin: http://pastebin.com/f21606798
Any1?
Reply
#2

Yes.. your code makes no sense at all.. VehX, VehY, VehZ.. they're global variables but they're not arrays - therefore they will just assume the same value for the last car that was parked, erasing earlier data.. you use GetPlayerPos when you should be using GetVehiclePos for accuracy, same with GetVehicleZAngle instead of GetPlayerFacingAngle, and while we're at it you could do this
pawn Код:
new vid = GetPlayerVehicleID(playerid);

GetVehiclePos(vid, VehX[vid], VehY[vid], VehZ[vid]);
GetVehicleZAngle(vid, vehAng[vid]);
Apart from that you only check if the player is in any vehicle, and if that vehicle is owned by anyone, you'll need to verify that the player owns the vehicle, and that he is currently driving it
Reply
#3

Quote:
Originally Posted by Rav
Yes.. your code makes no sense at all.. VehX, VehY, VehZ.. they're global variables but they're not arrays - therefore they will just assume the same value for the last car that was parked, erasing earlier data.. you use GetPlayerPos when you should be using GetVehiclePos for accuracy, same with GetVehicleZAngle instead of GetPlayerFacingAngle, and while we're at it you could do this
pawn Код:
new vid = GetPlayerVehicleID(playerid);

GetVehiclePos(vid, VehX[vid], VehY[vid], VehZ[vid]);
GetVehicleZAngle(vid, vehAng[vid]);
Apart from that you only check if the player is in any vehicle, and if that vehicle is owned by anyone, you'll need to verify that the player owns the vehicle, and that he is currently driving it
I'll try what you said about getting the Info, But the thing is that the info you gave is just "GET" but what is the problem with the Save?
Reply
#4

Lots of things wrong with that too.. for example, why do you read from a file you only need to write to? Why aren't you looping through all the available vehicles? Why do you try to write to a file when it's opened in io_read mode (that only allows reading a file..)? Why do you close a the file handler when you need it later on in the loop?

Try looking at some tutorials first
Reply
#5

Quote:
Originally Posted by Rav
Lots of things wrong with that too.. for example, why do you read from a file you only need to write to? Why aren't you looping through all the available vehicles? Why do you try to write to a file when it's opened in io_read mode (that only allows reading a file..)? Why do you close a the file handler when you need it later on in the loop?

Try looking at some tutorials first
Can you show a small Example of how it supposed to be.... I'm learning ...
ohh and I tried doing lie you said by checking the Vehicle Pos instead of the PlayerPos
I get this:
Код:
C:\Documents and Settings\User\Desktop\SAMP GameMode\filterscripts\VOS.pwn(233) : error 028: invalid subscript (not an array or too many subscripts): "X"
C:\Documents and Settings\User\Desktop\SAMP GameMode\filterscripts\VOS.pwn(233) : warning 215: expression has no effect
C:\Documents and Settings\User\Desktop\SAMP GameMode\filterscripts\VOS.pwn(233) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\User\Desktop\SAMP GameMode\filterscripts\VOS.pwn(233) : error 029: invalid expression, assumed zero
C:\Documents and Settings\User\Desktop\SAMP GameMode\filterscripts\VOS.pwn(233) : fatal error 107: too many error messages on one line
Here is the Command:
pawn Код:
if(strcmp(cmdtext, "/park", true) == 0)
    {
      if(IsPlayerInAnyVehicle(playerid))
      {
            new vID = GetPlayerVehicleID(playerid);
        new Float:X, Float:Y, Float:Z, Float:A;
          GetVehiclePos(vID, X[vID], Y[vID], Z[vID]);
            GetVehicleZAngle(vID, A[vID]);
        vehX = X;
        vehY = Y;
        vehZ = Z;
        vehAng = A;
            SaveCars();
        }
        return 1;
    }
I know it doesn't check if the player owns the Vehicle, I want to fix the Saving problem first
Reply
#6

pawn Код:
if(strcmp(cmdtext, "/park", true) == 0)
  {
    if(IsPlayerInAnyVehicle(playerid))
    {
      new vID = GetPlayerVehicleID(playerid);
      GetVehiclePos(vID, X[vID], Y[vID], Z[vID]);
      GetVehicleZAngle(vID, A[vID]);
 
      SaveCars();
    }
    return 1;
  }
a bit like that, at the top you'll need to define
pawn Код:
new Float: X[MAX_VEHICLES], Float: Y[MAX_VEHICLES], Float: Z[MAX_VEHICLeS, Float: A[MAX_VEHICLES];
Reply
#7

Thanks that Worked..
Please can you show me whats wrong with my Saving Callback!?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)