Created
June 10, 2018 09:01
-
-
Save Nickelony/b62e01f41b4c39d60ce7ba80f43cb79c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sourcemod> | |
#include <sdktools> | |
#undef REQUIRE_PLUGIN | |
#include <shavit> | |
#pragma newdecls required | |
#pragma semicolon 1 | |
bool gB_UseSpawnPosition[MAXPLAYERS + 1]; | |
float gF_PlayerOrigin[MAXPLAYERS + 1][3]; | |
float gF_PlayerAngles[MAXPLAYERS + 1][3]; | |
public Plugin myinfo = | |
{ | |
name = "[shavit] SetSpawn", | |
author = "Nickelony", | |
description = "Allows players to set their own spawn position.", | |
version = "1.0", | |
url = "steamcommunity.com/id/nickelony" | |
} | |
public void OnPluginStart() | |
{ | |
RegConsoleCmd("sm_setspawn", Command_SetSpawn); | |
RegConsoleCmd("sm_setstart", Command_SetSpawn); | |
} | |
public void OnClientPutInServer(int client) | |
{ | |
gB_UseSpawnPosition[client] = false; | |
} | |
public Action Command_SetSpawn(int client, int args) | |
{ | |
if(client == 0) | |
{ | |
ReplyToCommand(client, "This command may be only performed in-game."); | |
return Plugin_Handled; | |
} | |
if(!IsValidClient(client)) | |
{ | |
return Plugin_Handled; | |
} | |
return OpenSpawnMenu(client); | |
} | |
public Action OpenSpawnMenu(int client) | |
{ | |
Menu menu = new Menu(Menu_Handler); | |
menu.SetTitle("Classic Save"); | |
menu.AddItem("0", "Save Spawn"); | |
menu.AddItem("1", "Delete Spawn", (gB_UseSpawnPosition[client]) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED); | |
menu.ExitButton = true; | |
menu.Display(client, 20); | |
return Plugin_Handled; | |
} | |
public int Menu_Handler(Menu menu, MenuAction action, int param1, int param2) | |
{ | |
if(action == MenuAction_Select) | |
{ | |
char[] info = new char[16]; | |
menu.GetItem(param2, info, 16); | |
int choice = StringToInt(info); | |
MenuSelection(param1, choice); | |
OpenSpawnMenu(param1); | |
} | |
else if(action == MenuAction_End) | |
{ | |
delete menu; | |
} | |
return 0; | |
} | |
void MenuSelection(int client, int choice) | |
{ | |
if(choice == 0) | |
{ | |
if(Shavit_InsideZone(client, Zone_Start, -1)) | |
{ | |
if((GetClientButtons(client) & IN_DUCK) > 0) | |
{ | |
Shavit_PrintToChat(client, "You cannot duck while using this command"); | |
return; | |
} | |
float origin[3]; | |
GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin); | |
float angles[3]; | |
GetClientEyeAngles(client, angles); | |
gF_PlayerOrigin[client] = origin; | |
gF_PlayerAngles[client] = angles; | |
gB_UseSpawnPosition[client] = true; | |
Shavit_PrintToChat(client, "Spawn saved."); | |
} | |
else | |
{ | |
Shavit_PrintToChat(client, "You have to be in the start zone to use this command!"); | |
return; | |
} | |
} | |
else | |
{ | |
gB_UseSpawnPosition[client] = false; | |
Shavit_PrintToChat(client, "Spawn deleted."); | |
} | |
} | |
public void Shavit_OnRestart(int client, int track) | |
{ | |
if(gB_UseSpawnPosition[client]) | |
{ | |
TeleportEntity(client, gF_PlayerOrigin[client], gF_PlayerAngles[client], NULL_VECTOR); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment