Jump to content
  • 0

SQL Inserting data USING NPC Script


Reducto

Question


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  231
  • Reputation:   9
  • Joined:  12/16/11
  • Last Seen:  

-       script  skull   -,{
OnPCKillEvent:

        // anti-suicide, can remove
        if( killedrid == getcharid(3) )
                end;  

        // don't loot in this map
        if( ! compare( .ALLOW_MAP$, ";" + strcharinfo(3) + ";" ) )
                end;

        set .@size, getarraysize(@SKULL_LOOT_AID);
        set .@ok, 1;

        while ( .@i < .@size ) {

                if ( @SKULL_LOOT_DELAY[.@i] < gettimetick(1) ) {
                        deletearray @SKULL_LOOT_DELAY[.@i], 1;
                        deletearray @SKULL_LOOT_AID[.@i], 1;
                        set .@size, .@size-1;
                        continue;
                }
                if ( @SKULL_LOOT_AID[.@i] == killedrid )
                        set .@ok, 0;

                set .@i, .@i+1;
        }

        set @SKULL_LOOT_DELAY[.@size], gettimetick(1) + .SKULL_DELAY;
        set @SKULL_LOOT_AID[.@size], killedrid;

        if ( .@ok )
                getnameditem( .SKULL_ID, rid2name(killedrid) );
        end;



OnInit:

        // Configs
        set .SKULL_ID   , 7420 ;
        set .SKULL_DELAY  , 120  ; // seconds.
        setarray .@allow_map$
                , "ivory_pvp"
        ;

        // Building a Quick Search function
        for ( set .@size, getarraysize(.@allow_map$); .@i<.@size; set .@i,.@i+1 )
                set .ALLOW_MAP$, .ALLOW_MAP$ + ";" + .@allow_map$[.@i];
        set .ALLOW_MAP$, .ALLOW_MAP$ + ";";
                } 

Can anybody here help me. I have this table in my sql.

 

DROP TABLE IF EXISTS `char_pk`;
CREATE TABLE `char_pk` (
`char_id` int(11) NOT NULL,
`kill_count` int(11) NOT NULL default '0',
`death_count` int(11) NOT NULL default '0',
`score` int(11) NOT NULL default '0',
PRIMARY KEY (`char_id`)
) ENGINE=InnoDB; 

I want every one kill 1 score will be inserted to the sql table.

 

 
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

-	script	skull	-1,{
OnPCKillEvent:
// anti-suicide, can remove
	if( killedrid == getcharid(3) ) end;  

// don't loot in this map
	if( ! compare( .ALLOW_MAP$, ";" + strcharinfo(3) + ";" ) ) end;

	set .@size, getarraysize(@SKULL_LOOT_AID);
	set .@ok, 1;

	while ( .@i < .@size ) {
		if ( @SKULL_LOOT_DELAY[.@i] < gettimetick(1) ) {
				deletearray @SKULL_LOOT_DELAY[.@i], 1;
				deletearray @SKULL_LOOT_AID[.@i], 1;
				set .@size, .@size-1;
				continue;
		}
		if ( @SKULL_LOOT_AID[.@i] == killedrid )
				set .@ok, 0;

		set .@i, .@i+1;
	}

	set @SKULL_LOOT_DELAY[.@size], gettimetick(1) + .SKULL_DELAY;
	set @SKULL_LOOT_AID[.@size], killedrid;

	if ( .@ok )
		getnameditem( .SKULL_ID, rid2name(killedrid) );
	query_sql "insert into `char_pk` (`char_id`, `kill_count`, `death_count`, `score`) values ('"+ getcharid(0) +"', '1', '0', '1') on duplicate key update `kill_count` = `kill_count` +1, `score` = `score` +1";
	attachrid killedrid;
	query_sql "insert into `char_pk` (`char_id`, `kill_count`, `death_count`, `score`) values ('"+ getcharid(0) +"', '0', '1', '-1') on duplicate key update `death_count` = `death_count` +1, `score` = `score` -1";

	end;

OnInit:
	// Configs
	set .SKULL_ID   , 7420 ;
	set .SKULL_DELAY  , 120  ; // seconds.
	setarray .@allow_map$, "ivory_pvp";

	// Building a Quick Search function
	for ( set .@size, getarraysize(.@allow_map$); .@i<.@size; set .@i,.@i+1 )
			set .ALLOW_MAP$, .ALLOW_MAP$ + ";" + .@allow_map$[.@i];
	set .ALLOW_MAP$, .ALLOW_MAP$ + ";";
	end;
}

 

I just add

	query_sql "insert into `char_pk` (`char_id`, `kill_count`, `death_count`, `score`) values ('"+ getcharid(0) +"', '1', '0', '1') on duplicate key update `kill_count` = `kill_count` +1, `score` = `score` +1";
	attachrid killedrid;
	query_sql "insert into `char_pk` (`char_id`, `kill_count`, `death_count`, `score`) values ('"+ getcharid(0) +"', '0', '1', '-1') on duplicate key update `death_count` = `death_count` +1, `score` = `score` -1";

update the score +1, kill_count +1 each kill and score -1, death_count +1 for the killed

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  231
  • Reputation:   9
  • Joined:  12/16/11
  • Last Seen:  

The table is not updating in game. I need to restart the server again to see the update. Please help.!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

The table is not updating in game. I need to restart the server again to see the update. Please help.!

No need to restart. I guess it will update once you log out then log in.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...