I’m looking to clean up my current script (It works with some issues! Yay for progress) Right now what I have is
void OnLogin(Player* player, bool firstLogin)
{
uint32 rewardFrequency, TEAM_ALLIANCE, TEAM_HORDE,ALLIANCE_MOUNT, HORDE_MOUNT, playedtime, lastrewarded, newplaytime, MinutesToReward, ItemReward, InitialReward, StandardReward, MOUNTONSTART;
MOUNTONSTART = 1;
MinutesToReward = 5;
ItemReward = 29434;
InitialReward = 10;
StandardReward = 1;
rewardFrequency = MinutesToReward*60;
TEAM_ALLIANCE = 469;
TEAM_HORDE = 67;
ALLIANCE_MOUNT = 66090;
HORDE_MOUNT = 64659;
auto guid = player->GetGUID();
if(firstLogin) {
if(MOUNTONSTART == 1) {
if (player->GetTeam() == TEAM_ALLIANCE) {
player->LearnSpell(ALLIANCE_MOUNT, false);
}
if (player->GetTeam() == TEAM_HORDE) {
player->LearnSpell(HORDE_MOUNT, false);
}
}
}
QueryResult lastreward = CharacterDatabase.PQuery("SELECT last_reward FROM player_rewards WHERE guid = %u",guid);
QueryResult totaltime = CharacterDatabase.PQuery("SELECT totaltime FROM characters WHERE guid = %u", guid);
Field *played = totaltime->Fetch();
playedtime = played[0].GetUInt32();
if(!lastreward) {
ChatHandler(player->GetSession()).PSendSysMessage(“You have received 10 loyalty points”);
CharacterDatabase.PQuery(“INSERT INTO player_rewards(guid,last_reward) VALUES(%u, %u)”, guid, playedtime);
player->AddItem(ItemReward, InitialReward);
} else {
Field rewarded = lastreward->Fetch();
lastrewarded = rewarded[0].GetUInt32();
if(playedtime >= lastrewarded + rewardFrequency) {
uint amounttogrant, timecheck, timecheck2;
timecheck = lastrewarded + rewardFrequency;
timecheck2 = playedtime - timecheck;
amounttogrant = timecheck2/rewardFrequency+1;
ChatHandler(player->GetSession()).PSendSysMessage(“Grant %u Points”, amounttogrant);
//Update Script
newplaytime = amounttogrant60 + lastrewarded;
CharacterDatabase.PQuery(“UPDATE player_rewards SET last_reward = %u WHERE guid = %u”, playedtime, guid);
if(amounttogrant == 1) {
ChatHandler(player->GetSession()).PSendSysMessage(“%u Loyalty Point Has been added to your currency.”, amounttogrant);
} else {
ChatHandler(player->GetSession()).PSendSysMessage(“%u Loyalty Points Have been added to your currency.”, amounttogrant);
}
player->AddItem(ItemReward, amounttogrant*StandardReward);
}
uint32 timecheck = lastrewarded + rewardFrequency;
uint32 lastrewardedMinutes = lastrewarded / 60;
uint32 rewardFrequencyMinutes = rewardFrequency /60;
uint32 timecheckMinutes = timecheck / 60;
uint32 playedtimeMinutes = playedtime /60;
uint32 nextreward = timecheckMinutes - playedtimeMinutes;
if(nextreward == 1) {
ChatHandler(player->GetSession()).PSendSysMessage(“Next Loyalty Reward in %u minute.”,nextreward);
} else {
ChatHandler(player->GetSession()).PSendSysMessage(“Next Loyalty Bonus in %u minutes”, nextreward);
}
}
}
What I'd like to do is clean this up. A lot I mean...
For instance
void OnLogin(Player* player, bool firstLogin)
{
uint32 rewardFrequency, TEAM_ALLIANCE, TEAM_HORDE,ALLIANCE_MOUNT, HORDE_MOUNT, playedtime, lastrewarded, newplaytime, MinutesToReward, ItemReward, InitialReward, StandardReward, MOUNTONSTART;
MOUNTONSTART = 1;
MinutesToReward = 5;
ItemReward = 29434;
InitialReward = 10;
StandardReward = 1;
rewardFrequency = MinutesToReward*60;
TEAM_ALLIANCE = 469;
TEAM_HORDE = 67;
ALLIANCE_MOUNT = 66090;
HORDE_MOUNT = 64659;
auto guid = player->GetGUID();
if(firstLogin) {
RewardNewPlayer(Player* player, guid, ALLIANCE_MOUNT, HORDE_MOUNT, MOUNTONSTART);
}
}
void RewardNewPlayer(Player* player, uint32 guid, uint32 ALLIANCE_MOUNT, uint32 HORDE_MOUNT, uint32 MOUNTONSTART) {
ChatHandler(player->GetSession()).PSendSysMessage(“The Function Was Called”);
}
Of course the function would be to reward the new player. Not tell them the function was called, but that's just an
Of course the function would be to reward the player not to tell them we called a function, but that's just an example of what I'm trying to do. I believe my issue lies in Player* player. My PHP Example of what I'm trying to learn how to do in C++ would be.
function OnLogin($player = Player, bool $firstLogin) {
//Pretend All the variables are set here…
//Then we would call it as
RewardNewPlayer(Player, $guid, $ALLIANCE_MOUNT, $HORDE_MOUNT, $MOUNTONSTART);
}
function RewardNewPlayer($player = null, $guid, $ALLIANCE_MOUNT, $HORDE_MOUNT, $MOUNTONSTART) {
}