• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] String + Text

Status
Not open for further replies.

Lstm

Respected Member
Concatenate variable with string

Hello dear friends!
I was wondering how I can add a concatenate variable with string


Code:
uint32 entry_mudarchar;
						uint32 count_mudarchar;
						[COLOR="#FF0000"]uint32 text1_mudarchar;[/COLOR]
						[COLOR="#FF0000"]uint32 text1_mudarchar;[/COLOR]

						entry_mudarchar = uint32(sConfigMgr->GetIntDefault("NPC.EntryChangeToken", 49426));
						count_mudarchar = uint32(sConfigMgr->GetIntDefault("NPC.CountChangeToken", 1));
						[COLOR="#FF0000"]text1_mudarchar[/COLOR] = uint32(sConfigMgr->GetIntDefault("NPC.CountChangeToken", 0));
						[COLOR="#FF0000"]text1_mudarchar[/COLOR] = uint32(sConfigMgr->GetIntDefault("NPC.CountChangeToken", 0));

                        switch(uiAction)
                        {

                              case 0:
								  if (Player->HasItemCount(entry_mudarchar, count_mudarchar)) 
                                        {
											

											Player->DestroyItemCount(entry_mudarchar, count_mudarchar, true, true); 
											Player->DestroyItemCount(entry_mudarchar, count_mudarchar, true, false); 
                                                Player->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE);
                                                CharacterDatabase.PExecute("UPDATe characters Set at_login = at_login | '128' Where guid = %u", Player->GetGUID());
                                                Player->GetSession()->SendNotification("[COLOR="#FF0000"]|cffFFFFFFVocê precisa relogar para mudar sua Raca![/COLOR]");
                                                Player->PlayerTalkClass->SendCloseGossip();
                                        }
                                        else
                                        {
                                                Player->GetSession()->SendNotification("[COLOR="#FF0000"]|cffFF0000Você não tem emblemas o suficiente.[/COLOR]");
                                                Player->PlayerTalkClass->SendCloseGossip();
 
Last edited:

Rochet2

Moderator / Eluna Dev
In this case I believe it is best to use the built in method:
Player->GetSession()->SendNotification("Number: %u", text1_mudarchar);
If you look at SendNotification definition or declaration, you can see it expects a format cstring, and then additional arguments.
It works like printf, so I suggest you take a look at printf documentation. It will also include the different format characters: %s, %i etc.

However, you will likely hit this same problem elsewhere as well.
There are many solutions. You could use snprintf, which works in the same way as printf as well.
You could use stringstreams. Also, since TC now forces to use C++11, you can use to_string

CharacterDatabase.PExecute("UPDATe characters Set at_login = at_login | '128' Where guid = %u", Player->GetGUID());
This is wrong. The guid is actually low guid, so you should use GetGUIDLow.
Also, there already exists a prepared statement for this: https://github.com/TrinityCore/Trin...server/scripts/Commands/cs_character.cpp#L535

btw. I wouldnt use Player as a variable name since Player is already the class name.
Also, you have double declarations etc for the variable?
 
Status
Not open for further replies.
Top