Custom NPC Help ( SQL )

Virtue

New member
Messages
259
Points
0
trinity,113,84,3 script Compensation NPC 715,{query_sql("SELECT `last_mac` FROM `login` WHERE `account_id`="+getcharid(3), .@vmacp$);query_sql("SELECT day FROM `virtue_promo` WHERE `last_mac`='"+escape_sql(.@vmacp$ )+"'", .@vmacp2$,.@Dayb);if(query_sql("SELECT day,account_id FROM `virtue_promo` WHERE `day`='"+gettime(4)+"' AND `account_id`='"+getcharid(3)+"'")) { dispbottom "Your already received the items for Today."; end;} else if (query_sql("SELECT last_mac,day FROM `virtue_promo` WHERE `last_mac`='"+escape_sql(.@vmacp$ )+"' AND `day`='"+gettime(4)+"'")) { dispbottom "Your Computer is already registered at our logs. Please Do Not Abuse this System"; end;} else if(.@Dayb != gettime(4)){ query_sql "INSERT INTO `virtue_promo` (last_mac,day,account_id) VALUES ('"+escape_sql(.@vmacp$ )+"','"+gettime(4)+"','"+getcharid(3)+"')"; getitem 14609,100; getitem 12214,20; getitem 30034,20; getitem 30020,10; dispbottom "Enjoy!."; end; }} 
Hi. this script works fine, but after sometime, something went wrong. nothing is shown at the map_server, but it does not query the sql_queries, i've tried removing all the queries and it works.

 
Regular Hercules installation has none of the following:

  • `last_mac` column in table `login`;
  • `virtue_promo` table, and neither of its columns.

Considering you have these fields on your server:

Line 3, 4 & 7: `day` column isn't enclosed on ``. Shouldn't be a big problem, but just in case. Same for `account_id` for line 4 and `last_mac` for line 7;

Line 3: You just select `day`, but provide 2 arrays to write the information to. Don't know if this is a problem, but you shouldn't specify more arrays than columns of data to get. If `day` is always set from gettime(4) (which always returns an integer), it's not safe to treat it as text.

Line 7 & 11: No need to enclose an integer between ' ', this way you treat it as string and you're interested on using it as a number.

If any of the above doesn't do any effect, try to debug your script by filling it with debugmes or dispbottom if you don't mind spamming your users, telling the number of results returned from the queries and/or the queries executed. Try those queries yourself and see if anything is wrong. Anyways, that NPC seems correct at first glance since these little mistakes shouldn't be any important, but I suggest fixing them.

 
Back
Top