[HOWTO] Create Coins ID

01/02/2011 08:18 janvier123#1
Every character that did visit the D-Shop gets a unique ID, witch is different from the user_no
I know its retarded but we have to deal with it
so lets look at the SP in the database:

PHP Code:
/****** Object:  Stored Procedure dbo.BL_CreateIdCode    Script Date: 2006-5-25 13:03:36 ******/

CREATE PROCEDURE  dbo.BL_CreateIdCode
@o_id_code        varchar(20)         OUTPUT    
AS
BEGIN
    
    
DECLARE @serv_code  char(2)
    DECLARE @
rand_seqno varchar(12)
    DECLARE @
rand_code varchar(36)
    
SET @serv_code '01'
    
SET @rand_code newid() 
    
SET @rand_seqno SubString(@rand_code18) + SubString(@rand_code104)
    
SET @o_id_code = @serv_code CONVERT(VARCHAR(6), GetDate(), 12) +  @rand_seqno

END

GO 
And his user_no is: 09082414173865
but we dont need that yet!

we need to create a code like: 010909167956B7D86FEB

01 => The server ID code (normaly 01)
090916 => The date (year month day)
7956B7D86FEB => A random 12 number & letter code

we can make one with the following code

PHP Code:
<?php

//-----------------------------------------------------
// This is for MSSQL newid()
function create_newid($length$characters){

    if (
$characters == ''){ return ''; }
    
$chars_length strlen($characters)-1;
    
    
mt_srand((double)microtime()*1000000);
    
    
$newid '';
    while(
strlen($newid) < $length){
        
$rand_char mt_rand(0$chars_length);
        
$newid .= $characters[$rand_char];
    }
    
    return 
$newid;

}
//-----------------------------------------------------


// Server code is always 01
$serv_code '01';

// Create a random code
$rand_code create_newid(12'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890');

// Get the ymd date
$date date("ymd");

// Add it all toghter
$o_id_code $serv_code '' $date '' $rand_code;

// echo out the code
echo $o_id_code

?>
Now insert into a db

PHP Code:
INSERT INTO user_cash
    
(
    
id,
    
user_no,
    
group_id,
    
amount,
    
free_amount
    
)
VALUES
    
(
    
$o_id_code// the code we just created
    
$i_user_no// the user_no
    
'01'// the group code => should be 01
    
'0'// the amount
    
'0' // the free amount
    

this should work, if not ..... let me know :D
01/02/2011 08:21 caper#2
Cool, but not needed.
01/02/2011 08:36 bullet21.=BrokeBack_MT#3
Quote:
Originally Posted by caper View Post
Cool, but not needed.
Pls leave if u dun appreciate the man's work. Stop spamming..
01/02/2011 09:04 Cryptic.#4
Thanks Janvier!!!! Your awesome!
01/02/2011 09:51 janvier123#5
There, now you know its made :D
01/02/2011 23:53 Skeptiks#6
I left a Thanks even if I have no use of it but you get the Thanks for the work ;)
01/03/2011 02:20 pieter#7
u can also add a line to SP_CHAR_CREATE to execute this procedure
this is usefull when awarding characters free coins since u cant award coins untill they have openned dshop

when u add EXEC dbo.SP_YourCustomSPtoAddTheLines

to SP_CHAR_CREATE

u can award coins eventhough they did not open dshop yet :)