viewing paste Referral System v1 | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
//===== eAthena Script ================================================================================
//= Referral System
//===== By: ===========================================================================================
//= rahuldev345
//===== Current Version: ==============================================================================
//= V.1
//===== Compatible With: ==============================================================================
//= eAthena SVN, SQL Only
//===== Description: ==================================================================================
//= Referral System Working:
/*
        Player A : Old player (Invited player B and C)
        Player B and C : New comers
       
 1: As Player B and Player C logs in, they need to find npc
        "Referral Npc" and must Sign with NPC by choosing option
        "- My Friend Called me!" and Enter the exact name of his
        friend and then complete process by choosing option
        "Complete the process".
 2: The Player will be asked to Relog to Start with the System.
 3: As he relog, a timer will start attaching to player and
        it will run till he completes his todays work, i.e Play/
        Stay online for 5 Hours at your server.(as per below con-
        figuration, can be changed according to needs).
        ********************************************************\
          set $@hourstoplay, 5; // No. of hours to play everyday.
        \*******************************************************
 4: But, the reward wont be given just yet, the NPC will do
        constant checking, to see whether players B and C are
        active, for at least *days( Depends on you. ).
        Being active means, any(or) all of these;
                * Logs in and plays atleast X (won't mention this)
                  hours a day.
                * The npc keeps checking IP's Everytime the players
                  logs in, ( You can set the no. of octets you want
                  to check of ip-address )
                Eg; Referrals starting with first 3 octets being the
                same, ex: 204.152.10.25 and 204.152.10.75, won't count
                and it will dispbottom the warning.
 5: If they meet all those requirements, the inviter, will be
        rewared with some items.
*/
//===== Additional Comments: ===========================================================================
//= Let me know, if you find any bugs.
//===== Changelogs: ====================================================================================
// V.2 (a) Now the npc name is more suitable to edit.
//     (b) Now Recruits can't enter new players name than him. - thanks to Topher08 for pointing that out.
// V.3 (a) Prevent players those who completed job, but still able to apply as recruits.
//======================================================================================================
// - SQL TABLE
/*
CREATE TABLE IF NOT EXISTS `callfrnd` (
  `id` int(11) NOT NULL auto_increment,
  `account_id` int(11) NOT NULL default '0',
  `name` varchar(23) NOT NULL default '',
  `last_ip` varchar(100) NOT NULL default '',
  `last_ip2` varchar(100) NOT NULL default '',
  `ref_name` varchar(23) NOT NULL default '',
  `ref_id` int(11) NOT NULL default '0',
  `mins` tinyint(3) unsigned NOT NULL default '0',
  `days` tinyint(3) unsigned NOT NULL default '0',
  `task_end` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY (`account_id`),
  KEY (`id`)
) ENGINE=MyISAM;
*/
//======================================================================================================
 
//======================================================================================================
// Edit Configurations here:
//======================================================================================================
-       script  Ref_config      -1,{
 
OnInit:
        set $@daystoplay, 2;    // total no of days to play.
        set $@noofplayers, 2;   // min. no. of players to call to server to be eligible to get the price.
        set $@hourstoplay, 5;   // No. of hours to play everyday.
        set $@noofoctet, 3;             // No. of octects, that script will check.
        set $@new_aid, 2000000; // To be sure that the player is really new to server. Put the latest registered account id here.
        set $@name$,"^E41B17[Call Your Friend]^000000"; // Edit npc name here.
        end;
}
 
//======================================================================================================
// The main NPC:
//======================================================================================================
prontera,160,180,5      script  Referral Npc    100,{
               
        mes $@name$;
        mes "^616D7EI am one of the staff members of GM Team. And i am assigned to award players who bring players to our server and contribute to server population.";
        mes " ";
        next;
        mes $@name$;
        mes "^616D7ESo, How may I help you?";
        next;
        switch(select("- My Friend Called me!:- I have called My Friend's:- Close")) {
                mes $@name$;
                case 1:
                        if ( getcharid(3) < $@new_aid ) {
                                mes "^616D7EYou doesn't seems to be new to server.";
                                close;
                        }
                        mes "^616D7EOh.. Nice, so would you like to proceed with the Referral System?";
                        switch(select("Yes")) {
                                case 1:
                                        if (#CallFrnd >= 1) {
                                                mes "^616D7EYou are already Registered on our database.";
                                                close;
                                        }
                                        goto ReferralSystem;
                                }
                case 2:
                        if ( #YCallFrnd ) {
                                mes "^0000ffThanks! for supporting our server.";
                                close;
                        }
                        query_sql("SELECT count(ref_id) from `callfrnd` where ref_id = " + getcharid(3) + " AND task_end = 1",.@count);
                                if(.@count >= $@noofplayers) {
                                        mes "^616D7ECongratulations, It seems you have Recruited [^880000 " + .@count + " ^000000] Players, to our server.";
                                        next;
                                        set #YCallFrnd, 1;
                                        mes $@name$;
                                        mes "^616D7EAll Process has been completed successfully. Now are eligible of buying any but only one Item from the Referral Award Shop.";
                                        mes " ";
                                        mes "^616D7EHave a pleasent Stay at our server.!";
                                        close;
                                }
                        mes "^616D7ENot Enough Recruitment's. Work Hard.";
                        close;
                case 3:
                        mes "^616D7EI wish!, if you could have helped me. :(";
                        close;
        }
        end;
       
ReferralSystem:
        next;
        mes $@name$;
        mes " ";
        mes "^ff0000NOTE: ^000000^616D7EThe Entered Name should match with your friend's name or he won't get the prize.";
        mes " ";
        mes "^616D7EEnter your Friend name: ";
        next;
        input .@frnd$;
        if ( .@frnd$ == strcharinfo(0) ) {
                mes $@name$;
                mes "^616D7ESorry, you are not allowed to Enter your name.";
                close;
        }
        mes $@name$;
        mes "^616D7ESo you have been called by [ ^ff000f" + .@frnd$ + "^000000 ]? ^616D7EIs that right??";
        next;
        if(select("Yes:Back")==2) goto ReferralSystem;
                mes $@name$;
                mes "^616D7EIf you play more than [ ^2B60DE" + $@daystoplay + " days ^000000] and spend more than x hours to our server every day. Your friend will get a New Item from the list.";
                next;
                switch(select("Next:Show me the item List")) {
                        case 1:
                                break;
                        case 2:
                                mes $@name$;
                                mes "^616D7ETalk to my Neighbour Npc to check the Item List Or Read forums.";
                                close;
                }
                mes $@name$;
                mes "^616D7EAnd, if you Call your [ ^2B60DE" + $@noofplayers + " Friends ^000000] to our server, and they play more than [ ^2B60DE" + $@daystoplay + " days ^000000] and x no. of hours every day. Then you will also have a chance to win a Free Item.";
                next;
                mes $@name$;
                mes "^616D7EIts, Just that you need to follow some rules: ";
                mes " ";
                next;
                switch(select("Exit:Complete the process")) {
                        case 1:
                                mes $@name$;
                                mes "^616D7ENevermind~, You can come back again!";
                                close;
                        case 2:
                                query_sql("SELECT last_ip FROM `login` WHERE account_id = "+getcharid(3)+"", .@lastip$);        // recruits ip address
                                set .@frnd, query_sql ("SELECT name, char.account_id, last_ip FROM `char` LEFT JOIN `login` ON login.account_id = char.account_id where name = '" + escape_sql(.@frnd$) + "'",.@chname$, .@account_id, .@flastip$);     // recruiter ip address and information
                                        if (!.@frnd) {
                                                mes $@name$;
                                                mes "^ff0000FAILED! FAILED! FAILED!";
                                                mes " ";
                                                mes "^616D7ESorry, We didn't found your friend's name in our database. Make sure that you Enter's Everything correctly.";
                                                close;
                                        }
                                        if ( .@account_id == getcharid(3) ) {
                                                mes $@name$;
                                                mes "^ff0000WARNING: ^616D7EThis Player is found on your account. Sorry, Unable to proceed further!!!";
                                                mes " ";
                                                mes "Enter some other name";
                                                close;
                                        }
                                        if ( .@account_id > getcharid(3) ) {    // i am older than my frnd
                                                mes $@name$;
                                                mes "^616D7EIt seems, your friend is newer than you to our server. Damn you cheaters. ";
                                                close;
                                        }
                                        if ( .@lastip$ == .@flastip$ ) {
                                                mes $@name$;
                                                mes "^616D7EIt seems you and your friend are from IP Address: ^ff0000" + .@flastip$ + "^000000. Sorry, but its not allowed.";
                                                close;
                                        }
                                set #CallFrnd, 1;
                                query_sql("INSERT INTO `callfrnd` VALUES (NULL," + getcharid(3) + ",'" + escape_sql(strcharinfo(0)) + "','" + .@lastip$ + "','None','" + escape_sql(.@frnd$) + "'," + .@account_id + ",0,0,0)");
                                mes $@name$;
                                mes "^616D7EYour registration is now accepted.";
                                mes "^ff0000Now, you should relog to make changes save and start properly.^000000";
                                mes " ";
                                mes "and ^0000ff~ We Welcome's you to our server.";
                                close;
                }
}
 
//======================================================================================================
// Keep Checking Records and performs accordingly.
//======================================================================================================
-       script  timeplayed      -1,{
 
OnPCLoginEvent:
        if (#CallFrnd != 1) end;        // Task still not started or is completed
        query_sql("SELECT ref_id, mins, days from `callfrnd` where account_id = " + getcharid(3), @ref_id, @minute, consecutive_days);
        query_sql("SELECT SUBSTRING_INDEX(last_ip,'.'," + ($@noofoctet) + ") from `login` where account_id = " + @ref_id,.@fip$);
        query_sql("SELECT SUBSTRING_INDEX(last_ip,'.'," + ($@noofoctet) + ") from `login` where account_id = " + getcharid(3),@myip$);
        if((#lastDayOnlineC == gettimetick(2)/86400)) end;      // If today's job is completed or not.
        if( #lastDayOnlineC < ((gettimetick(2)/86400)-1) ) {    // if login was not yesterday
                set consecutive_days, 0;
                set @minute, 0;
                goto TimerStart;
        }
        if( #lastDayOnlineC == ((gettimetick(2)/86400)-1) ) {   // if login was yesterday
                goto TimerStart;
        }
 
TimerStart:
        if(.@fip$ == @myip$) {
                dispbottom "Referral system Stopped because you and your friend(s) ip is same.";
                end;
        }
        attachnpctimer ""+strcharinfo(0);
        initnpctimer;
        end;
       
OnTimer30000:
        if(checkvending() == 1 || checkchatting() == 1) {       //Check if Vending or chatting
                dispbottom "The timer stopped because you are vending/chatting. Please relog if you wish to start again.";
                stopnpctimer;
                end;
        }
 
        getmapxy( .@map$, .@x, .@y, 0 );        //Check if Idle
        if(@map$ == .@map$ && @x == .@x && @y == .@y) {
                set @afk, @afk + 1;
        } else {
                set @afk, 0;
        }
        set @map$, .@map$;
        set @x, .@x;
        set @y, .@y;
       
        if(@afk == 5) { // if afk for 5 mins reduce 4 mins from their total minutes.
                set @minute, @minute - 4;
                dispbottom "The timer stopped because you were Idle for 5 minutes. Please relog if you wish to start again.";
                stopnpctimer;
                end;
        }
        end;
 
OnTimer60000:   //Check every 1 Minute
        set @minute, @minute + 1;
        if(@minute == ($@hourstoplay*60)) {
                set @minute,0;
                query_sql("UPDATE `callfrnd` SET days = (days+1) WHERE account_id = " + getcharid(3) +";");
                set #lastDayOnlineC, gettimetick(2)/86400;
                set consecutive_days, consecutive_days +1;
                        if( consecutive_days == $@daystoplay ) {
                                set #CallFrnd, 2;
                                query_sql("UPDATE `callfrnd` SET task_end = 1 WHERE account_id = " + getcharid(3) +";");
                                stopnpctimer;
                                end;
                        }
                end;
        }
        initnpctimer;
        end;
       
OnPCLogoutEvent:
        if (#CallFrnd != 1) end;
        query_sql("INSERT INTO `callfrnd` (id,account_id,mins) VALUES (NULL," + getcharid(3) + ","+@minute+") ON DUPLICATE KEY UPDATE account_id= " + getcharid(3) + ",last_ip='"+@myip$+"',mins="+@minute);
        end;
}
 
//======================================================================================================
// Shop NPC:
// NOTE: This npc lets you buy only one item of quantity one.
//======================================================================================================
prontera,150,180,5      script  Referral Award Shop     83,{
        callshop "Ref#shop1",1;
        npcshopattach "Ref#shop1";
        end;
       
OnBuyItem:
        if(#YCallFrnd == 1) {
                set @cost,0;
                if ( @bought_quantity > 1) {
                        message strcharinfo(0), "You are only allowed to buy one item.";
                        end;
                }
                getitem @bought_nameid,@bought_quantity;
                set #YCallFrnd, 2;
                deletearray @bought_quantity, getarraysize(@bought_quantity);
                deletearray @bought_nameid, getarraysize(@bought_nameid);
                end;
        } else {
                mes "[ " + strnpcinfo(3) + " ]";
                mes "What? " + ((#YCallFrnd==0)? "you haven't Referred anyone to our server.":"you have alredy Received the price.");
                close;
        }
       
OnInit:
        npcshopattach "Ref#shop1";
        end;
}
 
-       shop    Ref#shop1       83,1750:-1,1751:-1,1752:-1,501:-1,502:-1,503:-1,504:-1,506:-1,645:-1,656:-1
Viewed 359 times, submitted by unknown.