AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random const? (https://forums.alliedmods.net/showthread.php?t=46021)

Drak 10-16-2006 21:25

Random const?
 
I'm trying to get random consts to work
Code:
#include <amxmodx> plugin_init() {          register_plugin("Testing","Yeah","Blahblah") } // I set up my array new const name[4][] = {     "Name1",     "Name2",     "Name3",     "Name4" } public my_func(id) {       client_print(id,print_chat,"Random name: %s",name[random(0,3)]) }
But i keep getting this compile error:
'Error: Number of arguments does not match definition on line 142'

Oh and as for a side note, there's alot of different ways to set up a menu, what would be the most 'optimized' way?

Nostrodamous 10-16-2006 21:29

Re: Random const?
 
:D Ok well this time Im going to show everyone how to make a menu , and make it support multiple languges , and text from file . So first let me begin by saying , If you arnt famailar with amxmodx scripting read over my tutorials 1 and 2 before reading this one . Im going to asume you know the basices of the codeing .
Ok first like the rest of our scripts were going to make our includes . Menu are pretty much covered by amxmodx and misc . So no other modules are needed to make a menu .
Code:

#include <amxmodx>
#include <amxmisc>

So the next thing in our script is going to be our variables . Here were decalaring that these are the keys for the menu
Code:

new  keys  = MENU_KEY_0 | MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_6 | MENU_KEY_7 | MENU_KEY_8 | MENU_KEY_9
So next is the part where we always regiister the plugin . It has to be in every script , Its like the main() functon in C++ . It is included in every script .
Code:

public plugin_init()
 {
 register_plugin("mine" , "1.0" , "tutorial")
 register_menucmd(register_menuid("raps_menu") ,1023 , "next_menu")
 register_concmd("amx_menu" , "my_menu" , ADMIN_ALL , "Brings Up Menu")
 register_dictionary("my_file.txt")
}

Ok now let me go into detail about what we just registered . When you make a menu you have to register it in the plugin_init . So the first param is the menuid , then the name of the menu , then the keys , then the function that will be called after selcting from the menu . Then we have also registered a dictionary . This is the text file that we will be caling from later in the script . but in order to use it , and mulit lang support you need it . Also ,once again we registered a concmd , that the player will type in to make the menu show up . Next were making the function that shows the menu .
Code:

public my_menu(id)
{
 new menu[192] //this declares the menu and lenght used
 format(menu , 191 , "%L" , LANG_PLAYER , "HI")  //format of the menu
 show_menu(id, keys , menu , -1  , "my_menu")  // shows the menu
 return PLUGIN_CONTINUE
}

Ok so first we have to decalre that we are going to have something called menu, and that menu can contain 192 charachters . The format , menu , keys , and length ,have already been defined , length will alwaya be 1 less then what we declared .
%L Means we are calling to a Lang file (the dictioanry we registered earlier) , LANG_PLAYER meens were translating into the language of the current player . We could use the servers language which is LANG_SERVER . Next were calling "HI" , which is in the txt file . In the txt file youll see
Code:

[en]  //this meens english
HI = Hello^n How Are You ?^n1. Good^n2. Bad^n

So HI is what it found from file , and hi == whatever . So it will show what HI equals . ^ is a new line for the menu .
return PLUGIN_CONTINUE meens functions will keep going . The show menu function is what will actually make the menu display . id , keys and
menu are already defined . so next the -1 means that we wont specify a set time for the menu to be displayed .The the menu that will be dispayed . Next up is what happens when some one make a choice from the menu
Code:

public next_menu(id , key ) // this is the function called when a chioce is made last param from register_menucd
{
 if(key ==0) // option 1 "good"
 {
  client_print(id , print_chat , "%L" , LANG_PLAYER , "GOOD")
 }
 else  // switches the statemant
 {
  if(key == 1)// option 2  "bad"
  {
  client_print(id , print_chat , "%L" , LANG_PLAYER , "BAD")
  }
 }
 return PLUGIN_HANDLED
}

So here we did aa client print in the players language from the lnguage file , depending on what they selected .There are also a good amount of languages supported by amxmodx .
[en] = english
[es] = spanish
[de] = german
so on and so forth . for a full list , go and get your languages file from the amxmodx/data/lang folder . It has all the languages and symbols it supports . So here is our full code
Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
new  keys  = MENU_KEY_0 | MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_6 | MENU_KEY_7 | MENU_KEY_8 | MENU_KEY_9
 
public plugin_init()
 {
 register_plugin("Tutorial 3" , "1.0" , "Nas")
 register_menucmd(register_menuid("my_menu") ,1023 , "next_menu")
 register_concmd("amx_menu" , "my_menu" , ADMIN_ALL , "Brings Up Menu")
 register_dictionary("my_file.txt")
}
public my_menu(id)
{
 new menu[192]
 format(menu , 191 , "%L" , LANG_PLAYER , "HI")
 show_menu(id, keys , menu , -1  , "my_menu")
 return PLUGIN_CONTINUE
}
public next_menu(id , key )
{
 if(key ==0) // option 1
 {
  client_print(id , print_chat , "%L" , LANG_PLAYER , "GOOD")
 }
 else
 {
  if(key == 1)// option 2
  {
  client_print(id , print_chat , "%L" , LANG_PLAYER , "BAD")
  }
 }
 return PLUGIN_HANDLED
}

and here is our text file
Code:

[en]
HI = Hello^n How Are You ?^n1. Good^n Bad^n^n0: EXIT
GOOD = Im Glad To Hear it . Im Good also
BAD = Im Sorry To hear That .
[es]
HI = ¿hola cómo es usted?^n1. Buena^n2. Mala^n^n0 : SALIDA
GOOD = Im alegre oírlo. Im bueno también
BAD = Im apesadumbrado de oír eso

Notice i only did english and spanish support . But you can add mroe on your own . Hope this helps . Any questions just ask :D

teame06 10-16-2006 21:36

Re: Random const?
 
Code:
random(0, 3) //to random_num(0, 3)

Also you have

Code:
plugin_init() //where it suppose to be public plugin_init()

Drak 10-17-2006 20:38

Re: Random const?
 
Ah, thank you. Both of you.

bibu 02-14-2013 10:37

Re: Random const?
 
With the 'fixed version' of teame, I got sometimes an error (I don't know it right now).

Right now, I use the following code. It doesn't throw an error, but prints just some random letters from the array.

PHP Code:

new const Msgs[][] =
{
    
"Ultimate-Rampage-Ultrakill-Multikill-Megakill-Unstoppable!",
    
"Megakill-Unstoppable-Ultrakill",
    
"Unstoppable"
}

my_function(id)
{
    
client_print(idprint_chat"%s"Msgs[random(sizeof(Msgs))])




All times are GMT -4. The time now is 04:51.

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