SA-MP Forums Archive
Repair Vehicle Fully - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Repair Vehicle Fully (/showthread.php?tid=72284)



Repair Vehicle Fully - Alec24 - 07.04.2009

This code just crashes my game but why.
pawn Код:
if(strcmp(cmdtext, "/fix", true) == 0)
  {
      if(IsPlayerInAnyVehicle(playerid))
        {
            new curveh;
            new newveh;
            new Float:X,Float:Y,Float:Z;
            new Float:ang;
            curveh = GetPlayerVehicleID(playerid);
            GetPlayerPos(playerid,X,Y,Z);
            ang = GetPlayerFacingAngle(playerid,ang);
            newveh = CreateVehicle(curveh,X,Y,Z,ang,-1,-1,0);
            DestroyVehicle(curveh);
            PutPlayerInVehicle(playerid,newveh,0);
            GivePlayerMoney(playerid, -500);
            GameTextForPlayer(playerid, "Fixed ($500)",5000,5);
            }else{
            GameTextForPlayer(playerid, "You Are Not In A Vehicle To Fix!",5000,5);
        }
        return 1;
    }



Re: Repair Vehicle Fully - Rks25 - 07.04.2009

you are destroying it with player in it?


Re: Repair Vehicle Fully - On_Top_Non_Stop - 07.04.2009

Because curveh will be the vehicle id not the model.

Try:
pawn Код:
if(strcmp(cmdtext, "/fix", true) == 0)
{
  if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
    new Float:X,Float:Y,Float:Z,Float:Angle,OldV,OldVM,NewV;
    OldV = GetPlayerVehicleID(playerid);
    OldVM = GetVehicleModel(OldV);
    GetPlayerPos(playerid,X,Y,Z);
    GetPlayerFacingAngle(playerid,Angle);
    SetPlayerPos(playerid,X,Y,Z+2);
    DestroyVehicle(OldV);
    NewV = CreateVehicle(OldVM,X,Y,Z,Angle,-1,-1,0);
    PutPlayerInVehicle(playerid,NewV,0);
    GivePlayerMoney(playerid, -500);
    GameTextForPlayer(playerid, "Fixed ($500)",5000,5);
  }
  else
  {
    GameTextForPlayer(playerid, "You Are Not In A Vehicle To Fix!",5000,5);
  }
  return 1;
}
Not tested!


Re: Repair Vehicle Fully - Alec24 - 07.04.2009

Quote:
Originally Posted by Rk_
you are destroying it with player in it?
In this code the player is removed but it still crashes.
pawn Код:
if(strcmp(cmdtext, "/fix", true) == 0)
  {
      if(IsPlayerInAnyVehicle(playerid))
        {
            new curveh;
            new newveh;
            new Float:X,Float:Y,Float:Z;
            new Float:ang;
            curveh = GetPlayerVehicleID(playerid);
            GetPlayerPos(playerid,X,Y,Z);
            ang = GetPlayerFacingAngle(playerid,ang);
            newveh = CreateVehicle(curveh,X,Y,Z,ang,-1,-1,0);
            RemovePlayerFromVehicle(playerid);
            DestroyVehicle(curveh);
            PutPlayerInVehicle(playerid,newveh,0);
            GivePlayerMoney(playerid, -500);
            GameTextForPlayer(playerid, "Fixed ($500)",5000,5);
            }else{
            GameTextForPlayer(playerid, "You Are Not In A Vehicle To Fix!",5000,5);
        }
        return 1;
    }
Quote:
Originally Posted by OnTop2K9
Because curveh will be the vehicle id not the model.
Any idea how to get the model of the curveh


Re: Repair Vehicle Fully - BMUK - 07.04.2009

GetVehicleModel(vehicleid)


Re: Repair Vehicle Fully - Alec24 - 07.04.2009

BM[UK] That now works, the only problem is the angle can be a bit weird. Also is there any way to find the cars colour instead of random.


Re: Repair Vehicle Fully - ICECOLDKILLAK8 - 07.04.2009

No, Not without using custom SetVehicleColor functions