Jump to content

script Admin Spec


_Tomas9_

Recommended Posts

Admin spec

Commands:

/specplayer

/specvehicle

/specoff

#pragma tabsize 0
#include <a_samp>
#include <core>
#include <float>
#include "../include/gl_common.inc"
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFFF
//------------------------------------------------------------------------------------------------------
#define ADMIN_SPEC_TYPE_NONE 0
#define ADMIN_SPEC_TYPE_PLAYER 1
#define ADMIN_SPEC_TYPE_VEHICLE 2
new gSpectateID[MAX_PLAYERS];
new gSpectateType[MAX_PLAYERS];
//------------------------------------------------------------------------------------------------------
public OnFilterScriptInit()
{
}
//------------------------------------------------------------------------------------------------------
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
// IF ANYONE IS SPECTATING THIS PLAYER, WE'LL ALSO HAVE
// TO CHANGE THEIR INTERIOR ID TO MATCH
new x = 0;
while(x!=MAX_PLAYERS) {
 if( IsPlayerConnected(x) && GetPlayerState(x) == PLAYER_STATE_SPECTATING &&
  gSpectateID[x] == playerid && gSpectateType[x] == ADMIN_SPEC_TYPE_PLAYER )
 {
	 SetPlayerInterior(x,newinteriorid);
 }
 x++;
}
}
//------------------------------------------------------------------------------------------------------
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new specplayerid, specvehicleid, idx;
//
if(!IsPlayerAdmin(playerid)) return 0;
cmd = strtok(cmdtext, idx);
// SPECTATE A PLAYER
 if(strcmp(cmd, "/specplayer", true) == 0) {
 new tmp[256];
 tmp = strtok(cmdtext, idx);
 if(!strlen(tmp)) {
  SendClientMessage(playerid, COLOR_WHITE, "USAGE: /specplayer [playerid]");
  return 1;
 }
 specplayerid = strval(tmp);
 if(!IsPlayerConnected(specplayerid)) {
  SendClientMessage(playerid, COLOR_RED, "specplayer: that player isn't active.");
  return 1;
 }
 TogglePlayerSpectating(playerid, 1);
 PlayerSpectatePlayer(playerid, specplayerid);
 SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
 gSpectateID[playerid] = specplayerid;
 gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
  return 1;
}
// SPECTATE A VEHICLE
 if(strcmp(cmd, "/specvehicle", true) == 0) {
 new tmp[256];
 tmp = strtok(cmdtext, idx);
 if(!strlen(tmp)) {
  SendClientMessage(playerid, COLOR_WHITE, "USAGE: /specvehicle [vehicleid]");
  return 1;
 }
 specvehicleid = strval(tmp);
 if(specvehicleid < MAX_VEHICLES) {
  TogglePlayerSpectating(playerid, 1);
  PlayerSpectateVehicle(playerid, specvehicleid);
  gSpectateID[playerid] = specvehicleid;
  gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
 }
  return 1;
}
// STOP SPECTATING
 if(strcmp(cmd, "/specoff", true) == 0) {
 TogglePlayerSpectating(playerid, 0);
 gSpectateID[playerid] = INVALID_PLAYER_ID;
 gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
 return 1;
}
return 0;
}
//------------------------------------------------------------------------------------------------------

Include

   //----------------------------------------------------------
   //
   // GRAND LARCENY common functions include.
   //
   //----------------------------------------------------------

   stock LoadStaticVehiclesFromFile(const filename[])
   {
   new File:file_ptr;
   new line[256];
   new var_from_line[64];
   new vehicletype;
   new Float:SpawnX;
   new Float:SpawnY;
   new Float:SpawnZ;
   new Float:SpawnRot;
   new Color1, Color2;
   new index;
   new vehicles_loaded;

   file_ptr = fopen(filename,filemode:io_read);
   if(!file_ptr) return 0;

   vehicles_loaded = 0;

   while(fread(file_ptr,line,256) > 0)
   {
   index = 0;

   // Read type
   index = token_by_delim(line,var_from_line,',',index);
   if(index == (-1)) continue;
   vehicletype = strval(var_from_line);
   if(vehicletype < 400 || vehicletype > 611) continue;

   // Read X, Y, Z, Rotation
   index = token_by_delim(line,var_from_line,',',index+1);
   if(index == (-1)) continue;
   SpawnX = floatstr(var_from_line);

   index = token_by_delim(line,var_from_line,',',index+1);
   if(index == (-1)) continue;
   SpawnY = floatstr(var_from_line);

   index = token_by_delim(line,var_from_line,',',index+1);
   if(index == (-1)) continue;
   SpawnZ = floatstr(var_from_line);

   index = token_by_delim(line,var_from_line,',',index+1);
   if(index == (-1)) continue;
   SpawnRot = floatstr(var_from_line);

   // Read Color1, Color2
   index = token_by_delim(line,var_from_line,',',index+1);
   if(index == (-1)) continue;
   Color1 = strval(var_from_line);

   index = token_by_delim(line,var_from_line,';',index+1);
   Color2 = strval(var_from_line);

   //printf("%d,%d,%f,%f,%f,%f,%d,%d",total_vehicles_from_files+vehicles_loaded+1,vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2);

   AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(30*60)); // respawn 30 minutes
   vehicles_loaded++;
   }

   fclose(file_ptr);
   printf("Loaded %d vehicles from: %s",vehicles_loaded,filename);
   return vehicles_loaded;
   }

   //----------------------------------------------------------

   stock strtok(const string[], &index)
   {
   new length = strlen(string);
   while ((index < length) && (string[index] <= ' '))
   {
   index++;
   }

   new offset = index;
   new result[20];
   while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
   {
   result[index - offset] = string[index];
   index++;
   }
   result[index - offset] = EOS;
   return result;
   }

   //------------------------------------------------

   stock strrest(const string[], &index)
   {
   new length = strlen(string);
   while ((index < length) && (string[index] <= ' '))
   {
   index++;
   }
   new offset = index;
   new result[128];
   while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
   {
   result[index - offset] = string[index];
   index++;
   }
   result[index - offset] = EOS;
   return result;
   }

   //----------------------------------------------------------
   // Tokenise by a delimiter
   // Return string and index of the end determined by the
   // provided delimiter in delim

   stock token_by_delim(const string[], return_str[], delim, start_index)
   {
   new x=0;
   while(string[start_index] != EOS && string[start_index] != delim) {
   return_str[x] = string[start_index];
   x++;
   start_index++;
   }
   return_str[x] = EOS;
   if(string[start_index] == EOS) start_index = (-1);
   return start_index;
   }

   //----------------------------------------------------------

   stock isNumeric(const string[])
   {
   new length=strlen(string);
   if (length==0) return false;
   for (new i = 0; i < length; i++)
   {
   if (
   (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
   || (string[i]=='-' && i!=0) // A '-' but not at first.
   || (string[i]=='+' && i!=0) // A '+' but not at first.
   ) return false;
   }
   if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
   return true;
   }

   //----------------------------------------------------------

   stock IsKeyJustDown(key, newkeys, oldkeys)
   {
   if((newkeys & key) && !(oldkeys & key)) return 1;
   return 0;
   }

   //----------------------------------------------------------

Link to comment
Share on other sites

Hele a podle mě je blbost dávat /specvehicle nebo jak to je zrovna to udělat když dáš /spec tak to specne hráče a je to jedno jestli je v autě a nebo ne

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...