[SOLVED] How do I make a vehicle ONLY available to Admins?
#1

Hello,

I have been working on a gamemode for my server, but there is one vehicle I would like to make available to Admins only. How could I do this? This is the vehicles coordinates, and comment...

Код:
AddStaticVehicle(609,1550.1262,-1446.2003,13.5259,270.4026,0,0); // CIA Unmarked Survailence Van (Admin's Only)
All answers appreciated! Thanks in advance, oh and please, if you are going to redirect me to someone else's post, make sure it makes sense to noobs. I just started scripting 2 weeks ago.

If your going to be a jerk and tell me to "Search" it, then don't post here, I already have, and I couldn't find anything that I could understand.


*Thanks in advance!*
Reply
#2

pawn Код:
new Car = AddStaticVehicle(...);
for(new i; i<MAX_PLAYERS; i++)
{
  if(IsPlayerConnected(i))
  {
    if(IsPlayerAdmin(i))
    {
      SetVehicleParamsForPlayer(Car, i, 0, 0 );
      continue;
    }
    SetVehicleParamsForPlayer(Car, i, 0, 1 );
  }
}
Reply
#3

Quote:
Originally Posted by [HiC
TheKiller ]
pawn Код:
new Car = AddStaticVehicle(...);
for(new i; i<MAX_PLAYERS; i++)
{
  if(IsPlayerConnected(i))
  {
    if(IsPlayerAdmin(i))
    {
      SetVehicleParamsForPlayer(Car, i, 0, 0 );
      continue;
    }
    SetVehicleParamsForPlayer(Car, i, 0, 1 );
  }
}
Wow. Thanks! Now all I have to do is out in the XYZ and Color coordinates where you had AddStaticVehicle(...) and thats it? Or do I have to put something everywhere you put an I? Thanks!
Reply
#4

your car needs a variable assigned to it, so you can "access" it later in the script...
at top at the definitions, add some lines:
Код:
#define MSGFAIL_COLOR 0xff55aaff //0x indicates a hex value, then write your colors in RRGGBBaa notation, 0xff0000ff is red.
new CIAUnmarkedSurvailenceVan;//to hold the car object
new CIAUnmarkedSurvailenceVanID=609;//boxville
btw: the defined color can be used at all SendClientMessage function w/o need to type a color value each time. it should be defined well. then it looks similar at all calls...
...and in your OnPlayerStateChange function you need to add the simple check for being an admin (or ! means its negative, so it will check like "is player NOT admin?"... including throwing a player out of that car if that condition is true:
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
//begin to cut HERE:
	if(newstate == PLAYER_STATE_DRIVER)
	{
		new VehID=GetVehicleModel(GetPlayerVehicleID(playerid));
		if(VehID==CIAUnmarkedSurvailenceVanID)
		{
			if(!IsPlayerAdmin(playerid))
			{
				new string[64];
				format(string,sizeof(string),"Only Admins can enter that Vehicle (%d)",CIAUnmarkedSurvailenceVanID);
				SendClientMessage(playerid,MSGFAIL_COLOR,string);
				RemovePlayerFromVehicle(playerid);
			}
		}
	}
	//the end should close with the } closing brace, if there is more code, then just make sure the return 1; dont gets called too early (it will abort the routine then)
	return 1;
}
at your OnGameModeInit() function, that car needs to be created:
Код:
public OnGameModeInit()
{
//your codes
	CIAUnmarkedSurvailenceVan=AddStaticVehicle(609,1550.1262,-1446.2003,13.5259,270.4026,0,0); // CIA Unmarked Survailence Van (Admin's Only)
//your codes
.. i hope i didnt forget something. i cutted it out of my (working) version, and just modified the name of your car..
so if you got any problems, dont hesitate to tell me, you will get this small problem fixed very quick!
edit: i hope you want to make ALL boxvilles available to admins only, thats the way the script works: it checks the vehicles model-ID, not the certain car itself. so: other boxvilles are forbidden too.
Reply
#5

@ Babul

Okay. Cool. Thanks, however, when I go to compile it, I get this error message...


C:\CnR SAMP Server\gamemodes\CnR.pwn(319) : warning 203: symbol is never used: "CIAUnmarkedSurvailenceVan"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Warning.


What should I do? I would send you my entire GM, but I don't want to give it out. Let me know if you need it...
Reply
#6

ok, i cutted the "CIAUnmarkedSurvailenceVan" and searched it. its the same name used 5 times, so i think its really a small bug in my script >-<
try to see if you get a "real" error when commenting that line out, so this
Код:
new CIAUnmarkedSurvailenceVan;//to hold the car object
becomes:
Код:
// new CIAUnmarkedSurvailenceVan;//to hold the car object
and is not used anymore, not causing that "never gets used" warning?
i doubt that the car can be added inside the OnGameModeInit now, coz the Variable dosnt get initialized at start..
Reply
#7

Haha... Well it got rid of that error, no there is this...

C:\CnR SAMP Server\gamemodes\CnR.pwn(100) : error 017: undefined symbol "CIAUnmarkedSurvailenceVan"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.


Oh well, it doesn't harm anything... Haha...

Well i tried it, and it works! Thanks ALOT.

Are you like a really good scripter? (Please send reply in a PM)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)