Jump to content

steadyfi

Members
  • Posts

    144
  • Joined

  • Last visited

Everything posted by steadyfi

  1. What happens if I don't unload it ? Security (hackers, etc..) ? Resource consumption ? No, it remains in your server ram, which gives you less ram for your other stuff. Not really a big deal for a small xml file, but when it gets larger it might starts to lagg. Even so I recommend you, to make unloading xml files a habit. https://wiki.multitheftauto.com/wiki/XmlUnloadFile Ok Thanks By the way, how do I set player blips if in team ? I have this script (Client Side) but it only executes when the resource is started. How can I add a triggerClientEvent() in the server script without sending elements as I don't have any ? Or i can just call teh function ? (it is in the same resource) Client-Side Script: function showPlayersFromTeamOnGPS() team = getPlayerTeam(getLocalPlayer()) if team and getTeamName(team) ~= "Player" or getTeamName(team) ~= "Zombie" then teamPlayers = getPlayersInTeam(team) for playerKey,playerValue in ipairs(teamPlayers) do if playerValue ~= getLocalPlayer() then teamBlip = createBlipAttachedTo(playerValue, 0, 2, 0, 255, 255, 255) end end end end addEventHandler("onClientResourceStart", getRootElement(), showPlayersFromTeamOnGPS) Sorry if it doesn't match the title anymore.
  2. What happens if I don't unload it ? Security (hackers, etc..) ? Resource consumption ?
  3. It works, i just added xmlSaveFile after xmlDestroyNode and it worked. Thank you. Off-topic: Do you want to come on my server and help me test it ? It need 2 players and I am the only one.
  4. Didn't work.. it still remains in the teams.xml file Edit: Ups... i forgot to add xmlSaveFile(xmlFile) ! Now it works. Thank you
  5. Thanks but the XML Loading system works, my problem is the Deleting system. I already did something but it doesn't work. I need to search for the team name through more XML Nodes with the same name and get the attribute that is equal to the team name that is being deleted and delete that node. Ex: XML: <root> <team name="Test"></team> <team name="TestTwo"></team> </root> And let's say I want to delete TestTwo, how do I do to find it ? My current code is this: (Server-Side) (it doesn't work) --XML local teamName = getTeamName(team) local xmlFile = xmlLoadFile("teams.xml") local children = xmlNodeGetChildren(xmlFile) for i,node in pairs(children) do local attributes = xmlNodeGetAttributes(node) if attributes == teamName then xmlDestroyNode(node) end end --END XML
  6. Edit: Source Code: (Server-Side) function getPlayerFromPartialName(who) --Useful Function | Author: TAPL local who = who and who:gsub("#%x%x%x%x%x%x", ""):lower() or nil if who then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(who, 1, true) then return player end end end end --x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x-- function createATeam(source, commandName, teamName) team = getPlayerTeam(source) if team then outputChatBox("You are already in a team", source, 255, 0, 0) return end if teamName then local newTeam = createTeam(teamName) if newTeam then setPlayerTeam(source, newTeam) local playerAccount = getPlayerAccount(source) setAccountData(playerAccount, "isTeamLeader", true) --XML local xmlFile = xmlLoadFile("teams.xml", "root") local team = xmlCreateChild(xmlFile, "team") local success = xmlNodeSetAttribute(team, "name", teamName) if success then xmlSaveFile(xmlFile) elseif not success then outputChatBox("XML FATAL ERROR: Failed to save a team in the XML Team file") destroyElement(team) end --END XML outputChatBox("Successfully created team with name: "..teamName, source, 0, 255, 0) end else outputChatBox("Please enter a team name", thePlayer, 255, 0, 0) end end addCommandHandler("create", createATeam) function inviteToTeam(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true then local target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if not getElementData(target, "invited_to_team") then local teamName = getTeamName(team) setElementData(target, "invited_to_team", true) setElementData(target, "team_invited_to", teamName) setElementData(target, "inviters_name", thePlayer) outputChatBox("Invited player "..target.." to team !", thePlayer, 0, 255, 0) outputChatBox("You were invited to the team"..teamName.." !", target, 0, 255, 0) outputChatBox("Type '/team accept' or '/team deny'", target, 0, 255, 0) elseif getElementData(target, "invited_to_team") then outputChatBox("The player is already invited to a team", thePlayer, 255, 0, 0) return end else outputChatBox("You cannot invite yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("invite", inviteToTeam) function inviteHandling(thePlayer, cmd, arg) if arg then if getElementData(thePlayer, "invited_to_team") == true then if arg == "accept" then local team = getPlayerTeam(thePlayer) if getPlayerTeam(thePlayer) == nil then local inviterElement = getElementData(thePlayer, "inviters_name") local theTeam = getElementData(thePlayer, "team_invited_to") local thePlayersName = getPlayerName(thePlayer) local inviter = getPlayerFromName(inviterElement) local teamName = getTeamName(theTeam) setPlayerTeam(thePlayer, theTeam) outputChatBox(thePlayersName.." has joined !", inviter, 0, 255, 0) setElementData(thePlayer, "invited_to_team", false) elseif team then outputChatBox("You are already in a team ! Leave it before joining another.", thePlayer, 255, 0, 0) end elseif arg == "deny" then local inviterElement = getElementData(thePlayer, "inviters_name") local thePlayersName = getPlayerName(thePlayer) local inviter = getPlayerFromName(inviterElement) setElementData(thePlayer, "invited_to_team", false) setElementData(thePlayer, "team_invited_to", false) outputChatBox(thePlayersName.." has declined the invitation !", inviter, 255, 0, 0) outputChatBox("Invitation declined", thePlayer, 0, 255, 0) end else outputChatBox("You are not invited to any team", thePlayer, 255, 0, 0) end else outputChatBox("Argument 2 is missing. arg2 = accept/deny", thePlayer, 255, 0, 0) end end addCommandHandler("team", inviteHandling) function setAnotherPlayerLeader(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true then target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if getPlayerTeam(target) == team then local targetAccount = getPlayerAccount(target) setAccountData(targetAccount, "isTeamAdmin", true) local targetPlayerName = getPlayerName(target) outputChatBox(targetPlayerName.." added as leader !", thePlayer, 0, 255, 0) local teamName = getTeamName(team) outputChatBox("You were added as a leader in team: "..teamName.." !", target, 0, 255, 0) else outputChatBox("Player not in team", thePlayer, 255, 0, 0) end else outputChatBox("You cannot permit yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("permit", setAnotherPlayerLeader) function kickFromTeam(thePlayer, cmd, who) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") == true or getAccountData(playerAccount, "isTeamAdmin") == true then target = getPlayerFromPartialName(who) if target then if target ~= thePlayer then if getPlayerTeam(target) == team then local targetAccount = getPlayerAccount(target) if not getAccountData(targetAccount, "isTeamLeader") then setPlayerTeam(target, nil) local targetPlayerName = getPlayerName(target) outputChatBox("Kicked "..targetPlayerName.." from team !", thePlayer, 0, 255, 00) outputChatBox("You were kicked from the team ! D:", target, 255, 0, 0) else outputChatBox("You cannot kick the leader !", thePlayer) end else outputChatBox("Player not in team", thePlayer, 255, 0, 0) end else outputChatBox("You cannot kick yourself", thePlayer, 255, 0, 0) end else outputChatBox("Failed to fetch target", thePlayer, 255, 0, 0) end else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("tkick", kickFromTeam) function leaveTeam(thePlayer) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if not getAccountData(playerAccount, "isTeamLeader") then if getAccountData(playerAccount, "isTeamAdmin") then setAccountData(playerAccount, "isTeamAdmin", false) end setPlayerTeam(thePlayer, nil) local teamName = getTeamName(team) outputChatBox("You left the team "..teamName.." !", thePlayer, 0, 255, 0) local teamPlayers = getPlayersInTeam(team) local playerName = getPlayerName(thePlayer) for playerKey, playerValue in ipairs(teamPlayers) do outputChatBox(playerName.." left the team ! D:", playerValue, 255, 0, 0) end else outputChatBox("You can not leave as a leader", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end addCommandHandler("leave", leaveTeam) function deleteTeam(thePlayer) local team = getPlayerTeam(thePlayer) if team then local playerAccount = getPlayerAccount(thePlayer) if getAccountData(playerAccount, "isTeamLeader") then local teamPlayers = getPlayersInTeam(team) for playerKey, playerValue in ipairs(teamPlayers) do if playerValue ~= thePlayer then accTeamMembers = getPlayerAccount(playerValue) if getAccountData(accTeamMembers, "isTeamAdmin") then setAccountData(accTeamMembers, "isTeamAdmin", false) end setPlayerTeam(playerValue, nil) outputChatBox("Kicked from team because it was deleted \"{SMILIES_PATH}/icon_sad.gif\" alt=\"\" title=\"Sad\" />", playerValue, 255, 0, 0) end end --XML local teamName = getTeamName(team) local xmlFile = xmlLoadFile("teams.xml") local children = xmlNodeGetChildren(xmlFile) for i,node in pairs(children) do local attributes = xmlNodeGetAttributes(node) if attributes == teamName then xmlDestroyNode(node) end end --END XML destroyElement(team) setAccountData(playerAccount, "isTeamLeader", false) setPlayerTeam(thePlayer, nil) outputChatBox("The team has been deleted", thePlayer, 0, 255, 0) else outputChatBox("Access Forbidden", thePlayer, 255, 0, 0) end else outputChatBox("You are not in a team", thePlayer, 255, 0, 0) end end
  7. Nope ! Edit: Load teams from XML problem SOLVED !
  8. Yeah... I don't really get it. I already used it. Sorry if I'm stupid but it's my first time using XML to store and read things and I already crawled through the entire section on XML Function on the wiki. Could you please show me an example or how I can fix it ?
  9. Hello. I have a little problem with my Team System. I want to save all the teams into a XML file so when the resource restarts they will all be loaded back. I know I have to do it with a for loop and some XML functions but I don't really get it in my case. I read the wiki on xmlNodeGetChildren but it doesn't help me too much. The script works like this. There is a root node in the XML called . Then, every team is in a node with the attribute name="Exemple". I want to loop thru all of those and on every loop I want to get the XML attribute and then create a team with that name and do it over and over again. My thoughts on what I understood so far are that the script need to look like this: Server Side Script: --XML Code addEventHandler("onResourceStart", resourceRoot, function() local xmlFile = xmlLoadFile("teams.xml") local xmlNodes = xmlNodeGetChildren(xmlFile) for _,node in ipairs(xmlNodes) do local team = xmlNodeGetAttribute(node) createTeam(team) end end) XML File (teams.xml): <root> <team name="Test"/> <team name="TestTest"/> </root> Thanks. Edit: Sorry for the double-post ! My left click is crazy and annoying. I deleted the duplicate
  10. Didn't help. When I say it return I mean it jumps to the ELSE RETURN END line.
  11. Hello. I'm trying to make a script for a DayZ server to instantly repair the vehicle (fill in Engine, Tires, Parts, Fuel) but it doesn't seem to fetch the ID correctly and it just jumps to else return end. Anyone knows how I can get the ID of the car correctly ? Code (Server-Side): --Make vehicle functional function vehicleInstantRepair(thePlayer) local playerVehicle = getPedOccupiedVehicle(thePlayer) local vehID = getElementModel(playerVehicle) if playerVehicle and vehID then if vehID == 422 then vehFuel = 80 engine = 1 tires = 4 parts = 1 elseif vehID == 470 then vehFuel = 100 engine = 1 tires = 4 parts = 1 elseif vehID == 468 then vehFuel = 30 engine = 1 tires = 2 parts = 1 elseif vehID == 433 then vehFuel = 140 engine = 1 tires = 6 parts = 1 elseif vehID == 437 then vehFuel = 140 engine = 1 tires = 6 parts = 1 elseif vehID == 453 then vehFuel = 60 engine = 1 tires = 0 parts = 1 elseif vehID == 509 then vehFuel = 0 engine = 0 tires = 0 parts = 0 elseif vehID == 487 then vehFuel = 60 engine = 1 tires = 0 parts = 1 elseif vehID == 497 then vehFuel = 60 engine = 1 tires = 0 parts = 1 else return end do setElementData(playerVehicle, "Tire_inVehicle", tires) setElementData(playerVehicle, "Engine_inVehicle", engine) setElementData(playerVehicle, "Parts_inVehicle", parts) setElementData(playerVehicle, "fuel", vehFuel) end end end addCommandHandler("fill", vehicleInstantRepair) Note: No error given as it is jumping to return Command is unique, it's not a problem from it Thanks.
  12. Yes, the variable target is the player element. But it doesn't return nil, it is returning as a string and I need a element
  13. Hello all. I've got a little problem with a script. Im trying to make a command to set a player as Premium. I'm using setAccountData but when I try it tells me that it expected ELEMENT but it got a STRING Is there any way i can get a Element and not a string ? Code (Server-Side): --[[ ## Set Premium ]]-- function setPremium(playerSource, cmd, target, kit) if target and kit then local targetAccount = getPlayerAccount(target) if targetAccount and not isGuestAccount(targetAccount) then setAccountData(targetAccount, "premium_kit", kit) outputChatBox("Player "..target.." has been added as Premium with kit: "..kit.." !", playerSource) end else outputChatBox("Player not found or error accrued" ,playerSource, 255, 0, 0) end end addCommandHandler("premium", setPremium) Error: WARNING: basics\modules\utils_server.lua:84: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got string 'Steady'] Thanks
  14. Thanks ! Now I can continue my gamemode SOLVED
  15. Some of them are global and some for each player, i just need to know how I can pass them.
  16. Hello. How can I pass Booleans and Floats to other sides ? I know that triggerClientEvent, triggerServerEvent, setElementData only work with elements. Is it possible or I just need to work more with each side ? Thanks
  17. Got it ! Thanks Solidsnake EDIT: How do I make it rotate with the mouse and enter cars etc ? Right now it only work with the basic controls: Forward,Backward,Left,Right,Jump,Sprint and attack
  18. Doesn't support peds. Oh... thanks. Can I use something else instead or it's just impossible ?
  19. Hello. I'm working on a script to make a ped that acts like a player , can enter cars, can shoot , can do everything. But I have 1 big problem. I wonder how can I use setCameraTarget on a ped and sync the direction i'm looking to to move the ped. I tried it but it returns an error. First of all, I wanna thanks CrystalMV for his remote car script, that gave me the start. His video: Link: My code: Client Side: Server Side: Error: Thanks !
  20. Thanks, so I know I can keep trying with my script #SOLVED
  21. Hello. Can I set setCameraTarget on a ped ? And by the way, what side , Client or Server ? Thanks.
  22. Thanks it worked Think it worked too , didn't try, but thanks anyway for helping me ! #SOLVED
×
×
  • Create New...