Ouuuu, awarding loot, I like it! I need to ask, why are you using controller public thread to run your code? In the example I posted above I use the datawriter, because it checks for errors first. When my code gets executed I know I have a valid post to work with.
You don't need to create a model to update your custom table, you can do it within your postloot class, and you can place it as a function so you only need to write it once to handle all three of your if results:
$this->_updateTestTable($loot, $coin, $userId);
Also, you only need to get one instance of $visitor as all three of your if statements uses it:
Near the top of your method put this in, $visitor = XenForo_Visitor::getInstance(); and now to get the user_id, just use this: $userId = $visitor->getUserId();
XenForo model user comes with a method to update specific user data; you can call it like this:
$userLootData = array(
'loot_alert' => $loot
);
$this->_getUserModel()->update($userId, $userLootData);
protected function _updateTestTable($testImput = 0, $testCoin = 0, $userId)
{
// note the xf_ added to the table name, all custom tables should be preceded with xf_
return $this->_db->query('
UPDATE xf_test_table
SET
test_imput = ?, test_coin = ?
WHERE user_id = ?', array(
$testImput, $testCoin, $userId
)
);
}
protected function _getUserModel()
{
return $this->getModelFromCache('XenForo_Model_User');
}