- UID
- 1612448
- 主题
- 14
- 阅读权限
- 70
- 帖子
- 1160
- 精华
- 0
- 积分
- 663
- 金钱
- 3834
- 荣誉
- 8
- 人气
- 34
- 在线时间
- 601 小时
- 评议
- 0
- 帖子
- 1160
- 精华
- 0
- 积分
- 663
- 金钱
- 3834
- 荣誉
- 8
- 人气
- 34
- 评议
- 0
|
反正还有时间,我就拿我写的换地图的脚本讲解下
- #pragma semicolon 1
- #include <sourcemod>
- #define PLUGIN_VERSION "1.0.0"
- #define CVAR_FLAGS FCVAR_PLUGIN
- new Handle:voteTimeout; // 申明一个句柄
- new bool:inVoteTimeout[MAXPLAYERS+1]; //申明一个数据类型 关于bool 可以到这里了解下 [[url]http://baike.baidu.com/view/1557195.htm[/url]]
- public Plugin:myinfo =
- {
- name = "NewMap Change",
- author = "AlliedModders LLC",
- description = "BY WIND",
- version = PLUGIN_VERSION,
- url = "http://www.sourcemod.net/"
- };
- public OnPluginStart( )
- {
- RegConsoleCmd("sm_newmap",check, "changethemap"); // 注册控制台指令 sm_newmap ,因为在sourcemod中的core.cfg中 sm会被定义为!所以,基本上大家都是习惯性的挂上sm,这样游戏里面就可以输入!newmap了,当然也可以是!sm_newmap
- voteTimeout = CreateConVar("newmap_vote_timeout", "120", "玩家发起新地图切换投票需要间隔",CVAR_FLAGS,true,0.0); // 这里是刚才申明的句柄,这里要赋予它一个值.
- }
- public OnMapStart() //插件加载
- {
- for(new i=0;i<sizeof(inVoteTimeout);i++) // 一段循环, 因为前面已经MAXPLAYERS+1过了,所以这里 按照理解应该是 new i=0;i<maxclient();i++) 分别返回false值,
- inVoteTimeout[i]=false;
- }
- public OnClientConnected(client) //当玩家连接成功后
- {
- inVoteTimeout[client]=false; //赋予玩家false
- }
- public isInVoteTimeout(client)
- {
- if (GetConVarBool(voteTimeout)) // 如果为真
- {
- return inVoteTimeout[client]; //返回inVoteTimeout
- }
- return false; //返回
- }
- public Action:TimeOutOver(Handle:timer, any:client) //时钟
- {
- inVoteTimeout[client] = false; //设置为初始值
- }
- public Action:check(client, args)
- {
- if(GetConVarInt(FindConVar("sv_hosting_lobby")) == 1) // 这里是检测是否为大厅服务器
- {
- ReplyToCommand(client, "\x01[SM] Server was started from lobby. can change map because mp_gamemode is locked\x03");
- return Plugin_Handled;
- }
-
- if(GetClientTeam(client) != 2) //判断是否为幸存者团队 1=怪物 3=空闲玩家
- {
- PrintToChat(client, "\x04[SM] \x01 你没有权限使用该功能.");
- return Plugin_Handled;
- }
-
- if (isInVoteTimeout(client)) //如果为真isInVoteTimeout(client)) =true
- {
- PrintToChat(client, "\x04[SM] \x01你必须要等待 %.1f 秒才可以再次发起切换地图投票.",GetConVarFloat(voteTimeout)); //则提示你需要等待多少秒后才可以继续投票.
- return Plugin_Handled;
- }
-
- inVoteTimeout[client]=true; // 不满足以上的判断则说明该玩家没有发表过投票,则现在给予他true的值,当下次再循环到的时候则会提示判断true,不再进行下面的操作
- new Float:timeout = GetConVarFloat(voteTimeout); //定义一个浮点型数据类timeout,他的值从voteTimeout中获得,参见 Onplugins
- if (timeout > 0.0) //如果时间>0,这里仅作为一个开关使用,如果我们在上面的onplugins中设置为0,这里的判断就会失效,那么一个人投票一次后就无法再输入!newmap来进行投票了.因为他们的值被给予了true而不会还原
- {
- CreateTimer(timeout, TimeOutOver, client); //创建一个时钟,附带参数client
- }
-
- newmap(client, args); // 执行子程序
- return Plugin_Handled;
- }
- public Action:newmap(client, args)
- {
- new Handle:menu = CreateMenu(ModeMenuHandler); //申请menu,创建菜单ModeMenuHandler
-
- SetMenuTitle(menu, "地图切换"); // 标题
- AddMenuItem(menu, "option1", "地图切换"); //创建菜单
- AddMenuItem(menu, "option2", "帮助说明");
- SetMenuExitButton(menu, true); // 能够看见关闭按钮
-
- DisplayMenu(menu, client, MENU_TIME_FOREVER); //永久显示菜单,直到用户操作
- }
- public ModeMenuHandler(Handle:menu, MenuAction:action, client, itemNum) //因为上面的操作都是针对menu(CreateMenu(ModeMenuHandler); ) 所以就跳到这里了
- {
- if ( action == MenuAction_Select ) // 判断操作选择
- {
- switch (itemNum)
- {
- case 0: // changemap
- {
- MapMenuVote(client, 0); // 调用子程序
- }
- case 1: // help
- {
- PrintToChat(client,"\x01[SM] 如果发现无法按下5,6,7,8,9,0键,请在控制台输入 bind 5 slot5; bind 6 slot6; bind 7 slot7; bind 8 slot8; bind 9 slot9; bind 0 slot10\x03");
- }
- }
- }
- }
- public Action:MapMenuVote(client, args)
- {
- new Handle:menu = CreateMenu(MapMenuVoteHandler); // 又创建了一个新的menu
-
- SetMenuTitle(menu, "请投票选择地图");
- AddMenuItem(menu, "option1", "保持当前地图");
- AddMenuItem(menu, "option2", "停尸间惊魂");
- AddMenuItem(menu, "option3", "死亡电站");
- AddMenuItem(menu, "option4", "血腥之城");
- AddMenuItem(menu, "option5", "监狱惊魂");
- SetMenuExitButton(menu, false);
-
- VoteMenuToAll(menu, 20); //调出投票,20秒后自动消失,这些都是API,所以很简单的就能完成了,而真正的C语言就不会那么容易了.
-
- return Plugin_Handled;
- }
- public MapMenuHandler(Handle:menu, MenuAction:action, client, itemNum)
- {
- if ( action == MenuAction_Select )
- {
- switch (itemNum)
- {
- case 0:
- {
- PrintToChatAll("[SM:] 投票失败,当前地图不会变更."); //选择1为保持当前投票,所以自然要给别人一点提示
- return; // 跳出
- }
- case 1:
- {
- ServerCommand("changelevel l4d_mortuary01"); //执行服务器指令
- }
- case 2:
- {
- ServerCommand("changelevel l4d_powerstation_utg_01");
- }
- case 3:
- {
- ServerCommand("changelevel l4d_deadcity01_riverside");
- }
- case 4:
- {
- ServerCommand("changelevel l4d_deathaboard01_prison");
- }
- }
- }
- }
- public MapMenuVoteHandler(Handle:menu, MenuAction:action, param1, param2)
- {
- if (action == MenuAction_End) //如果20秒不进行操作则
- {
- CloseHandle(menu); //关闭菜单
- }
- else if (action == MenuAction_VoteEnd) //如果投票结束后
- {
- MapMenuHandler(menu, MenuAction_Select, 0, param1); //调用子程序
- }
- }
复制代码
很多不明白的,可以到顶帖中的网址去查阅了,好了去睡觉了.. |
|