SA-MP Forums Archive
/v removes last spawned vehicle - 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)
+--- Thread: /v removes last spawned vehicle (/showthread.php?tid=385361)



/v removes last spawned vehicle - nickbouwhuis - 15.10.2012

Hey guys!

I have a car spawner in my server, and I want to make it so that, wheneven a player spawns a new vehicle, the other one gets distroyed (de-spawned). Here's my current script: http://pastebin.com/cgjLsxMd

Any help would be greatly apriciated!

-Nick


Re: /v removes last spawned vehicle - Randy More - 15.10.2012

Instead of defining "car" variable for each menu item, define it globally that way:

pawn Код:
new car[MAX_PLAYERS];
then each time a vehicle is being spawned the current gets destroyed like that..

pawn Код:
DestroyVehicle(car[playerid]);
So it be finally like that..

pawn Код:
// Anywhere after the includes..
new car[MAX_PLAYERS];

// An example of responding to a menu-item..
case 0: //go kart
{
            new Float:x, Float:y, Float:z, Float:a;
            GetPlayerFacingAngle(playerid,a);
            GetPlayerPos(playerid, x, y, z);
            if(car[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(car[playerid]);
            car[playerid] = CreateVehicle(571,x,y,z+4,a,-1,-1,30000);
            PutPlayerInVehicle(playerid,car,0);
            SendClientMessage(playerid, 0xFFFFFFFF, "Je selecteerde een Go Kart");
 
}



Re: /v removes last spawned vehicle - nickbouwhuis - 15.10.2012

Quote:
Originally Posted by Randy More
Посмотреть сообщение
Instead of defining "car" variable for each menu item, define it globally that way:

pawn Код:
new car[MAX_PLAYERS];
then each time a vehicle is being spawned the current gets destroyed like that..

pawn Код:
DestroyVehicle(car[playerid]);
So it be finally like that..

pawn Код:
// Anywhere after the includes..
new car[MAX_PLAYERS];

// An example of responding to a menu-item..
case 0: //go kart
{
            new Float:x, Float:y, Float:z, Float:a;
            GetPlayerFacingAngle(playerid,a);
            GetPlayerPos(playerid, x, y, z);
            if(car[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(car[playerid]);
            car[playerid] = CreateVehicle(571,x,y,z+4,a,-1,-1,30000);
            PutPlayerInVehicle(playerid,car,0);
            SendClientMessage(playerid, 0xFFFFFFFF, "Je selecteerde een Go Kart");
 
}
Thanks! Going to edit my script!


Re: /v removes last spawned vehicle - nickbouwhuis - 16.10.2012

Quote:
Originally Posted by Randy More
Посмотреть сообщение
Instead of defining "car" variable for each menu item, define it globally that way:

pawn Код:
new car[MAX_PLAYERS];
then each time a vehicle is being spawned the current gets destroyed like that..

pawn Код:
DestroyVehicle(car[playerid]);
So it be finally like that..

pawn Код:
// Anywhere after the includes..
new car[MAX_PLAYERS];

// An example of responding to a menu-item..
case 0: //go kart
{
            new Float:x, Float:y, Float:z, Float:a;
            GetPlayerFacingAngle(playerid,a);
            GetPlayerPos(playerid, x, y, z);
            if(car[playerid] != INVALID_VEHICLE_ID) DestroyVehicle(car[playerid]);
            car[playerid] = CreateVehicle(571,x,y,z+4,a,-1,-1,30000);
            PutPlayerInVehicle(playerid,car,0);
            SendClientMessage(playerid, 0xFFFFFFFF, "Je selecteerde een Go Kart");
 
}
Ok, so I edited my script (What it is now > http://pastebin.com/Rxd2qW6c)
And I get these errors:
Код:
autos.pwn(237) : error 033: array must be indexed (variable "car")
autos.pwn(238) : error 035: argument type mismatch (argument 2)
autos.pwn(249) : error 033: array must be indexed (variable "car")
autos.pwn(250) : error 035: argument type mismatch (argument 2)
autos.pwn(260) : error 033: array must be indexed (variable "car")
autos.pwn(261) : error 035: argument type mismatch (argument 2)
autos.pwn(271) : error 033: array must be indexed (variable "car")
autos.pwn(272) : error 035: argument type mismatch (argument 2)
autos.pwn(282) : error 033: array must be indexed (variable "car")
autos.pwn(283) : error 035: argument type mismatch (argument 2)
autos.pwn(293) : error 033: array must be indexed (variable "car")
autos.pwn(294) : error 035: argument type mismatch (argument 2)
autos.pwn(310) : error 033: array must be indexed (variable "car")
autos.pwn(311) : error 035: argument type mismatch (argument 2)
autos.pwn(321) : error 033: array must be indexed (variable "car")
autos.pwn(322) : error 035: argument type mismatch (argument 2)
autos.pwn(335) : error 033: array must be indexed (variable "car")
autos.pwn(336) : error 035: argument type mismatch (argument 2)
autos.pwn(349) : error 033: array must be indexed (variable "car")
autos.pwn(350) : error 035: argument type mismatch (argument 2)
autos.pwn(380) : error 033: array must be indexed (variable "car")
autos.pwn(381) : error 035: argument type mismatch (argument 2)
autos.pwn(391) : error 033: array must be indexed (variable "car")
autos.pwn(392) : error 035: argument type mismatch (argument 2)
autos.pwn(403) : error 033: array must be indexed (variable "car")
autos.pwn(404) : error 035: argument type mismatch (argument 2)
What's wrong?


Re: /v removes last spawned vehicle - nickbouwhuis - 17.10.2012

Bump


Re : /v removes last spawned vehicle - Ataraxia - 17.10.2012

Replace all "car=CreateVehicle(...)" to "car[playerid] = CreateVehicle(...)"


Re: Re : /v removes last spawned vehicle - nickbouwhuis - 17.10.2012

Quote:
Originally Posted by Ataraxia
Посмотреть сообщение
Replace all "car=CreateVehicle(...)" to "car[playerid] = CreateVehicle(...)"
Did that, still getting the same errors
(Edited pwn link: http://pastebin.com/4YXy3aAN)

Код:
autos.pwn(238) : error 035: argument type mismatch (argument 2)
autos.pwn(250) : error 035: argument type mismatch (argument 2)
autos.pwn(261) : error 035: argument type mismatch (argument 2)
autos.pwn(272) : error 035: argument type mismatch (argument 2)
autos.pwn(283) : error 035: argument type mismatch (argument 2)
autos.pwn(294) : error 035: argument type mismatch (argument 2)
autos.pwn(311) : error 035: argument type mismatch (argument 2)
autos.pwn(322) : error 035: argument type mismatch (argument 2)
autos.pwn(336) : error 035: argument type mismatch (argument 2)
autos.pwn(350) : error 035: argument type mismatch (argument 2)
autos.pwn(381) : error 035: argument type mismatch (argument 2)
autos.pwn(392) : error 035: argument type mismatch (argument 2)
autos.pwn(404) : error 035: argument type mismatch (argument 2)
autos.pwn(415) : error 035: argument type mismatch (argument 2)
autos.pwn(426) : error 035: argument type mismatch (argument 2)
autos.pwn(437) : error 035: argument type mismatch (argument 2)
autos.pwn(449) : error 035: argument type mismatch (argument 2)
autos.pwn(464) : error 035: argument type mismatch (argument 2)
autos.pwn(488) : error 035: argument type mismatch (argument 2)
autos.pwn(499) : error 035: argument type mismatch (argument 2)
autos.pwn(510) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase



Re : /v removes last spawned vehicle - Ataraxia - 17.10.2012

PHP код:
PutPlayerInVehicle(playerid,car,0);
// To
PutPlayerInVehicle(playeridcar[playerid], 0); 



Re: Re : /v removes last spawned vehicle - nickbouwhuis - 17.10.2012

Quote:
Originally Posted by Ataraxia
Посмотреть сообщение
PHP код:
PutPlayerInVehicle(playerid,car,0);
// To
PutPlayerInVehicle(playeridcar[playerid], 0); 
Thanks! That fixed it! Rep'd