Hi guys,
This is my very first attempt to create a plugin. But i have read on Source Pawn earlier and i have coding experience from PHP.
I am trying to make a plugin, that will set a players health to 150, if he has the custom6 flag, and if he has choose to get it, in the menu.
I have created a menu, where i want the player to be able to select Health boost on/off.
If he has selected On, next time he spawns he will get the boosed Health, and every time he spawns, until he enters the menu, to turn it off again.
It does not need to remember he choice if he disconnects, just for the current session (if it can remember it always, it will just be nice to have).
So far i have managed to create a menu, and the set health on spawn, if he has the custom6 flag - however, he does not have a choice right now, he will always have the boosted health.
Could you guys help me in the direction of what i need to do, to accomplish the above?
Code:
#include <sourcemod>
#define PLUGIN_VERSION "1.0"
public Plugin:myinfo =
{
name = "Test Plugin",
author = "ReLaX",
description = "Test Plugin",
version = PLUGIN_VERSION,
url = ""
}
public OnPluginStart()
{
/* Creating ConVars */
CreateConVar( "sm_testmenu_version", PLUGIN_VERSION, "Testmenu Plugin Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY );
/* Registering Commands */
RegConsoleCmd("sm_testmenu", test_menu);
/* Hooks */
HookEvent("player_spawn", Event_Spawn);
}
/* This is a event that will change properties on player spawn. */
public Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new valueHealth = 150;
new clientId = GetClientOfUserId(GetEventInt(event, "userid"));
if (clientId != 0 && IsClientInGame(clientId) && IsPlayerAlive(clientId))
{
/* Set Health */
if (CheckCommandAccess(clientId, "test_health", ADMFLAG_CUSTOM6, false))
{
SetEntityHealth(clientId, valueHealth);
}
}
return bool:Plugin_Handled;
}
public MenuHandler1(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:info[32];
new bool:found = GetMenuItem(menu, param2, info, sizeof(info));
PrintToConsole(param1, "You selected item: %d (found? %d info: %s)", param2, found, info);
}
/* If the menu was cancelled, print a message to the server about it. */
else if (action == MenuAction_Cancel)
{
PrintToServer("Client %d's menu was cancelled. Reason: %d", param1, param2);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
public Action:test_menu(client, args)
{
new Handle:menu = CreateMenu(MenuHandler1);
SetMenuTitle(menu, "Test Menu");
AddMenuItem(menu, "health", "Health");
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, 20);
return Plugin_Handled;
}
The "menu" code above is just a modified version of an example from the SourceMod Documentation
__________________