08.05.2012, 00:57
This worked perfect w/ .3a before I gave Everystuff away. I'm resurrecting a SMALL version of the original server...and all of a sudden vehicle-spawning for players is broken broken broken.
I'm using two functions...CreatePlayerVehicle and KillPlayerVehicle ('ill post them below). Players are allowed one car per-person at a time. I'm using playercar[playerid] to store the vehicle ID returned when I use CreateVehicle for the player. When a player disconnects, or spawns another car, KillPlayerVehicle is run and after destroying the car it sets playercar[playerid] = 0. I'm posting the functions/routines below...in the meantime can someone clue me in to whats changed w/ vehicles that could be causing issues?
Basically its not destroying the vehicles correctly, so people either leave a ghost car behind when they spawn a new one...or (occasisonaly) the entire /car command crashes and returns an UNKOWN COMMAND error.
ALL static vehicles are created in a separate filterscript, using CreateVehicle as well. I'm wondering if that should change to AddStaticVehicle.
Anyways, heres the code...by all means ask for more info if you need it. Thanks in advance!
PutPlayerInPlayerCar was used to work-around a timing issue in .3a. It may not be needed any longer.
Any time KillPlayerVehicle is called, its called in this fashion:
^This is called when a player creates a vehicle, or in OnPlayerDisconnect. The ONLY time playercar[playerid] is set to 0 is in KillPlayerVehicle.
Looking at it further, I should probably use vehicleid instead of playerid in KillPlayerVehicle. I'm not sure thats the issue...but I'm not sure of much given the changes I'm seeing (haven't touched pawn in 4-ish years).
These callbacks are either new to me, or I've never really used them (OnVehicleSpawn). Maybe I could be using these to my advantage.
After posting all that, I'm now going to look in the filterscripts section to see how other people are doing this (I assume other people are doing this).
I absolutely do NOT want ANY cars created by players to remain when they leave. I also do NOT want a player to have more than one personal (player-spawned) car at the same time.
I'm using two functions...CreatePlayerVehicle and KillPlayerVehicle ('ill post them below). Players are allowed one car per-person at a time. I'm using playercar[playerid] to store the vehicle ID returned when I use CreateVehicle for the player. When a player disconnects, or spawns another car, KillPlayerVehicle is run and after destroying the car it sets playercar[playerid] = 0. I'm posting the functions/routines below...in the meantime can someone clue me in to whats changed w/ vehicles that could be causing issues?
Basically its not destroying the vehicles correctly, so people either leave a ghost car behind when they spawn a new one...or (occasisonaly) the entire /car command crashes and returns an UNKOWN COMMAND error.
ALL static vehicles are created in a separate filterscript, using CreateVehicle as well. I'm wondering if that should change to AddStaticVehicle.
Anyways, heres the code...by all means ask for more info if you need it. Thanks in advance!
Код:
forward CreatePlayerVehicle(playerid, modelid); public CreatePlayerVehicle(playerid, modelid) { RemovePlayerFromVehicle(playerid); if(playercar[playerid]) KillPlayerVehicle(playercar[playerid]); new Float:a; GetPlayerFacingAngle(playerid, a); GetPlayerPos(playerid, playerx, playery, playerz); if(modelid < MIN_VEHI_ID || modelid > MAX_VEHI_ID) return SendClientMessage(playerid, COLOR_ERROR, "Error: Invalid Vehicle MODELID/NAME. Modelid range 400 - 611"); else if(modelid == 569 || modelid == 570) return SendClientMessage(playerid, COLOR_ERROR, "Error: Models 569 and 570 are buggy and cannot be spawned by players at this time"); new bad,boat,trailer,train,plane; switch(modelid) { case vHUNTER, vHYDRA, vRHINO, vSEASPARROW, vRCPLANE, vGOBLIN: bad = 1; // gun vehicles case 430,446,452,453,454,472,473,484,493,595: boat = 1; //boat case 435,450,584,591,606,607,608,610,611: trailer = 1; //trailer case 449,537,538,569,570,590: train = 1; //train case 417,465,469,487,488,497,548,563,460,476,511,512,513,519,539,553,577,592,593: plane = 1; //planre } if(RaceParticipant[playerid] && (bad || boat || trailer || train || plane)) return SendClientMessage(playerid,COLOR_ERROR,"Error: You cannot spawn this vehicle during a race. Type /leave to leave the race."); playercar[playerid] = CreateVehicle(modelid,playerx,playery,playerz+2,a,-1,-1,480); LinkVehicleToInterior(playercar[playerid], GetPlayerInterior(playerid)); SetVehicleVirtualWorld(playercar[playerid], GetPlayerVirtualWorld(playerid)); PutPlayerInPlayerCar(playerid); return playercar[playerid]; } forward KillPlayerVehicle(playerid); public KillPlayerVehicle(playerid) { if(playercar[playerid]) { DestroyVehicle(playercar[playerid]); playercar[playerid] = 0; } return 1; } stock PutPlayerInPlayerCar(playerid) { if(playercar[playerid]) { PutPlayerInVehicle(playerid,playercar[playerid],0); pvehicleid[playerid] = GetPlayerVehicleID(playerid); pmodelid[playerid] = GetVehicleModel(playercar[playerid]); TogglePlayerControllable(playerid,true); } return 1; }
Any time KillPlayerVehicle is called, its called in this fashion:
Код:
if(playercar[playerid]) KillPlayerVehicle(playerid);
Looking at it further, I should probably use vehicleid instead of playerid in KillPlayerVehicle. I'm not sure thats the issue...but I'm not sure of much given the changes I'm seeing (haven't touched pawn in 4-ish years).
These callbacks are either new to me, or I've never really used them (OnVehicleSpawn). Maybe I could be using these to my advantage.
Код:
OnVehicleDamageStatusUpdate OnUnoccupiedVehicleUpdate OnVehicleSpawn OnVehicleStreamIn OnVehicleStreamOut
I absolutely do NOT want ANY cars created by players to remain when they leave. I also do NOT want a player to have more than one personal (player-spawned) car at the same time.