Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
|
06-11-2016
, 09:09
Re: Random Respawn Pos
|
#4
|
Well, I didn't found it, so I recreated it, not tested through :
PHP Code:
#include <sourcemod> #include <sdktools> #include <colors>
#define PLUGIN_AUTHOR "Arkarr" #define PLUGIN_VERSION "1.00" #define PLUGIN_TAG "[Spawn Editor]" #define PLUGIN_CTAG "{green}[Spawn Editor]{default}"
#define CUSTOM_SPAWN_ENABLED "CUSTOM_SPAWN_ENABLED" #define POSITION_X "POSITION_X" #define POSITION_Y "POSITION_Y" #define POSITION_Z "POSITION_Z"
Handle ARRAY_Spawns;
bool PluginEnabled;
int NumberOfSpawns;
public Plugin myinfo = { name = "[ANY] Spawn Editor", author = PLUGIN_AUTHOR, description = "Allow you to edit default spawn location", version = PLUGIN_VERSION, url = "http://www.sourcemode.net" };
public void OnPluginStart() { ARRAY_Spawns = CreateArray(); HookEvent("player_spawn", Event_PlayerSpawn); RegAdminCmd("sm_createspawn", CMD_CreateSpawn, ADMFLAG_CHANGEMAP, "Create a new spawn location"); }
public void OnMapStart() { char mapName[45]; GetCurrentMap(mapName, sizeof(mapName)); PluginEnabled = LoadConfiguration(mapName); if(!PluginEnabled) PrintToServer("%s Plugin is DISABLED", PLUGIN_TAG); }
public void OnMapEnd() { SaveConfiguration(); }
public Action CMD_CreateSpawn(client, args) { if(!PluginEnabled) return Plugin_Handled; if(client == 0) { PrintToServer("%s This command is restricted to in-game.", PLUGIN_TAG); return Plugin_Handled; } float newSpawn[3]; GetEntPropVector(client, Prop_Send, "m_vecOrigin", newSpawn); Handle trie = CreateTrie(); SetTrieValue(trie, POSITION_X, newSpawn[0]); SetTrieValue(trie, POSITION_Y, newSpawn[1]); SetTrieValue(trie, POSITION_Z, newSpawn[2]); PushArrayCell(ARRAY_Spawns, trie); CPrintToChat(client, "%s New spawn added :D !", PLUGIN_CTAG); NumberOfSpawns++; return Plugin_Handled; }
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) { if(!PluginEnabled) return; int client = GetClientOfUserId(GetEventInt(event, "userid")); if(!IsValidClient(client)) return; PrintToChatAll("New spawn ID between : 0 - %i", (NumberOfSpawns-1)); int spawnID = GetRandomInt(0, NumberOfSpawns-1); Handle positions = GetArrayCell(ARRAY_Spawns, spawnID); float newSpawn[3]; GetTrieValue(positions, POSITION_X, newSpawn[0]); GetTrieValue(positions, POSITION_Y, newSpawn[1]); GetTrieValue(positions, POSITION_Z, newSpawn[2]); TeleportEntity(client, newSpawn, NULL_VECTOR, NULL_VECTOR); }
stock void SaveConfiguration() { char path[75], mapName[45]; GetCurrentMap(mapName, sizeof(mapName)); BuildPath(Path_SM, path, sizeof(path), "configs/SpawnEditor/%s.cfg", mapName); Handle file = OpenFile(path,"w"); WriteFileLine(file, "%s=%s", CUSTOM_SPAWN_ENABLED, (PluginEnabled ? "TRUE" : "FALSE")); for(int i = 0; i < GetArraySize(ARRAY_Spawns); i++) { Handle trie = GetArrayCell(ARRAY_Spawns, i); float Px = 0.0; float Py = 0.0; float Pz = 0.0; GetTrieValue(trie, POSITION_X, Px); GetTrieValue(trie, POSITION_Y, Py); GetTrieValue(trie, POSITION_Z, Pz); WriteFileLine(file, "%f;%f;%f", Px, Py, Pz); } }
stock bool LoadConfiguration(const char[] mapName) { char path[75]; BuildPath(Path_SM, path, sizeof(path), "configs/SpawnEditor/%s.cfg", mapName); if(!DirExists("addons/sourcemod/configs/SpawnEditor")) CreateDirectory("/addons/sourcemod/configs/SpawnEditor", 777); Handle file = INVALID_HANDLE; if(!FileExists(path)) file = OpenFile(path,"w"); else file = OpenFile(path, "r"); char line[200]; bool firstLine = true; ClearArray(ARRAY_Spawns); while(!IsEndOfFile(file) && ReadFileLine(file, line, sizeof(line))) { if(firstLine) { if(StrContains(line, CUSTOM_SPAWN_ENABLED) == 0) { if(StrContains(line, "FALSE", false) != -1) return false; firstLine = false; } } else { char positions[3][15]; ExplodeString(line, ";", positions, sizeof positions, sizeof positions[]); Handle trie = CreateTrie(); SetTrieValue(trie, POSITION_X, StringToFloat(positions[0])); SetTrieValue(trie, POSITION_Y, StringToFloat(positions[1])); SetTrieValue(trie, POSITION_Z, StringToFloat(positions[2])); PushArrayCell(ARRAY_Spawns, trie); } } CloseHandle(file); if(firstLine) { PrintToServer("%s NO CONFIGURATION FOUND !", PLUGIN_TAG); PrintToServer("%s Default spawn will be used !", PLUGIN_TAG); return false; } NumberOfSpawns = GetArraySize(ARRAY_Spawns) if(NumberOfSpawns < 1) PrintToServer("%s ZERO SPAWNS FOUND !", PLUGIN_TAG); else PrintToServer("%s LOADED %i CUSTOM SPAWNS !", PLUGIN_TAG, NumberOfSpawns); return true; }
stock bool IsValidClient(int client) { if (client <= 0)return false; if (client > MaxClients)return false; if (!IsClientConnected(client))return false; return IsClientInGame(client); }
Any donation thankfully accepted...
__________________
Last edited by Arkarr; 06-11-2016 at 10:53.
|
|