public OnPlayerConnect(playerid)
{
SendDeathMessage(playerid, INVALID_PLAYER_ID, 200);
return 1;
}
public OnPlayerDisconnect(playerid)
{
SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
}
new aVehicle; //Above Main
//gamemodeinit
aVehicle = AddStaticVehicle(598,2256.0903,2477.0115,10.5668,178.5022,0,1); //gamemodeinit
public AdminLock(playerid) //Anywhere in script
{
if(IsPlayerConnected(playerid))
{
if(IsPlayerAdmin(playerid))
{
SetVehicleParamsForPlayer(aVehicle, playerid,0,0);
}
else
{
SetVehicleParamsForPlayer(aVehicle, playerid,0,1);
}
}
}
public OnPlayerSpawn(playerid)
{
AdminLock(playerid);
return 1;
}
AddStaticVehicleEx(598,2256.0903,2477.0115,10.5668,178.5022,0,1,never);
new maxplayers; //Global Variable
public OnPlayerConnect(playerid){
if(playerid > maxplayers-1) maxplayers = playerid+1; //Getting the maximum playerid
}
public OnPlayerDisconnect(playerid){
if(playerid == maxplayers+1) for(new i=0;i<maxplayers;i++) if(IsPlayerConnected(i)) maxplayers = i+1; //Getting the minimum playerid
}
for(new i=0;i<maxplayers;i++) //the new more efficient loop
|
That won't work, you're assuming that all players are consecutive, which is rarely the case, you could have 10 players max, but only players 1, 4, 7 and 9 connected, which would make the max thing 9, saving almost nothing, and you would still need to check for connection. |
AddStaticVehicleEx(425,2137.0598,1729.9246,20.5675,59.3952,0,1,never);
AddStaticVehicleEx(522,2164.1125,1720.9868,20.1695,161.4324,0,1,never);
AddStaticVehicleEx(522,2168.9771,1719.4484,19.9998,169.0915,0,1,never);
AddStaticVehicleEx(522,2174.8657,1718.4332,20.1868,165.7749,0,1,never);
AddStaticVehicleEx(522,2179.6699,1717.1212,19.9994,166.9654,0,1,never);
AddStaticVehicleEx(444,2208.9463,1654.0419,20.0004,2.0738,0,1,never);
AddStaticVehicleEx(556,2184.9636,1654.0623,20.0956,2.9973,0,1,never);
AddStaticVehicleEx(425,2201.3828,1716.8575,34.2190,88.4603,0,1,never);
AddStaticVehicleEx(520,2141.1396,1637.6151,20.1024,120.4169,0,1,never);
AddStaticVehicleEx(541,2175.4431,1613.0690,20.0886,182.6934,0,1,never);
AddStaticVehicleEx(411,2168.8147,1614.7198,20.0885,181.9470,0,1,never);
AddStaticVehicleEx(451,2163.6968,1613.2709,20.0878,175.1219,0,1,never);
AddStaticVehicleEx(447,2141.5942,1591.2502,31.6095,124.6433,0,1,never);
(19229) : error 021: symbol already defined: "AddStaticVehicleEx"
enum pInfo
{
Sleeping,
Awake,
Tired
}
new Info[MAX_PLAYERS][pInfo];
SetTimer("Motels",5000,1);
SetTimer("SleepTime",300000,1);
public SleepTime()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
SendClientMessage(i,COLOR_GREY,"* You are starting to feel sleep *");
SendClientMessage(i,COLOR_GREY,"* Go to the nearest /hotel and get a rest *");
Info[i] [Tired] = 1;
Info[i] [Awake] = 0;
Info[i] [Sleeping] = 0;
}
}
public Motels()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerInCube(i,2236,-1076,1040,2245,-1066,1100))
{
if(Info[i][Tired] == 1)
{
GameTextForPlayer(i,"~w~Please wait while your energy is ~b~restored",3000,3);
Info[i] [Tired] = 0;
Info[i] [Sleeping] = 1;
Info[i] [Awake] = 0;
TogglePlayerControllable(i,0);
}
if(Info[i] [Awake] == 1)
{
GameTextForPlayer(i,"~w~You ~g~don't ~w~need to rest",2000,3);
}
if(Info[i] [Sleeping] == 1)
{
Info[i] [Awake] = 1;
Info[i] [Tired] = 0;
Info[i] [Sleeping] = 0;
GameTextForPlayer(i,"~w~Rise and Shine",2000,3);
TogglePlayerControllable(i,1);
}
}
if(IsPlayerInCube(i,2202,-1070,1000,2211,-1078,1100))
{
if(Info[i][Tired] == 1)
{
GameTextForPlayer(i,"~w~Please wait while your energy is ~b~restored",3000,3);
Info[i] [Tired] = 0;
Info[i] [Sleeping] = 1;
Info[i] [Awake] = 0;
TogglePlayerControllable(i,0);
}
if(Info[i] [Awake] == 1)
{
GameTextForPlayer(i,"~w~You ~g~don't ~w~need to rest",2000,3);
}
if(Info[i] [Sleeping] == 1)
{
Info[i] [Awake] = 1;
Info[i] [Tired] = 0;
Info[i] [Sleeping] = 0;
GameTextForPlayer(i,"~w~Rise and Shine",2000,3);
TogglePlayerControllable(i,1);
}
}
}
return 1;
}
if ( IsPlayerInCube(i,2236,-1076,1040,2245,-1066,1100) || IsPlayerInCube(i,2202,-1070,1000,2211,-1078,1100) )
#define MAX_VEHICLES 255 //amount of cars in script
new aVehicle[MAX_VEHICLES] //define of aVehicle
new never = 1000000;
aVehicle[1] = AddStaticVehicleEx(522,2164.1125,1720.9868,20.1695,161.4324,0,1,never);
aVehicle[2] = AddStaticVehicleEx(522,2168.9771,1719.4484,19.9998,169.0915,0,1,never);
public AdminLock(playerid) //Anywhere in script
{
if(IsPlayerConnected(playerid))
{
if(IsPlayerAdmin(playerid))
{
SetVehicleParamsForPlayer(aVehicle[MAX_VEHICLES], playerid,0,0);
}
else
{
SetVehicleParamsForPlayer(aVehicle[MAX_VEHICLES], playerid,0,1);
}
}
}
new RedAlertTimer;
public KickAll()
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
Kick(i);
}
}
}
if (strcmp(cmdtext, "/redalert", true)==0)
{
if(IsPlayerAdmin(playerid))
{
new string[256];
new aname[256];
GetPlayerName(playerid,aname,sizeof(aname));
GameTextForAll("~r~Red Alert",7000,4);
format(string,sizeof(string), "Admin: %s has called Red Alert",aname);
SendClientMessageToAll(0xAA3333AA,string);
SendClientMessageToAll(0xAA3333AA,"You will all be kicked in ten seconds.");
RedAlertTimer = SetTimer("KickAll",10000,0);
SendClientMessage(playerid, 0xFFFF00AA, "Red Alert Successful. To Abort Type /abort");
printf("%s has initialized the red alert countdown.",aname);
return 1;
}
else
{
return 0;
}
return 1;
}
if (strcmp(cmdtext, "/abort", true)==0)
{
if(IsPlayerAdmin(playerid))
{
new string[256];
new aname[256];
GetPlayerName(playerid,aname,sizeof(aname));
GameTextForAll("~y~Red Alert Aborted",7000,4);
format(string,sizeof(string), "Admin: %s has canceled the Red Alert",aname);
SendClientMessageToAll(0x33AA33AA,string);
KillTimer(RedAlertTimer);
SendClientMessage(playerid, 0xFFFF00AA, "Red Alert Abort Successful.");
printf("%s has cancelled the red alert countdown.",aname);
return 1;
}
else
{
return 0;
}
return 1;
}
// Set the timer triggering the function which checks if players are in the 'admin' area
SetTimer("AreaCheck", 1000, 1);
// The function
AreaCheck()
{
for(new i=0; i<MAX_PLAYERS; i++ ) {
if(IsPlayerConnected(i) && IsPlayerInArea(i, minx, maxx, miny, maxy) && !IsPlayerAdmin(i)) // CHECK: If the player is a admin, if the player is in the area
{ // He's not.
SendClientMessage(i, YOURCOLOR, "You are not allowed to enter the ADMIN area.");
/* Do with him whatever
you want */
}
}
}
// ISPIA Function
IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return 1;
return 0;
}
SendClientMessage(i, YOURCOLOR, "You are not allowed to enter the ADMIN area.");
|
Originally Posted by Flame^
I really dont see the use of that in this type of function :/ ..
|
SetTimer("AreaCheck", 1000, 1);
AreaCheck()
{
for(new i=0; i<MAX_PLAYERS; i++ ) {
if(IsPlayerConnected(i))
{
if(IsPlayerInArea(i, minx, maxx, miny, maxy) && !IsPlayerAdmin(i)) // CHECK: If the player is a admin, if the player is in the area
{ // He's not.
SendClientMessage(i, YOURCOLOR, "You are not allowed to enter the ADMIN area.");
/* Do with him whatever you want */
}
}
}
}
IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return 1;
return 0;
}
|
Originally Posted by Pixels^
What do i need to edit?
|