/* * This is my token/gambling code that I added to my mud...I have olc and did a bit of work to make it fit in...here's how to install. * * */ in act_info.c in function do_look. Find this line. switch ( obj->item_type ) { default: send_to_char( "That is not a container.\n\r", ch ); break; add this case ITEM_TOKEN: if (obj->value[4] != 1) { send_to_one(ch,"That is not a container."); break; } if(obj->value[2] > 0) { send_to_one(ch,"The current jackpot is %d gold.",obj->value[2]); break; } else send_to_one(ch,"There is no jackpot at this time."); break; ======================================================================================= in const.c find this { ITEM_JUKEBOX, "jukebox" }, add this { ITEM_TOKEN, "token" }, ======================================================================================== in db.c create_object function find this line case ITEM_SCROLL: if (level != -1 && !pObjIndex->new_format) obj->value[0] = number_fuzzy( obj->value[0] ); break; under it add this case ITEM_TOKEN: if( level != -1 ) { obj->value[1] = number_fuzzy( obj->value[1]); obj->value[2] = number_fuzzy( obj->value[2]); obj->value[3] = number_fuzzy( obj->value[3]); } break; ======================================================================================== in db2.c in load_objects find this line case ITEM_WEAPON: pObjIndex->value[0] = weapon_type(fread_word(fp)); pObjIndex->value[1] = fread_number(fp); pObjIndex->value[2] = fread_number(fp); pObjIndex->value[3] = attack_lookup(fread_word(fp)); pObjIndex->value[4] = fread_flag(fp); break; add this under it: case ITEM_TOKEN: pObjIndex->value[0] = fread_number(fp); pObjIndex->value[1] = fread_number(fp); pObjIndex->value[2] = fread_number(fp); pObjIndex->value[3] = fread_number(fp); pObjIndex->value[4] = fread_number(fp); break; further down convert_object case ITEM_SCROLL: add this case ITEM_TOKEN: ============================================================================================= merc.h with the item defines add this #define ITEM_TOKEN (free bit) ============================================================================================== tables.c find this line { "jukebox", ITEM_JUKEBOX, TRUE }, add this under it { "token", ITEM_TOKEN, TRUE }, ============================================================================================== if you have OLC olc_act.c in show_obj_values under the case for ITEM_DRINK_CON: add this case ITEM_TOKEN: sprintf(buf, "[v0] Token Type: [%s]\n\r" "[v1] Win Chance: [%d]\n\r" "[v2] Max Win: [%d]\n\r" "[v3] Min Win: [%d]\n\r" "[v4] Machine: [%d]\n\r", token_table[obj->value[0]].name, obj->value[1], obj->value[2], obj->value[3], obj->value[4]); send_to_char(buf,ch); break; further down in set_obj_values under this case 2: send_to_char( "LIQUID TYPE SET.\n\r\n\r", ch ); pObj->value[2] = ( liq_lookup(argument) != -1 ? liq_lookup(argument) : 0 ); break; case 3: send_to_char( "POISON VALUE TOGGLED.\n\r\n\r", ch ); pObj->value[3] = ( pObj->value[3] == 0 ) ? 1 : 0; break; } break; add this case ITEM_TOKEN: switch (value_num) { default: send_to_one(ch,"Token types, values for winning and if it's a machine or not."); return FALSE; case 0: send_to_char("TOKEN TYPE SET.\n\r\n\r",ch); pObj->value[0] = (token_lookup( argument ) != -1 ? token_lookup(argument) : 0 ); break; case 1: send_to_char("WIN CHANCE SET.\n\r",ch); pObj->value[1] = atoi(argument); break; case 2: send_to_char("MAXIMUM WINNINGS SET.\n\r",ch); pObj->value[2] = atoi(argument); break; case 3: send_to_char("MINIMUM WINNINGS SET.\n\r",ch); pObj->value[3] = atoi(argument); break; case 4: send_to_char("MACHINe SET.\n\r",ch); pObj->value[4] = atoi(argument); break; } break; ========================================================================================================= in olc_save.c in save_object under this case case ITEM_FOUNTAIN: fprintf( fp, "%d %d '%s' %d %d\n", pObjIndex->value[0], pObjIndex->value[1], liq_table[pObjIndex->value[2]].liq_name, pObjIndex->value[3], pObjIndex->value[4]); break; add this case ITEM_TOKEN: fprintf( fp, "%d %d %d %d %d\n", pObjIndex->value[0], pObjIndex->value[1], pObjIndex->value[2], pObjIndex->value[3], pObjIndex->value[4]); break; ====================================================================================================================================== That is all the code additions that i can figure..... add token.o to your make file and snip from below this statement email me at verias@powertrippin.org if you use this please and make sure to adjust OBJ_VNUM_TOKEN to an item you create. to make a gambling machine set the obj->value[4] to 1 and reset it in the room if you have an bugfixes, complaints or general questions feel free to email me.... //============================================TOKEN.C================================================================================== /* * Token code from Shattered Reality, (c) Verias of Shattered Reality, v1.2 Keith Wood 2000 */ #if defined(macintosh) #include #else #include #include #endif #include #include #include #include #include #include #include #include "merc.h" #include "olc.h" #include "interp.h" #include "recycle.h" #include "tables.h" #define OBJ_VNUM_TOKEN 27 bool chance args(( int num )); bool chance(int num) { if (number_range(1,100) <= num) return TRUE; else return FALSE; } OBJ_DATA *generate_token(CHAR_DATA *ch) { char buf[MIL]; OBJ_DATA *obj; int i, token; obj = create_object(get_obj_index(OBJ_VNUM_TOKEN),0); //for randomizing tokens for( i=0; i < MAX_TOKEN; i++) { if(ch->inserted->value[0] < 4 && (chance(7))) //we win an exp token { obj->value[0] = token_lookup("experience"); obj->value[1] = 100; obj->value[2] = number_fuzzy(token_table[obj->value[0]].max_win); obj->value[3] = number_fuzzy(token_table[obj->value[0]].min_win); obj->value[4] = 0; obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); if(ch->inserted->value[0] < 4) send_to_one(ch,"WooHoo!!! You won an experience token."); else send_to_one(ch,"You lost your %s token.",token_table[ch->inserted->value[0]].name); return obj; } else if(ch->inserted->value[0] != 3 && (chance(20)))//20 percent chance you get a quest token { obj->value[0] = token_lookup("quest"); obj->value[1] = number_range(0,100); obj->value[2] = number_fuzzy(token_table[obj->value[0]].max_win); obj->value[3] = number_fuzzy(token_table[obj->value[0]].min_win); obj->value[4] = 0; obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); if(ch->inserted->value[0] < 3) send_to_one(ch,"Hot Damn! You won a quest token."); else if( ch->inserted->value[0] > 3) send_to_one(ch,"Damn you just won back a quest token."); else send_to_one(ch,"You lost your %s token.",token_table[ch->inserted->value[0]].name); return obj; } else if(ch->inserted->value[0] != 2 && (chance(25))) //25 percent chance you get a train token { //we win a train token obj->value[0] = token_lookup("train"); obj->value[1] = number_range(0,100); obj->value[2] = number_fuzzy(token_table[obj->value[0]].max_win); obj->value[3] = number_fuzzy(token_table[obj->value[0]].min_win); obj->value[4] = 0; obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); if(ch->inserted->value[0] < 2) send_to_one(ch,"Nifty, you won a train token."); else if( ch->inserted->value[0] > 2) send_to_one(ch,"Shit you just won back a train token."); else send_to_one(ch,"You lost your %s token.",token_table[ch->inserted->value[0]].name); return obj; } else if(ch->inserted->value[0] != 1 && (chance(35))) //35 percent chance you get a practice token { //we win a prac token obj->value[0] = token_lookup("practice"); obj->value[1] = number_range(0,100); obj->value[2] = number_fuzzy(token_table[obj->value[0]].max_win); obj->value[3] = number_fuzzy(token_table[obj->value[0]].min_win); obj->value[4] = 0; obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); if(ch->inserted->value[0] < 1 ) send_to_one(ch,"You won a practice token."); else if (ch->inserted->value[0] > 1) send_to_one(ch,"Bah, you won back a practice token."); else send_to_one(ch,"You lost your %s token.",token_table[ch->inserted->value[0]].name); return obj; } else if(ch->inserted->value[0] !=0 && (chance(15))) { //win back a normal token obj->value[0] = token_lookup("normal"); obj->value[1] = number_range(0,100); obj->value[2] = number_range(250,400); obj->value[3] = number_range(25,249); obj->value[4] = 0; obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); if(ch->inserted->value[0] > 1) send_to_one(ch,"You just won back a normal token."); else send_to_one(ch,"You lost your %s token.",token_table[ch->inserted->value[0]].name); return obj; } } return NULL; } void do_insert(CHAR_DATA *ch, char *argument) { OBJ_DATA *obj, *obj_next; OBJ_DATA *obj2; OBJ_DATA *machine, *machine_next; int reward; bool found; if(argument[0] == '\0') { send_to_one(ch,"Insert what?"); return; } if( ( obj = get_obj_carry(ch,argument,ch)) == NULL) { send_to_one(ch,"You don't have that to insert."); return; } found = FALSE; for(machine = ch->in_room->contents; machine; machine = machine_next) { machine_next = machine->next_content; if( machine->item_type == ITEM_TOKEN && machine->value[4] == 1) { found = TRUE; if( obj->item_type != ITEM_TOKEN) { send_to_one(ch,"You can't insert that."); return; } //alrighty, let's gamble send_to_one(ch,"You insert %s into %s.",obj->short_descr,machine->short_descr); ch->inserted = obj; machine->value[2] += number_range(75,125); if(chance(obj->value[1])) { if(chance(45) && obj->value[0] != 4)//45 percent chance you win a new token generate_token(ch); else if( chance(5) && machine->value[2] != 0 && obj->value[0] == 0) //5 percent chance you hit jackpot with a normal token { reward = machine->value[2]; send_to_one(ch,"You hit the jackpot!"); send_to_one(ch,"You win %d gold!",reward); ch->gold += reward; machine->value[2] = 0; } else { reward = number_range(obj->value[3],obj->value[2]); send_to_one(ch,"You win %d %s!",reward, token_table[obj->value[0]].reward); if (token_table[obj->value[0]].value == 1) ch->gold += reward; else if(token_table[obj->value[0]].value == 2) ch->practice += reward; else if(token_table[obj->value[0]].value == 3) ch->train += reward; else if(token_table[obj->value[0]].value == 4) ch->pcdata->questpoints += reward; else if(token_table[obj->value[0]].value == 5) gain_exp(ch,reward); } obj_from_char(obj); extract_obj(obj); } else { send_to_one(ch,"You lost your %s token.",token_table[obj->value[0]].name); obj_from_char(obj); extract_obj(obj); return; } } } if(!found) { send_to_one(ch,"You see nothing to insert it into."); return; } return; } void do_token(CHAR_DATA *ch, char *argument) { OBJ_DATA *obj; char arg1[MSL]; char arg2[MSL]; char arg3[MSL]; char arg4[MSL]; argument = one_argument(argument,arg1); if(argument[0] == '\0' || arg1[0] == '\0') { send_to_one(ch,"Syntax: token \n\r" "Token Types are:\n\r" "Normal 0\n\r" "Practice 1\n\r" "Train 2\n\r" "Quest 3\n\r" "Exp 4\n\r" "All arguments must be numerical."); return; } obj = create_object(get_obj_index(OBJ_VNUM_TOKEN),0); /* if(!is_number(arg1) || !is_number(arg2)|| !is_number(arg3)|| !is_number(arg4)) { send_to_one(ch,"Arguments must be numerical."); return; } */ argument = one_argument(argument,arg2); argument = one_argument(argument,arg3); argument = one_argument(argument,arg4); obj->value[0] = atoi(arg1); obj->value[1] = atoi(arg2); obj->value[2] = atoi(arg3); obj->value[3] = atoi(arg4); obj->name = str_dup(token_table[obj->value[0]].name); free_string(obj->short_descr); obj->short_descr = str_dup(token_table[obj->value[0]].short_descr); free_string(obj->description); obj->description = str_dup(token_table[obj->value[0]].long_descr); obj_to_char(obj,ch); send_to_one(ch,"You have created a %s token.",token_table[obj->value[0]].name); // act("$n has created a $p token.",ch,NULL, obj, TO_ROOM); return; }