iwalidza Posted March 23, 2020 Share Posted March 23, 2020 I need make a Character system but i don't know where i can start needed a create character and you need select you character to spawn i need to use mysql Link to comment
The_GTA Posted March 23, 2020 Share Posted March 23, 2020 (edited) Dear iwalidza, since I have helped you do the login system with MySQL I think you did get some experience with it. Let's discuss the design aspects of a character system. I think you want to have two tables: one table for the character itself and a second for items that belong to the character. The first table should store accountName, skinID, character_id, currentHealth, currentArmor, maxHealth, money, last_x, last_y, last_z and last_rotation. Thus we could have this code: server.Lua local function restore_character(player, char_id) local account = getPlayerAccount(player); if not (account) then return false, "player has no account"; end; local accountName = getAccountName(account); if not (accountName) then return false, "no account name"; end; local query = dbQuery(db_conn, "SELECT * FROM characters WHERE accountName='?' AND character_id='?'", accountName, char_id); if not (query) then return false, "player character does not exist"; end; local results = dbPoll(query, -1); dbFree(query); local char_res = results[1]; -- Restore the character. setElementModel(player, tonumber(char_res.skinID)); setElementHealth(player, tonumber(char_res.currentHealth)); setPedArmor(player, tonumber(char_res.currentArmor)); setElementPosition(player, tonumber(char_res.last_x), tonumber(char_res.last_y), tonumber(char_res.last_z)); setPedRotation(player, tonumber(char_res.last_rotation)); setPlayerMoney(player, tonumber(char_res.money)); return true; end local function get_player_characters(player) local account = getPlayerAccount(player); if not (account) then return false, "no player account"; end; local accountName = getPlayerAccount(account); if not (accountName) then return false, "no account name"; end; local query = dbQuery(db_conn, "SELECT character_id, skinID FROM characters WHERE accountName='?'", accountName); if not (query) then return false, "query failed"; end; local results = dbPoll(query, -1); if not (results) then return false, "polling query results has failed"; end; return results; end I think the saving code is a good exercise. Edited March 23, 2020 by The_GTA 1 Link to comment
iwalidza Posted March 23, 2020 Author Share Posted March 23, 2020 @The_GTA You didn't understand what I meant i need somthing like this Link to comment
The_GTA Posted March 24, 2020 Share Posted March 24, 2020 11 hours ago, iwalidza said: @The_GTA You didn't understand what I meant i need somthing like this It looks like this character system does use many smooth camera transitions. For that you will have to use the MTA camera functions: smoothMoveCamera - useful function for interpolating a camera between two look-at points getCamera - for advanced effects used in combination with setElementPosition and setElementRotation setElementPosition setElementRotation I think you can figure out the character data into that MySQL table out yourself. Seems pretty straightforward, like character ID, name and language. Design-wise I recommend creating a scene for the character selection. You see that those characters are placed on tree-stumps. Think of something creative yourself, select a position on the map to put it and script the characters and the camera to be placed there. You may even want to play around with the MTA map editor. createObject - for creating background props at the character selection screen The DX overlay seems pretty basic. You should know about DX functions since we have recently talked about UI creation for an inventory system. getScreenFromWorldPosition - to get the position to draw DX at on the screen for attached-to-players overlay getPedBonePosition - you may want to get the position of the player head to draw the name at like in the video dxDrawLine3D - used for item placement highlight in the video At certain parts in the video (10:38) you see a message queue pop up above the player's head. Looks like a list of string messages that gets removed after a some timer has passed. I recommend writing a queue system yourself where you store the beginning time of each message and remove the items whose elapsedTime has reached 3 seconds during a server-side setTimer loop. You may want these functions: setTimer - creating a loop on the server to handle removal of messages getTickCount - check expire of single messages by calculating the elapsedTime the typical dx functions like dxDrawText and dxDrawRectangle I am curious. What kind of help are you expecting? You know that this is a lot of work, right? 1 Link to comment
iwalidza Posted March 24, 2020 Author Share Posted March 24, 2020 4 hours ago, The_GTA said: It looks like this character system does use many smooth camera transitions. For that you will have to use the MTA camera functions: smoothMoveCamera - useful function for interpolating a camera between two look-at points getCamera - for advanced effects used in combination with setElementPosition and setElementRotation setElementPosition setElementRotation I think you can figure out the character data into that MySQL table out yourself. Seems pretty straightforward, like character ID, name and language. Design-wise I recommend creating a scene for the character selection. You see that those characters are placed on tree-stumps. Think of something creative yourself, select a position on the map to put it and script the characters and the camera to be placed there. You may even want to play around with the MTA map editor. createObject - for creating background props at the character selection screen The DX overlay seems pretty basic. You should know about DX functions since we have recently talked about UI creation for an inventory system. getScreenFromWorldPosition - to get the position to draw DX at on the screen for attached-to-players overlay getPedBonePosition - you may want to get the position of the player head to draw the name at like in the video dxDrawLine3D - used for item placement highlight in the video At certain parts in the video (10:38) you see a message queue pop up above the player's head. Looks like a list of string messages that gets removed after a some timer has passed. I recommend writing a queue system yourself where you store the beginning time of each message and remove the items whose elapsedTime has reached 3 seconds during a server-side setTimer loop. You may want these functions: setTimer - creating a loop on the server to handle removal of messages getTickCount - check expire of single messages by calculating the elapsedTime the typical dx functions like dxDrawText and dxDrawRectangle I am curious. What kind of help are you expecting? You know that this is a lot of work, right? The type of help I expect is like yours It teaches me the benefits of the various functions that help me to develop I repeat this thank you very much but with mysql charactar names sort how i can do that and get the character states @The_GTA 1 Link to comment
The_GTA Posted March 24, 2020 Share Posted March 24, 2020 3 hours ago, iwalidza said: but with mysql charactar names sort how i can do that and get the character states @The_GTA https://www.w3schools.com/SQL/sql_orderby.asp SELECT state1, state2, state3, ..., characterName FROM characters WHERE ... ORDER BY characterName ASC 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now