Need help with vehicle system
#1

Hello guys, need some help here. I was away from scripting sa-mp, but my friends and I decided to create a new server, so I have several problems...

This code here, must be allowed to use only near your vehicle, the vehicle you own, the problem is that its usable near any vehicle, any server vehicle..

Код:
 
if(!strcmp(params,"lock",true))
	{
     	new Float:X,Float:Y,Float:Z, msg[60];
		for(new i=0; i<MAX_VEHICLES; i++) {
		    if(!strcmp(carDB[i][cOwner],playerDB[playerid][name],true)) {
		        GetVehiclePos(i,X,Y,Z);
		        if(IsPlayerInRangeOfPoint(playerid,5,X,Y,Z)) {
					if(carDB[i][cLocked] == 1) {
					    carDB[i][cLocked] = 0;
					    format(msg,sizeof(msg)," * %s unlocks their vehicle. *",playerDB[playerid][name]);
					    for(new p=0; p<MAX_PLAYERS; p++) {
							if(IsPlayerConnected(p)) {
							    SetVehicleParamsForPlayer(i,p,0,0);
							}
					    
					    }
					} else if(carDB[i][cLocked] == 0) {
					    carDB[i][cLocked] = 1;
					    format(msg,sizeof(msg)," * %s locks their vehicle. *",playerDB[playerid][name]);
					    for(new p=0; p<MAX_PLAYERS; p++) {
							if(IsPlayerConnected(p)) {
							    SetVehicleParamsForPlayer(i,p,0,1);
							}
					    }
					}
					GetPlayerPos(playerid,X,Y,Z);
					for(new a=0; a<MAX_PLAYERS; a++) {
						if(IsPlayerConnected(a) && IsPlayerInRangeOfPoint(a,30,X,Y,Z)) {
						    SendClientMessage(a,CLR_ACTION,msg);
						}
					}
					return 1;
				}
		    }
		}
		return 1;
	}
And the same happens with other commands i did like, /park .. It parks a not owned vehicle. I think the problem is with the function:
Код:
if(!strcmp(carDB[i][cOwner],playerDB[playerid][name],true))
Anyways, I wanted to ask one more thing:
If you, buy a vehicle from menu, but not by entering the vehicle, how to create that vehicle and make a player its owner? How to get that vehicleid to use in enums? This is what I did:

Код:
 
CreateVehicle(i) {
carDB[i][ownedvehicle] = CreateVehicle(blah, blah, blah); 
}
and its called on GameModeInit by this code:
Код:
for(new i=0; i<MAX_VEHICLES; i++) { CreateVehicle(i); }
P.S. I save all information in .ini files, using Dini and i get the information that way too.

Thanks for help, looking forward.
Reply
#2

Before using strcmp, you HAVE to make sure that the vehicle HAS an owner.

Use "if(!carDB[i][Owner][0])" , if this passes that means that the vehicle has no owner.
Reply
#3

Quote:
Originally Posted by SilentHuntR
Посмотреть сообщение
Before using strcmp, you HAVE to make sure that the vehicle HAS an owner.

Use "if(!carDB[i][Owner][0])" , if this passes that means that the vehicle has no owner.
Dang! Never thought that before. Thanks, I'll try that.
Reply
#4

Fuck, it doesnt work. I thought it works, becouse i tried it standing near not owned vehicle, but then i tried standing near owned. And it doesnt work... Hmm... Maybe you could answer my question i wrote?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)