Roulette
You searched for roulette many times, but couldn`t find good one?
You found one, but you don`t like it`s configuration? You configured code,
but roulette ended bad? Players was stucking in wall? Lose money, don`t having them?
Bomb disappeared from the map, so players couldn`t do map objectives? Or editing your roulette`s
source code with tens of thousands of lines beyond you and you feel a lot of discomfort in the editing?
It`s time for Benio`s roulette!
Now, every prize in your roulette, is a separate plugin.
Pleasant API allows to edit prizes with a comprehensive and clear way.
You can configure your roulette as you wanna, setting roulette and prize`s cvars,
and the installation of every new prize needs the installation of a new prize`s plugin only.
Creating and adding your own prizes will not make you any problem.
No! for repetitive prizes
You can forget about drawning same awards still and still, thanks
advanced system of avoiding drawn the same prize in short period of time.
No! for pointless prizes
You will not get any more prizes, which will not have an effect, as a loosing money,
which you do not have, thanks of the set requirements in SMA for individual awards.
Greater opportunities for selected awards
Each prize may have its own power, that means the
product of chance to the drawn towards other prizes.
Karma system
Continuous receive good or bad karma prizes will cause drawning prize
with invert karma. End of drawning always bad or always good prizes.
Description
Roulette is a plugin that allows you to get random prize, when you type
/roulette
The commands that activate roulette, are placed in the file
amxmodx/configs/roulette_keywords.ini
In each line, place a single command, the semicolon at the beginning of the line, will disable the command.
Commands will work both directly typed in the console, as well as prescribed, or preceded by a slash
on say or team_say.
Piece of cake
In order to facilitate editing and comprehensive management capabilities prizes,
each prize is written as a separate plugin, commonly called as
roulette_prize_name.amxx
Multitasking
Each player can use the roulette maximum once per round.
A lot of players can play simultaneously, drawning prize`s at same time.
(No) Payable Roulette
Setting cvar
roulette_prize to positive value
will make playing roulette payable, so the price (in dollars) sets this cvar.
Developer Prizes Menu
Roulette automatically adds to game administration menu (amxmodmenu), Menu "Roulette".
The menu allows you to test new prizes on your server. Simply select the desired prize
and you will force the prize to affect on you, without paying or checking requirements.
When we do not live, or we`re watching the game as observers, calling
the prize from menu will take action on player that we`re currently watching.
CVARs
PHP Code:
roulette_prize 1000 // <0|prize> prize of playing roulette (in dollars). Set this to 0 to make roulette free.
roulette_ban 20 // <0|number> number of nearest drawnings, drawned prize won`t be drawned again.
roulette_sv_speed 1 // <0|1> if set to 1, will set cvar sv_maxspeed to 1000, allowing speed buffs to take results
roulette_cl_speed 1 // <0|1> if set to 1, will set player`s speed cvars will be se to 1000, allowing speed buffs to take results
roulette_karma 250 // <-1|number> karma limit, exceed wchich will result in drawning invert karma`s prize. -1 turn off karma system
Require modules
PHP Code:
amxmodx
amxmisc
celltrie
colorchat
cstrike
fakemeta
hamsandwich
tutor
Other informations
Author:
- Paweł "benio101" Benetkiewicz
Credits:
- ConnorMcLeod
for get_remaining_seconds native, I merged it into Roulette
- DarkGL
for tutor system with natives. I precache and use it by default
- Harsay
for reporting detailed descripted bugs in source code
- sebul
for get_origin_from_dist_player stock, I use in some prizes
- speedkill
for many useful advices, which saved a lot of time to finish project
Developer informations
Description for developers, howto create new / edit prizes for roulette
Main roulette files
roulette.sma
roulette.inc
Creating new prize
In
plugin_init function, register new prize with
register_prize native.
PHP Code:
/*
Registers new prize, native must be placed in plugin_init function
desc - short description for developer menu. Limit: 100 characters
karma - how good is prize
positive value for favorable prizes
negative value for unfavorable prizes
0 for neutral or hard to assess prizes
pwr - the product of chance on the prize drawn, recommended value: POWER
key - translates key if set to true or just register prize with given name
Returns registered prize id. Prize ids begins from 0
*/
native register_prize(desc[200], pwr=POWER, karma=0, bool:key=true);
In 1st argument, pass prize`s name, in second, their power.
Description of prizes will be displayed in the developer menu.
Prize power determines the chance of the prize to drawn.
Finally, of all the prizes that meet the requirements to become drawned,
drawning will be held by the weighted method, ie each prize will receive x% chance to be drawned,
where x is equal to the quotient of this prize and the sum of all available prizes powers.
PHP Code:
/*
draw power =7!, for example, prize with 3× less chance to get out from draw,
we register with power: POWER/3: register_prize("prize name", POWER/3);
*/
#define POWER 5040
The third argument is the karma that determines how good is the prize.
For neutral prizes or difficult to assess, karma should be set to 0.
For prizes of positive or negative value should be added accordingly.
It is recommended that the karma values are given in the range of -100 to 100.
For easy editing, there are created some definitions for the karma level:
PHP Code:
// some predefines karma levels for prizes
#define KARMA_WORST "-100"
#define KARMA_VERY_BAD "-75"
#define KARMA_BAD "-50"
#define KARMA_QUITE_BAD "-25"
#define KARMA_MINUS "-1"
#define KARMA_NEUTRAL "0"
#define KARMA_PLUS "1"
#define KARMA_QUITE_GOOD "25"
#define KARMA_GOOD "50"
#define KARMA_VERY_GOOD "75"
#define KARMA_BEST "100"
Prize requirements
To the prize`s code, we have to add
check_prize forward as public function.
PHP Code:
/*
Ask for ability to draw the prize for a given player
id - number of player to draw the prize
Returning ROULETTE_ALLOW allows for draw the prize
Returning ROULETTE_BLOCK disallows for draw the prize
*/
forward check_prize(id);
We do return one of these values:
PHP Code:
enum{
ROULETTE_BLOCK, // Blocks forward execute or disallow for executing
ROULETTE_ALLOW // Executes the forward or allow for executing
}
If we want prize to be always available, just write simple
PHP Code:
public check_prize(id){
return ROULETTE_ALLOW;
}
Anyway, we can limit the prize, fe. for the terrorists only
PHP Code:
public check_prize(id){
return get_user_team(id)==1?ROULETTE_ALLOW:ROULETTE_BLOCK;
}
Forward can be executed only, when somebody plays roulette,
so we can assume that minimum one player is alive.
Allow for power reset
To prize`s code, we add the
power_reset forward too, which returns one of
ROULETTE_ALLOW or
ROULETTE_BLOCK values.
Returning
ROULETTE_ALLOW will allow to reset prize`s power when all prizes are unavailable or while ban set by
roulette_ban cvar,
ROULETTE_BLOCK disallowes forcing prize`s power to reset, useful if we wanna hard limit prize to be drawned only once per map.
PHP Code:
/*
Ask for change prize`s power
id - number of player to reset the power
Returning ROULETTE_ALLOW allows for prize`s power reset
Returning ROULETTE_BLOCK disallows for prize`s power reset
*/
forward power_reset(id);
Like
check_prize forward, be can assume that minimum one player is alive.
Executing prize
We have to add forward
execute_prize to our code, which is called when some player drawned whis prize.
It gets one and only argument, the id of player to exeture the prize to (1-32).
Forward is executed for alive players, so checking if player is alive is redundant.
PHP Code:
/*
Executes prize by given player
id - number of player wchich drew the prize
*/
forward execute_prize(id);
Change prize power
With
change_prize_power native, we can change prize`s power for given player.
PHP Code:
/*
Forces prize power change
id - number of player, which power is changed
if set to 0, power is changed for all players
pwr - new power to set
Returns old player`s prize power or -1 if id is 0
*/
native change_prize_power(id=0, pwr=0);
Option is useful to limit playing roulette for given player and to manipulate power in some cases, or to implement system,
decreasing chances after every drawn, or blocking prize for player after some events, excluding prize from being drawned out.
Change player`s karma
Sometimes, the exact karma of prizes will be possible to determine only after certain operations,
for example, drawn amount added life. Then, it`s good to use native, adding the karma to the player.
However, it`s important to set the initial value of karma positive for positive prizes or negative for the negative prizes.
PHP Code:
/*
Sets user karma level
id - number of player to set new karma
if set to 0, karma is set to all players
karma - new karma to set
Returns old player`s karma or -1 if id is 0
*/
native set_user_karma(id=0, karma=0);
PHP Code:
/*
Gets user karma level
id - number of player to get karma
*/
native get_user_karma(id);
Change prize karma
It`s possible to change prize`s karma too.
PHP Code:
/*
Changes prize`s karma
karma - new karma to set
Returns prize`s old karma
*/
native change_prize_karma(karma=0);
Time to the end of round
Useful native, returning time to the end of round.
Most useful to determine if the prize is available.
PHP Code:
/*
Gets time to end of round in seconds
*/
native timeleft();
Multilang
Roulette is multilang at all.
It`s implemented custom structure of celltrie`s dictionary.
PHP Code:
/*
Registers new dictionary of keys to translate
file - dictionary`s filename placed in data/lang
*/
native register_translate(file[128]);
PHP Code:
/*
Translates key registered by register_translate
id - number of player to translate key for
key - the key to translate
result - the output for translated key
*/
native translate(id, key[128], result[896]);
All arguments of translating keys deals to this celltrie`s dictionary.
Simple informations
In order to simply inform the player and his watchers about the drawned prize
and its course, It has been created native
prize_info, which takes a lot of arguments:
PHP Code:
/*
Shows information of drawed message to winner and his spectators
id - number of player to show the information
color - color of the message to show.
Available colors to choose:
YELLOW, GREEN, RED, BLUE
key - translates key if set to true or just shows given message
msg - message to show for a player. Limit of 190 characters
msgSpec - message to show for player`s spectators. Same limit.
channel - binary sum of channels message to show
1 - ColorChat
2 - Tutor
4 - Center
time - how long the tutor message have to lasts (float value)
*/
native prize_info(id, color=INFO_YELLOW, msg[190]="", msgSpec[190]="", bool:key=true, channel=3, Float:time=10.0);
PHP Code:
enum(<<=1){ // Message channels used in prize_info native
MSG_COLORCHAT=1,
MSG_TUTOR,
MSG_CENTER
}
PHP Code:
enum{ // Colors are projected to be compatible with ColorChat
INFO_YELLOW=1, // Yellow color has been added to make names more sense
INFO_GREEN,
INFO_RED=5,
INFO_BLUE
}
Note, that tutor is restricted to work on CS:CZ only due to satisfy YamiKaitou.
Simple countdowns
Not only inforations on say / tutor are useful.
It`s ready the native to simple countdown.
PHP Code:
/*
Shows counter centered information to winner and his spectators
Uses client_print print_center in format: "translated_key: number"
id - number of player to show the counter
key - the key to translate, being the prize name
number - number to show (f.e. seconds left, HP left, etc.)
spect - specifies, if show counter to spectators too.
*/
native prize_counter(id, key[128], number, bool:spect=true);
Prize template
PHP Code:
#include <amxmodx>
#include <roulette>
public plugin_init(){
register_plugin("Roulette Prize name", "0.1", "Prize Author");
register_prize("Prize name: Short prize description");
}
public execute_prize(id){
}
public check_prize(id){
return ROULETTE_ALLOW;
}
public power_reset(id){
return ROULETTE_ALLOW;
}
FCVAR_SHOWALL flag
To easier register cvars with flags that shows and notes changing values, it has been added definition:
PHP Code:
// defines cvar bitsum value, showing cvar`s existing and every change
#define FCVAR_SHOWALL FCVAR_ARCHIVE|FCVAR_SERVER
Global soft limitation
By default, roulette plugin limits drawning same prize
for same player in close interval of plays, by default,
same prize can be drawned after draws 20 other prizes.
The exception is when no one prize is available to draw
out. Then, it starts the try of reseting prize`s powers.
Template of soft global limitation for rounds set by
roulette_prize_name_rounds_ban cvar with default value of 20.
PHP Code:
#include <amxmodx>
#include <roulette>
new ban=0, c_rounds_ban;
public plugin_init(){
register_plugin("Roulette Prize name", "0.1", "Prize Author");
register_prize("Prize name: Short prize description");
register_logevent("roundStart", 2, "1=Round_Start");
c_rounds_ban=register_cvar("roulette_prize_name_rounds_ban", "20", FCVAR_SHOWALL);
}
public execute_prize(id){
change_prize_power(id, 0);
ban=get_pcvar_num(c_rounds_ban);
}
public roundStart(){
if(ban){
--ban;
}
}
public check_prize(id){
return ban?ROULETTE_BLOCK:ROULETTE_ALLOW;
}
public power_reset(id){
return ROULETTE_ALLOW;
}
Global hard limitation
Hard limitation`s diffrent is that prize power reset will be blocked,
returning
ROULETTE_BLOCK inside
power_reset forward.
PHP Code:
enum{
ROULETTE_BLOCK, // Blocks forward execute or disallow for executing
ROULETTE_ALLOW // Executes the forward or allow for executing
}
Similary, we can change default amount of limitations for custom players.
Creating time based function
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <roulette>
new maxPlayers, prize[33];
public plugin_init(){
register_plugin("Roulette Prize name", "0.1", "Prize Author");
register_prize("Prize name: Short prize description");
register_logevent("roundEnd", 2, "1=Round_End");
register_logevent("roundEnd", 2, "1=Game_Commencing");
RegisterHam(Ham_Killed, "player", "killed", 1);
}
public plugin_cfg(){
maxPlayers=get_maxplayers();
}
public execute_prize(id){
prize[id]=20;
new data[1];
data[0]=id;
set_task(1.0, "timer", _, data, 1, "a", prize[id]);
}
public timer(data[]){
new id=data[0];
if(is_user_alive(id) && prize[id]){
if(--prize[id]){
// tutaj wykonujemy kod co sekunde, dla dodatniego licznika czasu
} else {
// licznik czasu wlasnie dobiegl zera, wykonujemy pewien, inny kod
}
}
}
public killed(vid, kid, shouldgib){
if(prize[vid]){
prize[vid]=0;
}
}
public client_putinserver(id){
prize[id]=0;
}
public roundEnd(){
remove_task();
for(new i=1; i<=maxPlayers; ++i){
prize[i]=0;
}
}
public check_prize(id){
return ROULETTE_ALLOW;
}
public power_reset(id){
return ROULETTE_ALLOW;
}
We have created global variable
prize[
33], storing time counter for players.
Counter gets some value when player draws the prize (
execute_prize) and creates
task for this player, which will be executed every secons. In example, time is set to 20 seconds.
Next, every second, it`ll be executed function
timer, inside which we have to
check if player is alive and have timer, so have active prize. Here, we decredent the time and place proper code.
End of prize can occur, in standard, at 3 methods:
- End of time (counter reached 0 value)
- Player kill (thats the reason of killed function
- End of round (roundEnd function)
In
roundEnd function we will add the instruction, removing all existings tasks.
It is important to consider all listed possibles of prize end.
After end of prize, we can also return player to normal if
we operated on him hard, for example, give him a knife back.
Countdown function with counter
Now, we will add functional counter to our time based function, so practic base.
We will use random time too, limited by values of two cvars.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <roulette>
new maxPlayers, prize[33];
new c_prize_min, c_prize_max;
public plugin_init(){
register_plugin("Roulette Prize name", "0.1", "Prize Author");
register_prize("Prize name: Short prize description");
register_logevent("roundEnd", 2, "1=Round_End");
register_logevent("roundEnd", 2, "1=Game_Commencing");
RegisterHam(Ham_Killed, "player", "killed", 1);
c_prize_min=register_cvar("c_prize_name_min", "10", FCVAR_SHOWALL);
c_prize_max=register_cvar("c_prize_name_max", "20", FCVAR_SHOWALL);
}
public plugin_cfg(){
maxPlayers=get_maxplayers();
}
public execute_prize(id){
// gracz o numerze id wylosowal nagrode
// tutaj wykonujemy operacje tuz po wylosowaniu nagrody
prize[id]=random_num(get_pcvar_num(c_prize_min), get_pcvar_num(c_prize_max));
prize_info(id, INFO_BLUE, "PRIZE_NAME_DESC", "PRIZE_NAME_DESC_SPEC");
prize_counter(id, "PRIZE_NAME", prize[id]);
new data[1];
data[0]=id;
set_task(1.0, "timer", _, data, 1, "a", prize[id]);
}
public timer(data[]){
new id=data[0];
if(is_user_alive(id) && prize[id]){
if(--prize[id]){
// tutaj wykonujemy kod co sekunde, dla dodatniego licznika czasu
prize_counter(id, "PRIZE_NAME", prize[id]);
} else {
// licznik czasu wlasnie dobiegl zera, wykonujemy pewien, inny kod
prize_info(id, .key=false, .channel=MSG_CENTER);
}
}
}
public killed(vid, kid, shouldgib){
if(prize[vid]){
prize[vid]=0;
}
}
public client_putinserver(id){
prize[id]=0;
}
public roundEnd(){
remove_task();
for(new i=1; i<=maxPlayers; ++i){
prize[i]=0;
}
}
public check_prize(id){
return ROULETTE_ALLOW;
}
public power_reset(id){
return ROULETTE_ALLOW;
}
When player will drawn the prize, we will write out information on say and in tutor
for him and all his spectators. In additional, it is showed counter at the centre of
screen. In example, it is used red color, usually means bad prize, anyway, color
inceptions are individual for prize author, anyway, is is recommended to use
green color for good prizes, red for bad prizes and blue for neutral / informations.
File tutor.inc is neccessary to copy to
scripting/include to be able to compile roulette plugin.
Using tutor is restricted to work on CS:CZ only due to satisfy YamiKaitou.
tutor.inc
Also, in many plugins, it`s used stock
StripWeapons,
which allows player to loose chosen weapons or wepon type.
stripweapons.inc
Player soft limit
After getting prize, we execute on player
PHP Code:
change_prize_power(id, 0);
Thanks that, player won`t draw this prize
until the end of map of prize power`s reset.
Changelog
HTML Code:
24.12.2012 1.0 N Init version
28.12.2012 2.0 + Added custom configuration files. Plugin is fully plug & play now
03.01.2013 2.1 $ Fixed incorrect plugin native change prize power call
04.01.2013 2.2 + Added cutom map`s custom configuration files settings service
08.01.2013 3.0 % Improved memory usage, replacing stable tables with the cellarray
11.01.2013 3.1 $ Fixed the ArrayGetArray incorect identifier usage
13.01.2013 4.0 + Added multilanguage service, changed main plugin language to english
13.01.2013 4.0.1 $ Changed variables names and comments to english
13.01.2013 4.0.2 $ Fixed null sized array initialize while no prizes
13.01.2013 4.1 % Improved menu show while no prizes
13.01.2013 4.2 $ No more searching for winning prize`s execute forward id twice
28.01.2013 5.0 % Merged ConnorMcLeod`s get_remaining_seconds and Roulette
28.01.2013 5.0.1 + Added timeleft native
29.01.2013 5.1 + Added register_translate and translate natives
30.01.2013 5.1.1 $ Fixed translations for tutor
30.01.2013 5.2 + Added prize_info native
30.01.2013 5.3 $ Added register_prize multilang support
30.01.2013 5.3.1 % Improved some comparisons usage
30.01.2013 5.3.2 $ Fixed infinity loop bug when prize`s default power is 0
01.02.2013 6.0 + Added karma system
02.02.2013 6.0.1 % Improved some natives returns
02.02.2013 6.1 + Added change_prize_karma, set_user_karma and get_user_karma natives
03.02.2013 6.1.1 % Improved some natives parameters and variables usage
03.02.2013 6.1.2 + Added source code sections and some comments blocks
04.02.2013 6.1.3 + Added KARMA_* defines in INC file
04.02.2013 6.1.4 + Added POWER_STR, allowing use it directly in prize`s power cvars
04.02.2013 6.2 % Reduced POWER(_STR) to 7! to avoid integer overflow more effectively
04.02.2013 6.2.1 + Added FCVAR_SHOWALL definition to simplify registering some cvars
05.02.2013 6.2.2 $ Fixed translate native not returning translated string
05.02.2013 6.2.3 + Added credits informations in info section of SMA file
05.02.2013 6.3 + Added prize_counter native to simplify showing counters
06.02.2013 6.3.1 % Moved descriptions in INC file over the content to cooperate with editors
05.03.2013 6.3.2 % Changed array of booleand into bitsum, added bitsum defines
07.03.2013 6.3.2.1 - Removed tutor on CS other than CS:CZ to satisfy YamiKaitou
Download
roulette.zip
Optional files to put for fastDL:
fastDL.zip
Roulette Instalation
Copy & Play: Extract the contents of the package to the cstrike directory. Done!
You don`t have to do anything more, even you don`t have
to write roulette`s file name to plugins.ini. Just change the map.
Prizes Instalation (for custom prizes from outside of the package only)
Each prize files (.amxx) copy to the directory addons/amxmodx/plugins
To the file addons/amxmodx/configs/plugins-roulette.ini add their names with .amxx ending
If you are using WinSCP and you want to get a list of file names to be copied, just
select files prizes roulette, click PPM> File Names> Copy to Clipboard. then
just paste a ready list of awards the roulette file addons/amxmodx/configs/plugins-roulette.ini
A significant order (for custom prizes from outside of the package only)
Please note that the main plugin roulette.amxx must be listed at the very top of the configuration file plugins-roulette.ini
Then, below roulette.amxx line, place other prize`s filenames.
Parachute for roulette
Standard parachute is not compatible with most plugins and modifications, using gravity.
Changing your current parachute to parachute plugin by H.RED.ZONE, shall solve this problem.
Gravity won`t be reseted after using parachute and parachute will be invisible for invisible players.
Parachute by H.RED.ZONE v. 1.6 modified by myself not to show parachute at invisible players:
parachute.sma
Included prizes
With the roulette, there are
61 default prizes included.
You can read these desctiptions at the bottom of every prize`s SMA files.
Compiled plugins
As you need custom include files to compile, online compiler can't work, and as i'm not allowed to upload amxx files, i've asked a moderator to compile files.
You can find them there :
http://forums.alliedmods.net/showthr...28#post1913028
__________________