You should state what server / version you are using, making it easier for people to help you.
Your problem is that you want to give an item to a player wether he is online or not. If the player is offline, you have to inject code into the SQL directly, although this won't work if he's online.
You have to make an `if`-statement, checking if the player is online, should he be online, then you can just copy the functionality from the additem script, otherwise you'd have to, as I previously mentioned, make a query in this fashion:
Code:
db.query("INSERT INTO `player_items` SET `player_id` = x, `itemtype` = y, `count` = z")
Then there are continous problems where you want to place it (backpack, hand, feet), if the player has no capacity / room, then you might want to insert into the depot, etc. The lua function Player::addItem~ takes care of all of this, but if you're going to do it manually, you have to check these things yourself.
I hope this helps.
Ignazio.