AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   AMXX Mod begginer problem. (https://forums.alliedmods.net/showthread.php?t=12176)

wnn 04-07-2005 05:32

AMXX Mod begginer problem.
 
Hey, I've been learning PASCAL for the last three years, and I decided it's about time I'll made some plugins I've always wanted to see for the HL-Engine.

So, i read almost all of the doc on the site, and started scripting.

I ran into a problem with the menu tutorial, infact not a problem, I just don't understand some of the code there. Let me show you what i mean..

(The link if you want to take a look at the whoel tutorial:
http://www.amxmodx.org/doc/source/sc...nced.htm#menus )

Code:

//The clcmd function will just give us the player id
public showWeaponMenu(id)
{
    new menu[192]
    new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2

    format(menu, 191, "Which Weapon?^n^n1. AK47^n2. M4A1^n3. AWP")
    show_menu(id, keys, menu)
    return PLUGIN_HANDLED
}

//Our menu function will get the player id and the key they pressed
public giveWeapon(id, key)
{
    //key will start at zero
    if (key == 0)
    {
        give_item(id, "weapon_ak47")
    } else if (key == 1) {
        give_item(id, "weapon_m4a1")
    } else if (key == 2) {
        give_item(id, "weapon_awp")
    }
}

Ok, so the tutorial has this bit of code in it, and i just want to clearify some things.

new menu[192]: What does this Variable do ? Why 192 ? It wasn't explained in the tutorial.

format(menu, 191, "Which Weapon?^n^n1. AK47^n2. M4A1^n3. AWP"): menu, and 191, why ? What does menu do here ? Why 191 ?
And I'd be glad if you could explain the whole format function for me, however that's not very important.

show_menu(id, keys, menu): Why does he call that function ? I see it nowhere in the program, if it's a core function (probably is) care to explain what "menu" has to do with it ?

public giveWeapon(id, key): How is it called ? I see it called nowhere.. And if its called and i somehow missed that, how does it get its id and key ?

Thanks alot,

wnn.

wnn 04-07-2005 05:48

I couldn't seem to edit my post, sorry for double posting.

I realised my first two questions (oh boy i feel dumb ;) ):

Quote:

new menu[192]: What does this Variable do ? Why 192 ? It wasn't explained in the tutorial.

format(menu, 191, "Which Weapon?^n^n1. AK47^n2. M4A1^n3. AWP"): menu, and 191, why ? What does menu do here ? Why 191 ?
And I'd be glad if you could explain the whole format function for me, however that's not very important.
About the other two - I'd be glad if you could help.

Edit: I seem to be able to edit now..

PM 04-07-2005 07:00

show_menu(id, keys, menu)
Actually shows the menu. id is the id of the player. keys is a bitmask of the keys he can press. menu is the menu body, which the plugin has constructed in the format() line.

I'd bet that in public plugin_init(), the plugin uses a register_menu command and passes
"giveWeapon" as one of the parameter. As the menu body he passes to show_menu contains the other parameter the author gave register_menu, that function will be called when the player presses a key.


All times are GMT -4. The time now is 09:52.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.