1 Scripting thing where i need help for.
#1

I have my own server, and i know a little how to script. But i need one little thing:

When a player has already a car and he'll spawn a new vehicle, His old Vehicle will get removed.
Can anyone give me a script of this or help me with it?
Reply
#2

1. Global array new p_cars[MAX_PLAYERS]
2. On command to spawn car check if p_cars[playerid] is empty. If it is not, delete previous car. Assign created car id to p_cars[playerid]
Reply
#3

Hmm, i'm not understanding this sorry, I'm not a good scripter.
Reply
#4

So you want it so if a player spawns a car (we'll call this car A) and then they spawn a new car (call this one B), you want car A to despawn?, then if they were to spawn car C, car B will despawn? etc etc?
Reply
#5

@ Cosbraa, yes.


Imma going to eat now back in 1 hour kinda that.
Reply
#6

Does it matter if the person is in the car or not?
Reply
#7

Well, as Misiur said, make a global variable. Call it whatever you want
Car[MAX_PLAYERS];
Then when a player spawns, set the vehicleid of the car you spawn to Car[playerid].
So, when the command to spawn the car is called, it needs to run the check of seeing if they Car[playerid] > 0, and if it is, then DestroyVehicle(Car[playerid]);
But then have it spawn the car and set the new vehicle id to Car[playerid, like Car[playerid] = vehicleid.

Probably missed a few things and this probably wont help you much, i'm tired and im going.
Reply
#8

Create variable:
pawn Code:
new pCars[MAX_PLAYERS];
Put this under the car spawning command:
pawn Code:
if (pCars[playerid] > 0) DestroyVehicle(pCars[playerid]);
PutPlayerInVehicle(playerid, CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay), 0);
pCars[playerid] = GetPlayerVehicleID(playerid);
You have to put in the parameters for CreateVehicle function.
Haven't tested, but it should work.
Reply
#9

@ DaRealShazz

U mean under this:
new Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid,X,Y,Z);
if(dialogid == 2)
Reply
#10

Quote:
Originally Posted by DaRealShazz
View Post
Create variable:
pawn Code:
new pCars[MAX_PLAYERS];
Put this under the car spawning command:
pawn Code:
if (pCars[playerid] > 0) DestroyVehicle(pCars[playerid]);
PutPlayerInVehicle(playerid, CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay), 0);
pCars[playerid] = GetPlayerVehicleID(playerid);
You have to put in the parameters for CreateVehicle function.
Haven't tested, but it should work.
To make this work you'd have to set pCars[playerid] = 0; under OnPlayerConnect.
Reply
#11

Better yet:

pawn Code:
new pCars[MAX_PLAYERS] = {0, ...};
Reply
#12

Quote:
Originally Posted by Misiur
View Post
Better yet:

pawn Code:
new pCars[MAX_PLAYERS] = {0, ...};
Yes, and you spam your code with utter nonsense, imagine if he has max_players of 500, he's going to create 500 lines saying {0}?! Instead of one simple line under OnPlayerConnect?
Reply
#13

I got this error when im doing Compile:

C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(4187) : warning 204: symbol is assigned a value that is never used: "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 017: undefined symbol "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : warning 215: expression has no effect
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 001: expected token: ";", but found "]"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 029: invalid expression, assumed zero
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#14

Actually, neither of these are required, because default value is equal 0 ( https://sampwiki.blast.hk/wiki/Scripting_Basics#Accessing )

@OP:

Looks like you didn't register the variable as global (outside any local scope). Did you place its initialization in some callback?
Reply
#15

Quote:
Originally Posted by UnlimitedFreeroam
View Post
I got this error when im doing Compile:

C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(4187) : warning 204: symbol is assigned a value that is never used: "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 017: undefined symbol "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : warning 215: expression has no effect
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 001: expected token: ";", but found "]"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : error 029: invalid expression, assumed zero
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11956) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Show me those lines, my guess is that you did not place pCars into a "global scope area".
Show me 5 lines before EACH error.
Reply
#16

Quote:
Originally Posted by Misiur
View Post
Actually, neither of these are required, because default value is equal 0 ( https://sampwiki.blast.hk/wiki/Scripting_Basics#Accessing )

@OP:

Looks like you didn't register the variable as global (outside any local scope). Did you place its initialization in some callback?
You need to initialize any array to it's full extent, try using your own suggestion and you'll know.
Reply
#17

I don't understand anything about that Global bla bla Area.

Quote:

SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "If you want to repair your car, press 'CapsLock");
// (the previous player may of changed it)
TextDrawShowForPlayer(playerid, WelcomeText);
for( new slots = GetMaxPlayers( ), i; i < slots; i ++ )
{
if( IsPlayerConnected( i ) && !IsPlayerNPC( i ) )
{
SpeedBoostMultiplier[ i ] = 3.0;
}
new pCars[MAX_PLAYERS];

First error on line 4187, I don't know or i placed everything on the right place etc.





return SendClientMessage(playerid, 0xFF0000FF, "Now Drive your car into the Neon Garage");
}
}
}
}
// credits to Yuri for his carmenu
new Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid,X,Y,Z);
if(dialogid == 2)
{
if (pCars[playerid] > 0) DestroyVehicle(pCars[playerid]);
PutPlayerInVehicle(playerid, CreateVehicle(modelid, Float, Float:y, Float:z, Float:angle, color1, color2, respawn_delay), 0);
pCars[playerid] = GetPlayerVehicleID(playerid);
if(response)


Second error at line 11956


I don't know anything about this things, maybe u can help me on Teamviewer.
Reply
#18

Place pCars[MAX_PLAYERS]; somewhere where it is outside of all scopes ( not between any { } ).
Reply
#19

Quote:

C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(4189) : warning 204: symbol is assigned a value that is never used: "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11957) : error 017: undefined symbol "pCars"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11957) : warning 215: expression has no effect
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11957) : error 001: expected token: ";", but found "]"
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11957) : error 029: invalid expression, assumed zero
C:\Users\eigenaar\Contacts\Pictures\Desktop\BETA Server\gamemodes\TorettoRacing1.pwn(11957) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


4 Errors.

Still this errros,

Maybe u can help me with Teamviewer if u have it?
Reply
#20

Quote:
Originally Posted by UnlimitedFreeroam
View Post
Still this errros,

Maybe u can help me with Teamviewer if u have it?
Check your PM.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)