Despanwing a car
#1

Ok, I use CW:RP script which is SQL based. I've made a car system which allows you to own 3 different vehicles but only to have one spawned at once. So, I've made the command /park, using DestroyVehicle, to despawn a car if you own it and then the commands /getcar1, /getcar2 and /getcar3 to spawn it using CreateVehicle if your car key matches with the vehicle ID. /getcar will only works if you have no vehicle spawned (my cars table has a spawned column working perfectly (0=not spawned, so no AddStaticVehicleEx added on server restart or reloading the cars table, 1=spawned)

The problem is that when I despawn my car and then try to respawn it I get "You already have a car spawned" (which I added myself, but as I just despawned my car it shouldn't happen). So I looked at my script, it was ok, then I looked at my stats and mt car keys hadn't changed, but when I used /gotocar <my car key, so car ID> it teleported me to another car and I saw that I owned it...

In conclusion:
Actually each time I /park, all car IDs are changed, if I owned car 200 it will disappear from the server and the car 201 or 199 will become car number 200, mine. So each time I'll /park my car it will make it disappear and i'll just be the owner of another car. Whereas in my database no car has been deleted.

I think this is due to the DestroyVehicle thing, so do you know a way to despawn a car using another function?

Here is a part of my script: (in my .pwn, it's well indented)

if(strcmp("/park", cmdtext, true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new car = GetPlayerVehicleID(playerid);
GetPlayerName(playerid, playername, sizeof(playername));
if(CarInfo[car][cOwned] == 1 && strcmp(CarInfo[car][cOwner], playername, true) == 0)
{
new Floatark_x, Floatark_y, Floatark_z;
park_x = CarInfo[car][cLocationx];
park_y = CarInfo[car][cLocationy];
park_z = CarInfo[car][cLocationz];
if(PlayerToPoint(3.0, playerid, park_x, park_y, park_z))
{
CarInfo[car][cSpawned] = 0;
DestroyVehicle(car);
DisablePlayerCheckpoint(playerid);
SendClientMessage(playerid, COLOR_WHITE, "Vйhicule despawned. Tapez /getcar pour le respawn");
format(sql, 256, "UPDATE cars SET spawned=0 WHERE id=%d", car);
samp_mysql_query(sql);
SaveSQLCar(car);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Vous n'кtes pas а votre place de parking.");
SetPlayerCheckpoint(playerid, park_x, park_y, park_z, 5.0);
return 1;
}
}

else
{
SendClientMessage(playerid, COLOR_GREY, "Ce vйhicule ne vous appartient pas.");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "Vous n'кtes dans aucun vйhicule.");
}
return 1;
}

//GETCAR

if(strcmp("/getcar", cmdtext, true) == 0)
{
SendClientMessage(playerid, COLOR_GREY, "Utilisez /getcar1, /getcar2 ou /getcar3 pour spawn un de vos vйhicules.");
return 1;
}

if(strcmp("/getcar1", cmdtext, true) == 0)
{
if(IsPlayerConnected(playerid))
{
if (PlayerInfo[playerid][pPcarkey] == 999)
{
SendClientMessage(playerid, COLOR_GREY, "Vous n'avez aucun vйhicule а cet emplacement.");
return 1;
}
new car = PlayerInfo[playerid][pPcarkey];
if(HasACarSpawned(playerid))
{
SendClientMessage(playerid, COLOR_GREY, "Vous avez dйjа un vйhicule spawned.");
return 1;
}
new Floatark_x, Floatark_y, Floatark_z, Floatark_a;
park_x = CarInfo[car][cLocationx];
park_y = CarInfo[car][cLocationy];
park_z = CarInfo[car][cLocationz];
park_a = CarInfo[car][cAngle];
CreateVehicle(CarInfo[car][cModel],park_x,park_y,park_z,park_a, CarInfo[car][cColorOne],CarInfo[car][cColorTwo], 99999999);
SendClientMessage(playerid, COLOR_YELLOW, "Vйhicule spawned.");
SetPlayerCheckpoint(playerid, park_x, park_y, park_z, 5.0);
CarInfo[car][cSpawned] = 1;
format(sql, 256, "UPDATE cars SET spawned=1 WHERE id=%d", car);
samp_mysql_query(sql);
return 1;
}
return 1;
}
Thanks in advance, this problem really annoys me...


Ok, forget what I wrote above. Here is my problem: I use a SQL DataBase for my cars, and I wan't a way to despawn a car from the server, I found it but there's an effect that I don't like... When I do /park it perfectly despawn the car but it also REMOVE it from the database...

So could someone tell me how to despawn a car without using DestroyVehicle please?
Here is my command (simplified, just to show you how it works):
pawn Код:
if (strcmp, "/park", cmdtext, true) == 0)
{
    if(!IsPlayerInAnyVehicle(playerid)) return 1;
    new carid = GetPlayerVehicleID;
    SendClientMessage(playerid, WHITE, "You have despawned your car.");
    DestroyVehicle(carid);
    return 1;
}
In my script, it's more complex (if it's your car, if you're at the right place, etc) but the main point here is that I use DestroyVehicle.

Help me please I really need this command to work...
Reply
#2

Aks in the CWRP thread
Reply
#3

Quote:
Originally Posted by JeNkStAX
Aks in the CWRP thread
It isn't related to CW:RP, I could have done it on any other GM
Reply
#4

1st post updated, re-read and help me please
Reply
#5

Dudes, I really need this working, could someone give me an answer please?
Reply
#6

You really need to spam that much?

.
You want the vehicle to be in the server but not appearing? I would do SetVehiclePos somewhere else.
Reply
#7

Quote:
Originally Posted by [K4L
Leoprune ]
You really need to spam that much?

.
You want the vehicle to be in the server but not appearing? I would do SetVehiclePos somewhere else.
Nah, it wouldn't reduce lag... Or would it if i'd set its pos in the skies?
Reply
#8

Ya sure, i don't think players can see that far :P.
Reply
#9

why not just use the database to save their positions, instead of the actual vehicle, so you can do destroy vehicle without loss of it's position then respawn whenever
Reply
#10

I got it work, but I need a hint please.

What's the command (to put in the script) to delete a record from the SQL DB?

Thanks in advance
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)