Senior Member
Join Date: Dec 2013
Location: Israel
|
07-21-2015
, 14:52
Re: Detected out of bounds index 0
|
#2
|
You got compile warning, and you didn't fix, I fixed it to you, so try to compile it:
PHP Code:
#include <sourcemod> #include <sdktools> #pragma semicolon 1 #define PLUGIN_VERSION "1.13.0" new bool:pSpawnSet[MAXPLAYERS+1]; new Float:pSpawn[MAXPLAYERS+1][3]; new Float:pAngle[MAXPLAYERS+1][3]; new pTeam[MAXPLAYERS+1]; new Handle:cEnabled; public Plugin:myinfo = { name = "Player Spawns", author = "noodleboy347 & WhosAsking?", description = "Sets player spawns", version = PLUGIN_VERSION, url = "http://www.frozencubes.com" } public OnPluginStart() { RegConsoleCmd("sm_whereami", Command_WhereAmI); RegConsoleCmd("sm_setspawn", Command_Setspawn); RegConsoleCmd("sm_clearspawn", Command_Clearspawn); RegAdminCmd("sm_setplayerspawn", Command_Setplayerspawn, ADMFLAG_GENERIC); RegAdminCmd("sm_setplayerspawn2", Command_Setplayerspawn, ADMFLAG_GENERIC); RegAdminCmd("sm_clearplayerspawn", Command_Clearplayerspawn, ADMFLAG_GENERIC); RegAdminCmd("sm_savespawn", Command_Savespawn, ADMFLAG_GENERIC); RegAdminCmd("sm_loadspawn", Command_Loadspawn, ADMFLAG_GENERIC); CreateConVar("sm_playerspawns_version", PLUGIN_VERSION, "Player Spawns plugin version", FCVAR_NOTIFY); cEnabled = CreateConVar("sm_playerspawns_enable", "1", "Enables plugin"); HookConVarChange(cEnabled, Cvar_Toggle); HookEvent("player_spawn", Event_Spawn); } bool:CanSetSpawn(client) { return GetConVarBool(cEnabled) && ((IsPlayerAlive(client) && (GetClientTeam(client) > 1)) || IsFakeClient(client)); } public Cvar_Toggle(Handle:cvar, const String:oldVal[], const String:newVal[]) { if(StringToInt(newVal) == 0) { for(new i=1; i < GetMaxClients(); i++) { pSpawnSet[i] = false; } } } public OnClientPostAdminCheck(client) { pSpawnSet[client] = false; pTeam[client] = 0; } public Action:Command_Setspawn(client, args) { if(CanSetSpawn(client)) { GetClientAbsOrigin(client, pSpawn[client]); GetClientAbsAngles(client, pAngle[client]); pSpawnSet[client] = true; pTeam[client] = GetClientTeam(client); ReplyToCommand(client, "[SM] Spawn location set."); } else ReplyToCommand(client, "[SM] You can't set a spawn now."); return Plugin_Handled; } public Action:Command_Clearspawn(client, args) { if(GetConVarBool(cEnabled)) { if(!pSpawnSet[client]) ReplyToCommand(client, "[SM] You haven't set your spawn yet."); else { ReplyToCommand(client, "[SM] Spawn location cleared."); pSpawnSet[client] = false; } } return Plugin_Handled; } public Action:Command_Setplayerspawn(client, args) { if(GetConVarBool(cEnabled)) { decl String:arg[64]; GetCmdArg(0, arg, sizeof(arg)); if(args < 1) { ReplyToCommand(client, "[SM] Usage: %s <player>", arg); return Plugin_Handled; } new bool:alt = (StrContains(arg,"setplayerspawn2",false) >= 0); GetCmdArg(1, arg, sizeof(arg)); decl String:target_name[MAX_TARGET_LENGTH]; decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; if((target_count = ProcessTargetString( arg, client, target_list, MAXPLAYERS, 0, target_name, sizeof(target_name), tn_is_ml)) <= 0) { ReplyToTargetError(client, target_count); return Plugin_Handled; } for(new i = 0; i < target_count; i++) if (CanSetSpawn(target_list[i])) { new source = (alt) ? target_list[i] : client; GetClientAbsOrigin(source, pSpawn[target_list[i]]); GetClientAbsAngles(source, pAngle[target_list[i]]); pSpawnSet[target_list[i]] = true; pTeam[target_list[i]] = GetClientTeam(target_list[i]); } else ShowActivity2(client, "[SM]", "WARNING: Spawn of %N could not be set.", target_list[i]); ShowActivity2(client, "[SM]", "Set the spawn of %s", target_name); } return Plugin_Handled; } public Action:Command_Clearplayerspawn(client, args) { if(GetConVarBool(cEnabled)) { if(args != 1) { ReplyToCommand(client, "[SM] Usage: sm_clearplayerspawn <player>"); return Plugin_Handled; } decl String:arg[64]; GetCmdArg(1, arg, sizeof(arg)); decl String:target_name[MAX_TARGET_LENGTH]; decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml; if((target_count = ProcessTargetString( arg, client, target_list, MAXPLAYERS, 0, target_name, sizeof(target_name), tn_is_ml)) <= 0) { ReplyToTargetError(client, target_count); return Plugin_Handled; } for(new i = 0; i < target_count; i++) pSpawnSet[target_list[i]] = false; ShowActivity2(client, "[SM]", "Cleared the spawn of %s", target_name); } return Plugin_Handled; } public Action:Command_Savespawn(client, args) { // Determine the name of the game. decl String:MapName[PLATFORM_MAX_PATH]; decl String:MapFile[PLATFORM_MAX_PATH]; decl String:Name[64]; GetCurrentMap(MapName, sizeof(MapName)); // Modify to arrive at the filename. Format(MapFile,sizeof(MapFile),"spawn_%s.dat",MapName); //Initiate file handling. new Handle:f = INVALID_HANDLE; // Create string for full path. decl String:FilePath[PLATFORM_MAX_PATH]; BuildPath(Path_SM, FilePath, PLATFORM_MAX_PATH, "gamedata/%s", MapFile); // Open file for writing, wiping existing content. f = OpenFile(FilePath,"wtb"); // TEST: To continue, file must be properly opened. if (f != INVALID_HANDLE) { // Write the client's ID and coordinates. for (new i = 1;i <= MAXPLAYERS;i++) // IF a Spawn is set for that client. if (pSpawnSet[i]) { GetClientName(i, Name, sizeof(Name)); WriteFileString(f, Name, true); WriteFile(f,_:pSpawn[i],3,4); WriteFile(f,_:pAngle[i],3,4); } // Writing complete. Close the file. CloseHandle(f); LogMessage("File %s saved.",MapFile); ReplyToCommand(client,"File %s saved.",MapFile); } // TEST FAIL: File didn't open correctly. Report to log and server. else { LogMessage("Error opening file %s. No locations saved.",MapFile); ReplyToCommand(client,"WARNING: Error opening file %s. No locations saved.",MapFile); } return Plugin_Handled; } public Action:Command_Loadspawn(client, args) { // Determine the name of the game. decl String:MapName[PLATFORM_MAX_PATH]; decl String:MapFile[PLATFORM_MAX_PATH]; GetCurrentMap(MapName, sizeof(MapName)); // Modify to arrive at the filename. Format(MapFile,sizeof(MapFile),"spawn_%s.dat",MapName); //Initiate file handling. new Handle:f=INVALID_HANDLE; // Create string for full path. decl String:FilePath[PLATFORM_MAX_PATH]; BuildPath(Path_SM, FilePath, PLATFORM_MAX_PATH, "gamedata/%s", MapFile); // Test #1: File must exist. if (FileExists(FilePath)) { // Open file for reading. f=OpenFile(FilePath,"rb"); // Test #2: File must have opened correctly. if (f!=INVALID_HANDLE) { // All good. Proceed with read until entire file is read. while (!IsEndOfFile(f)) { decl String:Name[64]; decl String:Match[64]; decl Float:Spawn[3]; decl Float:Angle[3]; ReadFileString(f, Name, sizeof(Name)); ReadFile(f,_:Spawn,3,4); ReadFile(f,_:Angle,3,4); for (new i = 1;i <= MaxClients;i++) { if (!IsClientConnected(i)) continue; GetClientName(i, Match, sizeof(Match)); if (StrEqual(Name, Match)) { pSpawnSet[i] = true; pSpawn[i] = Spawn; pAngle[i] = Angle; } } } LogMessage("Spawn file %s loaded.", MapFile); ReplyToCommand(client,"Spawn file %s loaded.", MapFile); } // Test #2 FAIL: File didin't open correctly. Report to log and server. else { LogMessage("Error opening file %s. No locations loaded.",MapFile); ReplyToCommand(client,"WARNING: Error opening file %s. No locations loaded.",MapFile); } // In all cases, close handle to clean up. CloseHandle(f); } // Test #1 FAIL: File does not exist. Report to log and server. else { LogMessage("File %s not found. No locations loaded.",MapFile); ReplyToCommand(client,"WARNING: File %s not found. No locations loaded.",MapFile); } return Plugin_Handled; }
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast) { new client = GetClientOfUserId(GetEventInt(event, "userid")); new team = GetClientTeam(client); if ((team == pTeam[client]) || IsPlayerAlive(client) && IsFakeClient(client)) { if(pSpawnSet[client]) TeleportEntity(client, pSpawn[client], pAngle[client], NULL_VECTOR); } else { pSpawnSet[client] = false; pTeam[client] = team; } } public Action:Command_WhereAmI(client, args) { if (IsClientConnected(client)) { new Float:Temp[3]; GetClientAbsOrigin(client, Temp); ReplyToCommand(client, "You are currently located at (%0.2f, %0.2f, %0.2f)", Temp[0], Temp[1], Temp[2]); GetClientAbsAngles(client, Temp); ReplyToCommand(client, "with an orientation of (%0.2f, %0.2f, %0.2f).", Temp[0], Temp[1], Temp[2]); } return Plugin_Handled; }
__________________
Last edited by TheUnderTaker; 07-21-2015 at 14:53.
|
|