Regonize Organization vehicle -
jasperschellekens - 25.11.2017
Hello.
Im stuck on something.
I have some kind of script for organization vehicle's. Now i want to set a restriction for certain commands. so that they can only be used in organization vehicles.
What i tried:
If(vehicleid != Organization[orgid][VehiclesCreated]) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
Код:
CMD:m1(playerid,params[])
{
if(IsJailedOrMuted(playerid))return 1;
if(PlayerOrgType(playerid)==LAW) {
new vehicleid=GetPlayerVehicleID(playerid),str[128];
If(vehicleid != Organization[orgid][VehiclesCreated]) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
}
SendNearbyMessage(playerid,150.0,str,BLUE);
}else return SendClientMessage(playerid,GREY,"You are not a police officer");
return 1;
}
What am i doing wrong? How to make it work.
This is how a organization vehicle is created:
Код:
CreateOrgVehicle("San Andreas Police Dept",596,1600.3672,-1704.1592,5.6134,89.9169,53,1);
stock CreateOrgVehicle(org[40],model,Float:x,Float:y,Float:z,Float:rot,clr1,clr2)
{
if (!DoesOrgExist(org)) return printf("You are attempting to create org. vehicles for an org. which does not exist");
new orgid=GetOrgID(org);
new freeslot=Organization[orgid][VehiclesCreated];
if (freeslot >=MAX_ORG_VEHICLES) return printf("ERROR: %s cannot handle more vehicles! Aborted",org);
Organization[orgid][Vehicles][freeslot]=CreateVehicle(model,x,y,z,rot,clr1,clr2,900);
Organization[orgid][VehiclesCreated]++;
new string[10];
format(string,10,"Org (%d)",orgid);
SetVehicleNumberPlate(Organization[orgid][Vehicles][freeslot],string);
return 1;
}
Edit:
I now have this. But when i'm in a organization vehicle it says im not driving a organization vehicle.
Код:
//==============================================================================
CMD:m1(playerid,params[])
{
if(IsJailedOrMuted(playerid))return 1;
if(PlayerOrgType(playerid)==LAW) {
new orgid=PlayerOrg[playerid];
new vehicleid=GetPlayerVehicleID(playerid),str[128];
if(vehicleid != Organization[orgid][VehiclesCreated]) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
}
SendNearbyMessage(playerid,150.0,str,BLUE);
}else return SendClientMessage(playerid,GREY,"You are not a police officer");
return 1;
}
Re: Regonize Organization vehicle -
MEW273 - 25.11.2017
The problem is here:
if(vehicleid != Organization[orgid][VehiclesCreated]) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
The variable
Organization[orgid][VehiclesCreated] is counting the number of vehicle created, not the ID of the vehicle created. You need to compare vehicleid against the ID of the vehicles you have created.
See in your vehicle creation function:
Organization[orgid][Vehicles][freeslot]=CreateVehicle(model,x,y,z,rot,clr1,clr2,900);
Organization[orgid][VehiclesCreated]++;
new string[10];
Re: Regonize Organization vehicle -
jasperschellekens - 25.11.2017
Thank you.
I now have if(vehicleid == Organization[orgid][Vehicles])
But it still does not work.
Re: Regonize Organization vehicle -
MEW273 - 25.11.2017
Could you try the following code:
[i]
CMD:m1(playerid,params[])
{
if(IsJailedOrMuted(playerid))return 1;
if(PlayerOrgType(playerid)==LAW) {
new orgid=PlayerOrg[playerid];
new vehicleid=GetPlayerVehicleID(playerid),str[128];
if(!isVehicleOwnerOrg(orgid, vehicleid)) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
}
SendNearbyMessage(playerid,150.0,str,BLUE);
}else return SendClientMessage(playerid,GREY,"You are not a police officer");
return 1;
}
isVehicleOwnerOrg(orgid, vehicleid)
{
for(new i = 0, j = MAX_VEHICLES; i <= j; i++)
{
if(vehicleid == Organization[orgid][Vehicles]
) return 1;
}
return 0;
}
This should loop through all vehicles and check if the vehicleid being driven is an org vehicle.
Re: Regonize Organization vehicle -
jasperschellekens - 25.11.2017
Thank you very much,
I did try but it still says i'm not driving an organization vehicle.
Re: Regonize Organization vehicle -
MEW273 - 25.11.2017
I think I made an error, try the below:
Код:
CMD:m1(playerid,params[])
{
if(IsJailedOrMuted(playerid))return 1;
if(PlayerOrgType(playerid)==LAW) {
new orgid=PlayerOrg[playerid];
new vehicleid=GetPlayerVehicleID(playerid),str[128];
if(isVehicleOwnerOrg(orgid, vehicleid)) return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
}
SendNearbyMessage(playerid,150.0,str,BLUE);
}else return SendClientMessage(playerid,GREY,"You are not a police officer");
return 1;
}
isVehicleOwnerOrg(orgid, vehicleid)
{
for(new i = 0, j = MAX_VEHICLES; i <= j; i++)
{
if(vehicleid == Organization[orgid][Vehicles][i]) return 1;
}
return 0;
}
Re: Regonize Organization vehicle -
RedFusion - 25.11.2017
Try this
pawn Код:
CMD:m1(playerid,params[]) {
if( IsJailedOrMuted(playerid) ) {
return 1;
}
if( PlayerOrgType(playerid) != LAW ) {
return SendClientMessage(playerid,GREY,"You are not a police officer"), 1;
}
new
orgid=PlayerOrg[playerid],
vehicleid=GetPlayerVehicleID(playerid)
;
if( !isVehicleOwnerOrg(orgid, vehicleid) ) {
return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!"), 1;
}
new str[144+1];
format(str, sizeof str,"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
SendNearbyMessage(playerid,150.0,str,BLUE);
return 1;
}
isVehicleOwnerOrg(orgid, vehicleid) {
for(new i; i < MAX_VEHICLES; i++) {
if( vehicleid == Organization[orgid][Vehicles][i] ) {
return 1;
}
}
return 0;
}
Re: Regonize Organization vehicle -
jasperschellekens - 25.11.2017
I dont know why but it still does not work.
Re: Regonize Organization vehicle -
grymtn - 25.11.2017
when vehicle despawns like if vehicle crashes, alsoid theres another despawned player vehicle. It will give the police vehicle that despawned. Give a global variable for those cars and make that global variable start from maybe 100-200 so it doesnt get the old player vehicles ids maybe?
im not sure but maybe because you use ++ for vehicle ids lets say before you create an organisation vehicle someone created a vehicle and its id became 1 also your "Organization[orgid][Vehicles]" start from 0 too and when you give ++ to it, it becomes 1 too.
Re: Regonize Organization vehicle -
jasperschellekens - 26.11.2017
bump
Re: Regonize Organization vehicle -
jasperschellekens - 27.11.2017
bump
Re: Regonize Organization vehicle -
jasperschellekens - 28.11.2017
I managed to get it to work but have another problem now.
If i dont add return 0; it send 100 of messages. it will also execute the blue message several times.
But return 0 shows also unknown command after he send You are not driving once.
How to fix that?
Код:
//==============================================================================
CMD:m1(playerid,params[])
{
if(IsJailedOrMuted(playerid))return 1;
if(PlayerOrgType(playerid)==LAW)
{
new vehicleid=GetPlayerVehicleID(playerid),str[128];
for(new i=1;i<OrgsCount+1;i++)
{
for(new a=0;a<MAX_ORG_VEHICLES;a++)
{
if(vehicleid==Organization[i][Vehicles][a] && PlayerOrg[playerid] !=i)
{
if(DoesOrgExist(GetOrgName(i)))
{
SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
return 0;
}
}
}
}
if(PlayerOrg[playerid] == 3)
{
format(str,sizeof(str),"Megaphone: THIS IS THE POLICE, PULL OVER TO THE SIDE OF THE ROAD!!!");
SendNearbyMessage(playerid,150.0,str,BLUE);
}
if(PlayerOrg[playerid] == 9)
{
format(str,sizeof(str),"Megaphone: THIS IS THE FBI, PULL OVER TO THE SIDE OF THE ROAD!!!");
SendNearbyMessage(playerid,150.0,str,BLUE);
}
}else return SendClientMessage(playerid,GREY,"You are not law enforcement");
return 1;
}
Re: Regonize Organization vehicle -
RedFusion - 28.11.2017
Use break
Re: Regonize Organization vehicle -
jasperschellekens - 28.11.2017
That gives the same result as using no return. It doesnt break it.
Re: Regonize Organization vehicle -
jasperschellekens - 28.11.2017
Thx for the help.
this fixed it:
if(DoesOrgExist(GetOrgName(i)))
{
return SendClientMessage(playerid, COLOR_RED, "You are not driving a organization vehicle!");
}