Per-player vehicle spawning giving me FITS!!111
#1

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!

Код:
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;
}
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:
Код:
if(playercar[playerid]) KillPlayerVehicle(playerid);
^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.
Код:
OnVehicleDamageStatusUpdate
OnUnoccupiedVehicleUpdate
OnVehicleSpawn
OnVehicleStreamIn
OnVehicleStreamOut
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.
Reply
#2

Long time no see kaisersouse.

Anyway, I've had an issue before in my old server where people would share the same vehicle, it would be a somewhat rare event and I eventually figured out it was caused by a set of chain events. I'm guessing you've got a similar problem here.

Quote:

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.

This part is especially interesting, can you show me the /car command in its entirety? I'd like to figure out where the unknown command part is coming from, it may point to a possible reason as to why this is happening.

I would also like to point out a small potential issue with your code. Your variable which is used to tell if the player has a vehicle also contains the vehicle ID, right? That's fine, but the value you recognize as the player not having a vehicle is 0, but 0 is also a valid vehicle ID. So what if it so happens that the player actually gets a vehicle ID of 0? You said other vehicles in your script are all created using CreateVehicle, if they are destroyed, a player can potentially get his hands on a vehicle with an ID of 0 and it can never be destroyed because you identify 0 as him not having a vehicle. I would suggest changing the value of not having a vehicle to -1.
Reply
#3

OH NO!!!!!! Thats it right there....0 IS a vehicleid. CRAP. My god...I wonder if this is what made everystuff so chitty-chitty-bang-bang in the first place (when 200 cars was the limit)!?!

My car command: the only reason I didnt post it is due to it being menu based, and I wanted to root out potential issues w/ the main portion of the entire system before getting into a fight w/ menus again. I think this plan has worked to my advantage...as within the first reply I'm fairly certain you've solved my problems. The CreatePlayerVehicle is passed once the player selects a car from the menu (sending the modelid) and returning playercar[playerid] at the end. Since this can be 0....the command crashes.

I'm going to do the -1 thing, and since I expect it to fix a lot of whats wrong w/ my vehicle stuff..thank you! I didn't want to make a spectacle of coming back, I didn't really know I was until a few days ago.

How are things? I miss you guys (-1 hahaha)
Reply
#4

Quote:
Originally Posted by kaisersouse
Посмотреть сообщение
OH NO!!!!!! Thats it right there....0 IS a vehicleid. CRAP. My god...I wonder if this is what made everystuff so chitty-chitty-bang-bang in the first place (when 200 cars was the limit)!?!

My car command: the only reason I didnt post it is due to it being menu based, and I wanted to root out potential issues w/ the main portion of the entire system before getting into a fight w/ menus again. I think this plan has worked to my advantage...as within the first reply I'm fairly certain you've solved my problems. The CreatePlayerVehicle is passed once the player selects a car from the menu (sending the modelid) and returning playercar[playerid] at the end. Since this can be 0....the command crashes.

I'm going to do the -1 thing, and since I expect it to fix a lot of whats wrong w/ my vehicle stuff..thank you! I didn't want to make a spectacle of coming back, I didn't really know I was until a few days ago.

How are things? I miss you guys (-1 hahaha)
Glad I could help, I also did suspect that the unknown command was actually coming from that, I thought there was a chance you were returning that variable in your command text callback

But yeah things are good, we've missed you too!
Reply
#5

turns out i was also passing vehicleids to a callback that was looking for playerid haha

I know why too...mass-replace when converting script. NOOB ERROR haha
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)