Removing the vehicles a player spawned when they die.
#1

Hi,

I have a command for players (/veh) where they can choose a car from a menu and then it'll automatically spawn for them. But when 5 people are spawning cars without the cars disappearing the server will become a huge mess.

After the players have selected a car, this happens.

Код:
{
	new Float:pos[3], Float:angle, veh;
	GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
	if(IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), angle), DestroyVehicle(GetPlayerVehicleID(playerid));
	else GetPlayerFacingAngle(playerid, angle);
	veh = CreateVehicle(vehicleid, pos[0], pos[1], pos[2], angle, -1, -1, 99999);

	SetVehicleNumberPlate(veh, "{00CCFF}EXFR 2013x");
 	SetVehicleToRespawn(veh);

	PutPlayerInVehicle(playerid, veh, 0);
	return 1;
}
Could anyone help me make it so that when the player dies, all the cars they have spawned get destroyed?
Reply
#2

Should I just remove 'SetVehicleToRespawn' ?
Reply
#3

Yes, remove it and it should work buddy!
Reply
#4

No it won't! If you want to remove all vehicles a player has spawned you should make a global per-player variable and track vehicle IDs spawned, also impose a limit of maximum vehicles a player can create and you would need another (global!) per-player variable to keep track of how many vehicles player spawned.
Reply
#5

Quote:
Originally Posted by Stanford
Посмотреть сообщение
Yes, remove it and it should work buddy!
Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
No it won't! If you want to remove all vehicles a player has spawned you should make a global per-player variable and track vehicle IDs spawned, also impose a limit of maximum vehicles a player can create and you would need another (global!) per-player variable to keep track of how many vehicles player spawned.
Thanks for your answers. I tried to remove the respawn line, but that didn't work (like Virtuality already stated)
Could you make an example of how that'd look, Virtual1ty?
Reply
#6

I'm on a tablet ATM but I'll try.
EDIT: finally.
pawn Код:
#define MAX_PVEH (10) // max vehicles a player can spawn
new
    gPlayerVeh[MAX_PLAYERS][MAX_PVEH],
    gVehsSpawned[MAX_PLAYERS]
;

// in create cmd:
new idx = gVehsSpawned[playerid];
if (idx >= MAX_PVEH) return SCM(playerid, -1, "Can't create any more vehicles - max reached! (10)");
// but beware: if you do not plan on deleting every vehicle this 'idx' stuff won't work
// as planned - you would have to write a 'GetFreeSlot" function..
gPlayerVeh[playerid][idx] = CreateVehicle(...);
gVehsSpawned[playerid]++;

// under OnPlayerDeath:
for (new i; i < MAX_PVEH; i++)
{
    if (IsValidVehicle(gPlayerVeh[playerid][i]))
    {
        DestroyVehicle(gPlayerVeh[playerid][i]);
        gPlayerVeh[playerid][i] = INVALID_VEHICLE_ID;
        gVehsSpawned[playerid]--;
    }
}
I apologise for any indentation mistakes!
Reply
#7

Thanks! I gave you some rep for the effort.
Reply
#8

No problem
Reply
#9

I got these errors, but I couldn't figure out how to fix them. (I'm new to scripting and the whole thing you made is out of my league )
I placed the define in my list of defines, the 'new' under that, and I placed the other two things where you said I should add them.
Код:
D:\Desktop\testserver\filterscripts\vehicle.pwn(47) : error 017: undefined symbol "MAX_PVEH"
D:\Desktop\testserver\filterscripts\vehicle.pwn(47) : error 009: invalid array size (negative, zero or out of bounds)
D:\Desktop\testserver\filterscripts\vehicle.pwn(137) : error 017: undefined symbol "MAX_PVEH"
D:\Desktop\testserver\filterscripts\vehicle.pwn(139) : error 017: undefined symbol "IsValidVehicle"
D:\Desktop\testserver\filterscripts\vehicle.pwn(141) : error 035: argument type mismatch (argument 1)
D:\Desktop\testserver\filterscripts\vehicle.pwn(142) : error 046: unknown array size (variable "gPlayerVeh")
D:\Desktop\testserver\filterscripts\vehicle.pwn(142) : warning 215: expression has no effect
D:\Desktop\testserver\filterscripts\vehicle.pwn(1236) : error 017: undefined symbol "MAX_PVEH"
D:\Desktop\testserver\filterscripts\vehicle.pwn(1239) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


8 Errors.
Reply
#10

Check the macro is present and that there is at least a space after it's "name", I missed it by accident.
Also, at the top, under the #define, put this
pawn Код:
native IsValidVehicle(vehicleid);
Then, it's ready to go.
P.S. Also don't just copy code straight away, edit a bit, SCM is SendClientMessage, but it would take me long to write that on a mobile so I shortened it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)