Manager quix Posted March 16, 2023 Manager Share Posted March 16, 2023 In this topic, I'll post some codes I'll create for you to understand how this language works. (NOTE: These codes might not work as intended and might need some changes!) 1. If the player has "Leaks" in their name, it sends a welcoming message to them, eitherway, it sets their health to 200: #include <sourcemod> public Action:ClientConnect(int client) { char name[MAX_PLAYER_NAME+1]; GetClientName(client, name, sizeof(name)); if (strstr(name, "Leaks") != NULL) { char msg[128]; format(msg, sizeof(msg), "Welcome to the server, %s! Enjoy your stay.", name); ShowSyncTextMsg(client, 1, msg); } else { SetEntProp(client, Prop_Send, "m_iHealth", 200); } return Plugin_Continue; } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 16, 2023 Author Manager Share Posted March 16, 2023 2. Shows when the player kills an enemy by a headshot: #include <sourcemod> public Action:ClientDisconnect(int client) { // Clean up any textdraws when the client disconnects ShowSyncHudText(client, -1, ""); return Plugin_Continue; } public Action:ClientPostThink(int client) { // Check if the player killed an enemy with a headshot if (GetClientProp(client, Prop_Send, "m_iLastKilledByHeadshot") == 1) { // Show a congratulatory textdraw ShowSyncHudText(client, 1, "Headshot! Nice shot!"); } return Plugin_Continue; } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 16, 2023 Author Manager Share Posted March 16, 2023 3. Sends a welcoming message every 10 minutes in chat: #include <sourcemod> public void OnPluginStart() { CreateTimer(600.0, RepeatMessage, _, TIMER_REPEAT); } public Action RepeatMessage(Handle timer) { ChatMessage("\x04[Leaks]\x01 Welcome to Leaks!", -1); return Plugin_Continue; } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 16, 2023 Author Manager Share Posted March 16, 2023 4. This code creates a new currency named "LeakCoins" and will be visible by a textdraw at the middle bottom of the screen. If you kill someone with a headshot, you get 10 LeakCoins, eitherway you only get 5 and if you die you lose 5. It updates after every kill / death and resets LeakCoins to 0 after player disconnection. #include <sourcemod> new const Float:TEXTDRAW_X = 320.0; new const Float:TEXTDRAW_Y = 450.0; new Handle:textdraw_LeakCoins; public void OnPluginStart() { // Create the textdraw for LeakCoins textdraw_LeakCoins = TextDrawCreate(TEXTDRAW_X, TEXTDRAW_Y, "LeakCoins: 0"); TextDrawColor(textdraw_LeakCoins, 255, 0, 0, 255); // Set the text color to red TextDrawSetOutline(textdraw_LeakCoins, 1); // Add an outline to the text } public Action EntDeath(ent, attacker, weapon) { if (!IsClientConnected(ent) || !IsClientConnected(attacker)) return Plugin_Continue; if (attacker == ent) // Suicide { TextDrawSetString(textdraw_LeakCoins, "LeakCoins: " + GetPlayerInt(attacker, "LeakCoins")); return Plugin_Continue; } // Check if the attacker killed with headshot or not if (weapon == CSW_DEAGLE && GetClientEyePosition(attacker, Vector:eye_pos) && GetClientEyePosition(ent, Vector:victim_pos)) { new Float:distance = GetDistanceBetweenPoints(eye_pos, victim_pos); if (distance <= 128.0) { SetPlayerInt(attacker, "LeakCoins", GetPlayerInt(attacker, "LeakCoins") + 10); TextDrawSetString(textdraw_LeakCoins, "LeakCoins: " + GetPlayerInt(attacker, "LeakCoins")); return Plugin_Continue; } } // If the attacker didn't kill with headshot, give them 5 LeakCoins SetPlayerInt(attacker, "LeakCoins", GetPlayerInt(attacker, "LeakCoins") + 5); TextDrawSetString(textdraw_LeakCoins, "LeakCoins: " + GetPlayerInt(attacker, "LeakCoins")); return Plugin_Continue; } public Action ClientDisconnect(client) { SetPlayerInt(client, "LeakCoins", 0); TextDrawSetString(textdraw_LeakCoins, "LeakCoins: 0"); return Plugin_Continue; } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 17, 2023 Author Manager Share Posted March 17, 2023 5. Adds a command to make someone a VIP and gives them the ability to double jump: #include <sourcemod> // Variables int g_VipIndex = -1; // Function prototypes void OnPluginStart(); void OnClientPutInServer(int client); void OnClientDisconnected(int client); void OnPlayerRunCmd(int client, CUserCmd@ cmd); // Plugin initialization void OnPluginStart() { RegConsoleCmd("sm_makevip", CmdMakeVip, "Make a player a VIP"); } // Player events void OnClientPutInServer(int client) { if (IsClientInGame(client) && g_VipIndex != -1 && client == g_VipIndex) { // Remove the "on ground" flag so the player can double jump SetGroundEntity(client, Entity(0)); } } void OnClientDisconnected(int client) { if (client == g_VipIndex) { g_VipIndex = -1; } } void OnPlayerRunCmd(int client, CUserCmd@ cmd) { if (client == g_VipIndex) { // Double jump if (cmd.buttons & IN_JUMP) { if (IsOnGround(client)) { SetGroundEntity(client, Entity(0)); } else { SetEntityVelocity(client, GetEntityVelocity(client) + Vector(0, 0, 250)); } } } } // Console commands void CmdMakeVip(int client, const CCommand@ args) { if (args.ArgC() < 2) { PrintToChat(client, "Usage: sm_makevip <target>"); return; } int target = GetTargetClient(client, args.Arg(1)); if (target == 0) { PrintToChat(client, "Player not found"); return; } if (g_VipIndex != -1) { // Remove the "on ground" flag from the previous VIP player if there was one SetGroundEntity(g_VipIndex, Entity(0)); } g_VipIndex = target; PrintToChatAll(GetClientName(g_VipIndex) + " is now a VIP!"); } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 17, 2023 Author Manager Share Posted March 17, 2023 6. Creates two separate permissions: admin and root, for admin you have the prefix [Moderator] with a green color in chat, and for root you have the prefix [Administrator] with a red color in chat: #include <sourcemod> // Function prototypes void OnPluginStart(); void OnClientAuthorized(int client); void OnAdminCheck(int client, int authlevel); // Plugin initialization void OnPluginStart() { // Register events RegAdminCmd("sm_moderator", CmdSetModerator, ADMFLAG_ADMIN, "Add the moderator prefix to a player's name"); RegAdminCmd("sm_administrator", CmdSetAdministrator, ADMFLAG_ROOT, "Add the administrator prefix to a player's name"); RegEvent("client_auth", "OnClientAuthorized", "b"); RegEvent("player_spawn", "OnAdminCheck", "ci", "1=normal,2=admin,3=root"); } // Events void OnClientAuthorized(int client) { // Add the appropriate prefix to the player's name when they join the server if (GetAdminLevel(client) >= ADMFLAG_ADMIN) { SetClientName(client, "\x01[Moderator] \x04" + GetClientName(client)); } else if (GetAdminLevel(client) >= ADMFLAG_MODERATOR) { SetClientName(client, "\x01[Administrator] \x03" + GetClientName(client)); } } void OnAdminCheck(int client, int authlevel) { // Update the player's name with the appropriate prefix when their admin level changes if (authlevel >= ADMFLAG_ADMIN) { SetClientName(client, "\x01[Moderator] \x04" + GetClientName(client)); } else if (authlevel >= ADMFLAG_MODERATOR) { SetClientName(client, "\x01[Administrator] \x03" + GetClientName(client)); } } // Console commands void CmdSetModerator(int client, const CCommand@ args) { if (args.ArgC() < 2) { PrintToChat(client, "Usage: sm_moderator <target>"); return; } int target = GetTargetClient(client, args.Arg(1)); if (target == 0) { PrintToChat(client, "Player not found"); return; } SetAdminFlag(target, ADMFLAG_MODERATOR); } void CmdSetAdministrator(int client, const CCommand@ args) { if (args.ArgC() < 2) { PrintToChat(client, "Usage: sm_administrator <target>"); return; } int target = GetTargetClient(client, args.Arg(1)); if (target == 0) { PrintToChat(client, "Player not found"); return; } SetAdminFlag(target, ADMFLAG_ADMIN); } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Manager quix Posted March 17, 2023 Author Manager Share Posted March 17, 2023 7. Creates a textdraw that shows player's velocity with the color cyan and the text "Leaks Speed: ": #include < amxmodx > #include < amxmisc > #include < hamsandwich > new Float:vSpeed[32]; public plugin_init() { register_plugin("Velocity Textdraw", "1.0", "Your Name"); register_event("HLTV", "player_disconnect", "a"); register_event("HLTV", "round_end", "a"); register_event("HLTV", "player_run_cmd", "ahf", "1=client,2=cmd,3=forward"); register_clcmd("say", "cmd_say"); register_clcmd("say_team", "cmd_say_team"); create_velocity_textdraw(); register_logevent("Velocity Textdraw Enabled."); } public create_velocity_textdraw() { new id = textdraw_create(400.0, 10.0, "Leaks Speed: "); textdraw_color(id, 0x00FFFFAA); textdraw_font(id, 1); textdraw_letter_size(id, 0.2, 0.8); textdraw_set_outline(id, 1); textdraw_set_shadows(id, 1); } public player_run_cmd(id, cmd[], foward) { if(!is_user_connected(id)) return Plugin_Handled; if(get_user_flags(id) & ADMIN_FLAG) { if(!stricmp(cmd, "velocity_textdraw")) { create_velocity_textdraw(); client_print(id, print_chat, "Velocity Textdraw created."); return Plugin_Handled; } } new Float:vSpeed[2]; pev(id, pev_velocity, vSpeed); new Float:Speed = Float:sqrt(vSpeed[0] * vSpeed[0] + vSpeed[1] * vSpeed[1] + vSpeed[2] * vSpeed[2]); set_pdata_float(id, 0, Speed); return Plugin_Continue; } public client_putinserver(id) { set_pdata_float(id, 0, 0.0); } public player_disconnect(id) { set_pdata_float(id, 0, 0.0); } public round_end() { for(new i = 1; i <= get_maxplayers(); i++) { if(is_user_connected(i)) { textdraw_set_text(Float:vSpeed[i], i); } } } public cmd_say(id, msg[], team) { return Plugin_Continue; } public cmd_say_team(id, msg[]) { return Plugin_Continue; } Hi, DM me ONLY if you have problems on my uploads! With love, quix! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now