Jump to content
  • 0

How to Add Columns in SQL


Poring King

Question


  • Group:  Members
  • Topic Count:  61
  • Topics Per Day:  0.02
  • Content Count:  911
  • Reputation:   166
  • Joined:  11/27/14
  • Last Seen:  

Hello im trying to add automatically a column in my database if not exist thru NPC Script .

 

ALTER TABLE IF NOT EXIST  `guild` (
    ADD `woe_point` INT(11) UNSIGNED NOT NULL DEFAULT '0',
) ENGINE = MYISAM;


 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

I don't recommend alter a column from official table

Spoiler

just write for fun, but please don't do it
 


-	script	kjhksjhf	FAKE_NPC,{
OnInit:
	if (!query_sql("SHOW COLUMNS FROM `guild` WHERE `Field` = 'woe_points'", .@fields, .@a, .@b, .@c, .@d, .@e))
		query_sql "ALTER TABLE `guild` ADD COLUMN `woe_points` INT DEFAULT 0 AFTER `skill_point`, ADD INDEX(`woe_points`)";
	end;
}

 

honestly just create a new table

CREATE TABLE `guild_woe_points` (
	`guild_id` INT PRIMARY KEY,
	`guild_name` VARCHAR(23),
	`woe_points` INT,
	KEY(`woe_points`)
) ENGINE = InnoDB;

then just

query_sql "INSERT INTO `guild_woe_points` VALUES ("+ getcharid(2) +", '"+ escape_sql(strcharinfo(2)) +"', 1) ON DUPLICATE KEY UPDATE `woe_points` = `woe_points` +1;

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  61
  • Topics Per Day:  0.02
  • Content Count:  911
  • Reputation:   166
  • Joined:  11/27/14
  • Last Seen:  

@AnnieRuru Well to be honest im trying to update and upgrade your old script

 

prontera,155,181,5    script    Woe Points    100,{
   .@nb = query_sql( "select name, woe_points from guild order by woe_points desc limit 3", .@guild_name$, .@points );
   for ( .@i = 0; .@i < .@nb; .@i++ ) {
       if ( !.@points[.@i] ) break;
       mes ( .@i +1 )+". "+ .@guild_name$[.@i] +" -> "+ .@points[.@i];
   }
   close;
OnClock1930:
OnClock2000:
OnClock2030:
OnClock2100:
   for ( .@i = 0; .@i < 30; .@i++ ) {
       .@castle_guild_id = getcastledata( getvariableofnpc( .Castles$[.@i], "WOE_CONTROL" ), 1 );
       if ( getvariableofnpc( .Active[0], "WOE_CONTROL" ) & 1 << .@i && .@castle_guild_id )
           query_sql "update guild set woe_points = woe_points +1 where guild_id = "+ .@castle_guild_id;
   }
   end;
OnBreakEmp: // put doevent under OnAgitBreak ...
   query_sql "update guild set woe_points = woe_points +1 where guild_id = "+ getcharid(2);
   end;
}


Im planning to Add

  1. Shop(That only Guild Master can Access) ,
  2. Get the points and use it for the fake_npc shop
  3. Automatically Install if the column is not exist (SQL)
  4. Get the last guild from the recently woe winners and give +(MorePoints)
Edited by Poring King
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

if you mean my old script from 2013, yeah I have learned things since then
in fact anything I made before 2015 should be scrap

I've seen your script collection release topic, you should be able to handle this kind of modification ....
this is script support section after all ... no spoon feed

and ? which part you don't understand ?

 

5 hours ago, Poring King said:

Get the last guild from the recently woe winners and give +(MorePoints)

just add the ON DUPLICATE KEY UPDATE statement inside OnAgitBreak label of woe script

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  61
  • Topics Per Day:  0.02
  • Content Count:  911
  • Reputation:   166
  • Joined:  11/27/14
  • Last Seen:  

16 minutes ago, AnnieRuru said:

if you mean my old script from 2013, yeah I have learned things since then
in fact anything I made before 2015 should be scrap

I've seen your script collection release topic, you should be able to handle this kind of modification ....
this is script support section after all ... no spoon feed

and ? which part you don't understand ?

 

just add the ON DUPLICATE KEY UPDATE statement inside OnAgitBreak label of woe script

Still learning ^_^  . Ok Thx for your effort

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...