Raised This Month: $ Target: $400
 0% 

Random const?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 10-16-2006 , 21:25   Random const?
Reply With Quote #1

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?
Drak is offline
Send a message via MSN to Drak
Nostrodamous
BANNED
Join Date: Oct 2006
Old 10-16-2006 , 21:29   Re: Random const?
Reply With Quote #2

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

Last edited by Nostrodamous; 10-16-2006 at 21:32.
Nostrodamous is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 10-16-2006 , 21:36   Re: Random const?
Reply With Quote #3

Code:
random(0, 3) //to random_num(0, 3)

Also you have

Code:
plugin_init() //where it suppose to be public plugin_init()
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
Drak
Veteran Member
Join Date: Jul 2005
Old 10-17-2006 , 20:38   Re: Random const?
Reply With Quote #4

Ah, thank you. Both of you.
Drak is offline
Send a message via MSN to Drak
bibu
Veteran Member
Join Date: Sep 2010
Old 02-14-2013 , 10:37   Re: Random const?
Reply With Quote #5

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))])

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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