欢迎光临散文网 会员登陆 & 注册

自定义血量插件(特定/全体对象)使用方法及源代码

2021-10-30 12:07 作者:Hildskjalf  | 我要投稿

插件原作者:joac1144 / Zyanthius [DK

https://forums.alliedmods.net/showthread.php?t=233971

食用方法:和其他插件一样,在安装了基础mod模块后把插件文件(后缀.SMx)移到某文件夹即可

游戏内使用示例(控制台输入):

SM_hp player1 200 //将玩家player1的血量设置为200

SM_hp @all 500 //将全体玩家的血量设置为500

SM_spawnhp player1 200 //玩家player1出生时的血量设置为200

SM_spawnhp @all 500 //全体玩家出生时的血量设置为500

编译前的插件.sp内容:

(这个网站可以在线编译.sp文件为.SMx):

https://www.sourcemod.net/compiler.php

#include <sourcemod>

#include <sdkhooks>

#include <sdktools>

#include <cstrike>


#pragma newdecls required


char spawnTarget[32];

char hp[32];

int spawnHealth[MAXPLAYERS+1];

bool spawnHealthOn[MAXPLAYERS+1];


public Plugin myinfo =

{

name = "Set Health",

author = "joac1144 / Zyanthius [DK]",

description = "Set players' health",

version = "2.0",

url = "https://forums.alliedmods.net/showthread.php?t=233971"

};


public void OnPluginStart()

{

LoadTranslations("common.phrases");

RegAdminCmd("SM_hp", Command_HP, ADMFLAG_SLAY, "Set players health");

RegAdminCmd("SM_spawnhp", Command_SpawnHP, ADMFLAG_SLAY, "Set health on spawn");

HookEvent("player_spawn", PlayerSpawn);

}


public Action Command_HP(int client, int args)

{

int health;


if (args < 2)

{

ReplyToCommand(client, "[SM] Usage: SM_hp <name or #userid> <hp>");

return Plugin_Handled;

}

char Target[64];

char cHP[32];

GetCmdArg(1, Target, sizeof(Target))

if (args >= 2 && GetCmdArg(2, cHP, sizeof(cHP)))

{

health = StringToInt(cHP);

}


char target_name[MAX_TARGET_LENGTH];

int target_list[MAXPLAYERS];

int target_count;

bool tn_is_ml;


if ((target_count = ProcessTargetString(

Target,

client,

target_list,

MAXPLAYERS,

COMMAND_FILTER_ALIVE,

target_name,

sizeof(target_name),

tn_is_ml)) <= 0)

{

ReplyToTargetError(client, target_count);

return Plugin_Handled;

}


for (int i = 0; i < target_count; i++)

{

if (health <= 0)

{

PrintToChat(client, "[SM] Please choose a higher value!");

return Plugin_Handled;

}

else

{

SetEntityHealth(target_list[i], health);

LogAction(client, target_list[i], "Admin %L set %L's health to %d.", client, target_list[i], health);

}

}


if (tn_is_ml)

{

ShowActivity2(client, "[SM] ", "Set %t health to %d.", target_name, health);

}

else

{

ShowActivity2(client, "[SM] ", "Set %s's health to %d.", target_name, health);

}


return Plugin_Handled;

}


public Action Command_SpawnHP(int client, int args)

{

/*

char spawnTarget[MAX_NAME_LENGTH];

int spawnHealth[MAXPLAYERS+1];

char hp[32];

bool spawnHealthOn[MAXPLAYERS+1];

*/

GetCmdArg(1, spawnTarget, sizeof(spawnTarget));

if (args < 2)

{

ReplyToCommand(client, "[SM] Usage: SM_spawnhp <name or #userid> <HP>");

return Plugin_Handled;

}

char target_name[MAX_TARGET_LENGTH];

int target_list[MAXPLAYERS];

int target_count;

bool tn_is_ml;

if ((target_count = ProcessTargetString(

spawnTarget,

client,

target_list,

MAXPLAYERS,

COMMAND_FILTER_ALIVE,

target_name,

sizeof(target_name),

tn_is_ml)) <= 0)

{

ReplyToTargetError(client, target_count);

return Plugin_Handled;

}

for (int i = 0; i < target_count; i++)

{

if (args >= 2 && GetCmdArg(2, hp, sizeof(hp)))

{

spawnHealth[target_list[i]] = StringToInt(hp);

}

if (spawnHealth[target_list[i]] <= 0)

{

ReplyToCommand(client, "[SM] Please choose a higher value!");

return Plugin_Handled;

}

else

{

spawnHealthOn[target_list[i]] = true;

LogAction(client, target_list[i], "Admin %L set %L to spawn with %d HP", client, target_list[i], spawnHealth[target_list[i]]);

}

}

if (tn_is_ml)

{

ShowActivity2(client, "[SM] ", "Set spawnhealth on %t", target_name);

}

else

{

ShowActivity2(client, "[SM] ", "Set spawnhealth on %s", target_name);

}


return Plugin_Handled;

}


public void PlayerSpawn(Event event, const char[] name, bool dontBroadcast)

{

int client = GetClientOfUserId(event.GetInt("userid"));

if (spawnHealthOn[client])

{

SetEntityHealth(client, spawnHealth[client]);

}

}








自定义血量插件(特定/全体对象)使用方法及源代码的评论 (共 条)

分享到微博请遵守国家法律