Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BB Human classes (Extension for Base Builder Zombie mod)
- 1.0
- Prince (rewrite: Mega)
- Api:
- natives:
- bb_is_user_zombie(client)
- @return - if zombie -> true, else -> false
- bb_get_user_class(client)
- @return - player human class
- bb_set_user_class(client, class)
- - forcefully sets player's new class
- @return - -1 on disconnected player, 0 on success
- bb_register_hclass(const cName[], const cDesc[], const cMenuName[], iClassFlag)
- cName - Class name which will be printed in chat after successful class selection
- cDesc - Class description which will be shown in class menu
- cMenuName - Class name which will be shown in class menu
- iClassFlag - Class access flag (you can use any of existing Amxmodx flags, eg. ADMIN_ALL - everyone has access, ADMIN_LEVEL_H - access is restricted to "t" flag)
- @return - On success, returns new class ID, on failure, returns -1
- forwards:
- bb_human_spawned(client, class)
- gets called when human is spawned.
- bb_player_hclass_changed(client, class)
- gets called when human changes class(if no class is selected, it gets called immediately after class selection, otherwise, it gets called on next player spawn)
- bb_player_selected_class(client, class)
- gets called when player selects the class from the menu (it can be blocked if you return 0 or less in that event!)
- */
- #include <amxmodx>
- #include <hamsandwich>
- #include <colorchat>
- enum _:FORWARD_LIST {
- PLAYER_SPAWNED = 0,
- PLAYER_CHANGED_CLASS,
- PLAYER_SELECTED_CLASS
- }
- new bbforwards[FORWARD_LIST], gDummyRes
- new const bbforwards_names[FORWARD_LIST][] = {
- "bb_human_spawned",
- "bb_player_hclass_changed",
- "bb_player_selected_hclass"
- }
- new const bbnatives[][][] = {
- { "bb_is_user_zombie", "native_is_user_zombie" },
- { "bb_get_user_hclass", "native_get_user_hclass" },
- { "bb_set_user_hclass", "native_set_user_hclass" },
- { "bb_register_hclass", "native_register_hclass" }
- }
- new iRegisteredClasses = 0, bool:bArraysAreSet = false;
- new Array:className, Array:classDesc, Array:classMenuName, Array:classFlags
- new playerclass[33], newclass[33]
- public plugin_init() {
- register_plugin("BB Human Classes", "1.0", "Prince (rewrite: Mega)")
- RegisterHam(Ham_Spawn, "player", "fwPlayerSpawnPost", 1)
- SetUpArrays()
- for(new i = 0; i < sizeof(bbforwards_names); i++) bbforwards[i] = CreateMultiForward(bbforwards_names[i], ET_CONTINUE, FP_CELL, FP_CELL)
- native_register_hclass("No class", "", "No class", ADMIN_ALL)
- register_clcmd("say /hclass", "CmdHClass")
- }
- public fwPlayerSpawnPost(id) {
- if(!is_user_alive(id) || native_is_user_zombie(id)) return HAM_IGNORED
- if(newclass[id] > -1) {
- playerclass[id] = newclass[id]
- newclass[id] = -1
- ExecuteForward(bbforwards[PLAYER_CHANGED_CLASS], gDummyRes, id, playerclass[id])
- }
- ExecuteForward(bbforwards[PLAYER_SPAWNED], gDummyRes, id, playerclass[id])
- return HAM_IGNORED
- }
- public CmdHClass(id) {
- if(native_is_user_zombie(id)) return
- new sClassName[32], sClassDesc[48], sMenuItem[96], menu = menu_create("Human classes: ", "CmdHClass_Handler")
- for(new i = 0; i < iRegisteredClasses; i++) {
- ArrayGetString(classMenuName, i, sClassName, charsmax(sClassName))
- ArrayGetString(classDesc, i, sClassDesc, charsmax(sClassName))
- formatex(sMenuItem, charsmax(sMenuItem), "%s %s", sClassName, sClassDesc)
- menu_additem(menu, sMenuItem)
- }
- menu_display(id, menu)
- }
- public CmdHClass_Handler(id, menu, item) {
- if(item == MENU_EXIT || native_is_user_zombie(id)) {
- menu_destroy(menu)
- return PLUGIN_CONTINUE
- }
- new iClass = item+1, cName[32]
- new iFlags = ArrayGetCell(classFlags, iClass)
- ExecuteForward(bbforwards[PLAYER_SELECTED_CLASS], gDummyRes, id, iClass)
- if(gDummyRes < 1 || iClass == playerclass[id]) return PLUGIN_HANDLED
- if(!(get_user_flags(id) & iFlags)) {
- ColorChat(id, TEAM_COLOR, "[Human Classes]^x01 You don't have access to that class!")
- return PLUGIN_HANDLED
- }
- if(playerclass[id] > 0) {
- newclass[id] = iClass
- ColorChat(id, TEAM_COLOR, "[Human Classes]^x01 Class will be changed after your next spawn.")
- } else {
- playerclass[id] = iClass
- ArrayGetString(className, iClass, cName, charsmax(cName))
- ColorChat(id, TEAM_COLOR, "[Human Classes]^x01 You've successfully selected^x04 %s^x01 class.", cName)
- ExecuteForward(bbforwards[PLAYER_CHANGED_CLASS], gDummyRes, id, iClass)
- }
- return PLUGIN_CONTINUE
- }
- public SetUpArrays() {
- className = ArrayCreate(32, 1)
- classDesc = ArrayCreate(48, 1)
- classMenuName = ArrayCreate(32, 1)
- classFlags = ArrayCreate(1, 1)
- bArraysAreSet = true
- }
- public native_is_user_zombie(id) {
- if(!is_user_connected(id)) return -1
- return (get_user_team(id) == 1?true:false)
- }
- public native_get_user_class(id) {
- if(!is_user_connected(id)) return -1
- return playerclass[id]
- }
- public native_set_user_class(id, iClass) {
- if(!is_user_connected(id)) return -1
- if(playerclass[id] > 0) {
- newclass[id] = iClass
- ColorChat(id, TEAM_COLOR, "[Human Classes]^x01 Class will be changed after you spawn as a human again.")
- } else {
- playerclass[id] = iClass
- ExecuteForward(bbforwards[PLAYER_CHANGED_CLASS], gDummyRes, id, iClass)
- }
- return 0;
- }
- public native_register_hclass(const cName[], const cDesc[], const cMenuName[], iClassFlag) {
- param_convert(1)
- param_convert(2)
- param_convert(3)
- if(strlen(cName) < 3 || strlen(cMenuName) < 3 || !bArraysAreSet) return -1
- ArrayPushString(className, cName)
- ArrayPushString(classDesc, cDesc)
- ArrayPushString(classMenuName, cMenuName)
- ArrayPushCell(classFlags, iClassFlag)
- iRegisteredClasses++
- return iRegisteredClasses-1
- }
- public client_putinserver(id) {
- playerclass[id] = 0
- newclass[id] = -1
- }
- public plugin_natives() {
- for(new i = 0; i < sizeof(bbnatives); i++) register_native(bbnatives[i][0], bbnatives[i][1])
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement