Jump to content

Gamesnert

MTA Contributors
  • Posts

    2,035
  • Joined

  • Last visited

Everything posted by Gamesnert

  1. Gamesnert

    NameColor

    I think someone else can better make this code from scratch. Would work better and might even take less time. I'll look what it was intended to do and if I know another way of doing it. You'll hear it if I made any big progress in it. EDIT: Stuck! I don't know how to convert a string to a variable... There exists like "tonumber", "tostring" etc. But something like "tovar"doesn't... I'll keep on looking. But I have to go in about 20 to 30 minutes... If I can't finish it, I'll post it. If I can, I'll post it. (I'll edit this post again) EDIT2: I'm almost done, but g2g... Doesn't work yet, so someone else may finish it and improve it: -- ************* IMPROVED RELEASE *************** -- ************* MADE BY GAMESNERT *************** -- ************* SCRIPTNAME : *************** -- ************* NAMECOLOR (working version) *************** -- ************* A MUST HAVE FOR CLANS!! *************** -- ************* ORIGINAL BY: FATALITRY *************** accountdat={} function init() local xmlFile=xmlLoadFile("config.xml") if xmlFile then local configNode=true i=0 while configNode~=false do configNode=xmlFindSubNode(xmlFile,"user",i) if configNode then local xmlReadName=xmlNodeGetAttribute(configNode,"name") local xmlReadClass=xmlNodeGetAttribute(configNode,"class") accountdat[xmlReadName]={name=xmlReadName, class=xmlReadClass} accountdat[i+1]=accountdat[xmlReadName] else if i<1 then outputDebugString(getResourceName(getThisResource()) .. ": No users were found in the config file! The script won't have any effect!") end end i=i+1 end configNode=false configNode=xmlFindSubNode(xmlFile,"colors",0) if configNode then local readAdmin=xmlNodeGetAttribute(configNode,"admin") local readModerator=xmlNodeGetAttribute(configNode,"moderator") local readMember=xmlNodeGetAttribute(configNode,"member") accountdat["colors"]={admin=readAdmin,moderator=readModerator,member=readMember} else outputDebugString(getResourceName(getThisResource()) .. ": No color setting could be found! The script won't have any effect!") end end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),init) function onPlayerTalk(msg,msgType) if msgType==0 then local className=accountdat[getClientName(source)].class if className=="admin" then class=admin end if className=="moderator" then class=moderator end if className=="member" then class=member end local color=accountdat["colors"].class if class~=nil or class~=false then outputChatBox(color .. "[" .. className .. "] " .. getClientName(source) .. ": " .. "#FFFFFF" .. msg,getRootElement(),0,0,0,true) else outputChatBox("Booooooo!",getRootElement(),0,0,0) end end end addEventHandler("onPlayerChat",getRootElement(),onPlayerTalk) function stopNormalChat(msg,type) if type==0 then cancelEvent() end end addEventHandler("onPlayerChat",getRootElement(),stopNormalChat) The problem is that color (in outputChatBox) seems to be nil for some reason, also the pointless "if class==..." was because I found no other solution... Let's hope this'll work soon! EDIT3: Lol, forgot the rest of the files: config.xml: <config> <user name="Gamesnert" class="admin"/> <colors admin="#FF0000" moderator="#00FF00" member="#0000FF"/> </config> Aslong as you have a meta.xml leading to the script file, and you fix a few things... It SHOULD work... Atleast better than the other one, it was a shame to see someone making a big function which does not even have an "addEvent- or Command- Handler" ...
  2. And THAT'll take some time... Anyway: Ok, I believe you. Can't imagine it... But I'll believe you! XML is just simply great! Although I can't give you alot of info about it because I'm quite new with it, knowing this is an advantage itself! XML is very simple to use, you can save things you want to save in files, and you can make scripts in a way that they do not have to change the script itself to change a few results. A pretty easy example is the .map file, actually XML. Only thing is that it's loaded alot easier. Imagine, you have made a resource that'll display a message in a message box WITH DELAY. You might want it to be 2 seconds, but someone else might want it to be 1 second. You make a XML file to let them change it, without even having to open the script file. Now that you know about XML, you might want to know how it works. I'll redirect you to the XMLnode main page on the wiki. Like you most probably did with scripting other things, I'll let you learn it yourself: http://development.mtasa.com/index.php?title=Xmlnode Now note that XML is a bit slower and uses a bit more memory than normal in a script. But you can change that by loading everything from the start and saving it in variables and tables. But let's not rush and let you discover XML yourself first. Any questions can be placed on the forums.
  3. Dimensions are indeed not settable for an entire .map file, but it is SCRIPTABLE. You can use XML (my way) or another way (better one) to set the dimension of every content inside a .map file. About that bug: What you need it to be so far anyway? If you would like to create your own city's or something, do it at about ±1500 Z, instead of X and Y. That'd be my advice.
  4. And MY opinion is that this works fine, and do not need another system for now.
  5. Ok all nevermind! Found the problem! The readsystem seemed to act a little weird... I entered a linenumber, but apparently something was wrong with that... In the check code try to replace "line" with "1". Works for me. But I still do not understand what was wrong in those... 4 lines... Only "line" seemed to be wrong... Although the importance now is VERY low, I would like to know what I did do wrong. If anyone knows why that was wrong, please for... Eh... My sake. Tell me. EDIT: I'll edit my first post, to replace the non-working script with the working one. Just for other people so they might learn from it. (MIGHT learn from it )
  6. Ok, I changed: -accountdat to accountdat[i+1]. -The read attributes are now printed in the server window. Now comes something expected: (atleast by me) The XML system works fine... It must be in the writing or reading. So every line which involves writing and reading the table has more chance of being the problem than any other line... Anyone can see the problem with that info?
  7. Sorry forgot to mention accountdat actually WAS defined as a table. And 1 also didn't work
  8. As you could have read in a recently answered topic, Alexander said it would be a performance improvement to not constantly read from a XML file. Tables should be more efficiently. So I decided to try something out with these tables. Armed with a Lua tutorial I tried out some things and learned about tables for a bit. Now I have 3 problems: 1. The table WRITE could be wrong. 2. The table READ could be wrong. 3. I dunno which is wrong. So well, I recently learned to work with XML, and thought that would be a perfect test. It's an accountdata system, currently only containing money data and username data, but if this works it would be very likely to be expanded! So here are some pieces of code, the accountdat file, and, ofcourse, the error. accountdat.xml: <cash> <user name="Gamesnert" money="10000"/> <user name="Someothersucker" money="1"/> </cash> Table creation code: function xmlLoadInTable() local xmlFile=xmlLoadFile("accountdat.xml") if xmlFile then i=0 dataNode=true while dataNode~=false do dataNode=xmlFindSubNode(xmlFile,"user",i) if dataNode then local xmlReadName=xmlNodeGetAttribute(dataNode,"name") local xmlReadMoney=xmlNodeGetAttribute(dataNode,"money") accountdat[xmlReadName]={name=xmlReadName, money=xmlReadMoney} else outputDebugString("The while loop had reached " .. i) end i=i+1 end xmlUnloadFile(xmlFile) end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),xmlLoadInTable) The read, intended to check if the saving works. But I still don't know which is wrong... : function readTableLine(thePlayer,command,target) outputDebugString(accountdat[target].name .. ", " .. accountdat[target].money) end addCommandHandler("output",readTableLine) (Note: you can and must use playernames now! Improvement so I don't have to use loops to find the right string all the time ) (the ex)Error! I don't know why he starts about a ?... I just type the command "output 0" or "output 1" in the console, and they both give this error... Why?
  9. Gamesnert

    Reading XML

    The while loop above should help with it. Then you make the police vehicle ID's like "police1","police2" etc and then you use the while loop to read them all at a time.
  10. Gamesnert

    Reading XML

    XML is versatile, all the things you told actually ARE possible... Read this topic: http://development.mtasa.com/index.php? ... lementByID Dimension can be set with normal scripting functions and the help of the link above. About the custom XML, I quite agree because you can put in any argument you want. But it actually also is possible with a normal .map file. And what's the problem with that? In the resourcestart you just load all of the XML data and store it in tables.
  11. I knew it would be something stupid... Thanks...
  12. The array won't be saved... What kind of array? The one in the called function or the one like "something=call(..."? In case of the 2nd, I would not be surprised. It doesn't return anything without defining what to return with "return ".
  13. Although it did look like that was the solution, it wasn't... There HAS to be something with "if (sucMod and sucX and sucY and sucZ and secRX and sucRY and sucRZ) then"(or the places where they're defined) I think... The rest works perfectly! It saves the file correctly and everything... Only wrong message... (and it only saved because I added that to test which var was wrong ... NONE... )
  14. Do you really think anyone will give you precise date? Ofcourse I do. Nah, I asked when we COULD expect DP3.
  15. Sometimes the rocket speed IS right. Maybe when the airplane is going really slow? Or no... Even a hovering Hydra will be hit with extremely high speed.
  16. Those things are SOOOOOOO annoying... I don't even care if the speed is so high... Aslong as the speed is the same for both! (or did I already say that..? )
  17. Well if I didn't, I wouldn't see this in the server window eh? "Error: Not all necessary variables could be saved! Save aborted!"
  18. Sorry, but he's not talking about functions for as far as I understand, but he's talking about an event. An event that indeed needs to come to MTA. (because for as far as I know, there is no onVehicleWaterHit or something yet...)
  19. Hi again all, Another problem... Now about an "emergency saving system" for mabako's map editor. (since it won't save now and then, I made this just in case ) The problem is: I let it look where the script has gone wrong, and print that in the server screen. For some reason, the script below gave the last possible error: "Error: Not all necessary variables could be saved! Save aborted!" Now if you watch closely, I already wanted to check what was wrong, and put xmlSaveFile just in front of the error. I look in the file, and I see... No errors..? What is quite strange, because it DOES return false, and DOES give the error in the server window. Can anyone see what I did do wrong? (probably something stupid again... ) function saveVehicleLocation(thePlayer) if (isPlayerInVehicle(thePlayer)) then local vehicle=getPlayerOccupiedVehicle(thePlayer) local model=getVehicleID(vehicle) local x,y,z=getElementPosition(vehicle) local rx,ry,rz=getVehicleRotation(vehicle) rz=(360-rz) local xmlFile=xmlLoadFile("vehicles.xml") if xmlFile then local newVehicleLine=xmlCreateSubNode(xmlFile,"vehicle") if newVehicleLine then local sucMod=xmlNodeSetAttribute(newVehicleLine,"model",model) local sucX=xmlNodeSetAttribute(newVehicleLine,"posX",x) local sucY=xmlNodeSetAttribute(newVehicleLine,"posY",y) local sucZ=xmlNodeSetAttribute(newVehicleLine,"posZ",z) local sucRX=xmlNodeSetAttribute(newVehicleLine,"rotX",rx) local sucRY=xmlNodeSetAttribute(newVehicleLine,"rotY",ry) local sucRZ=xmlNodeSetAttribute(newVehicleLine,"rotZ",rz) if (sucMod and sucX and sucY and sucZ and secRX and sucRY and sucRZ) then xmlSaveFile(xmlFile) return true else xmlSaveFile(xmlFile) outputDebugString("Error: Not all necessary variables could be saved! Save aborted!") return false end else outputDebugString("Error: New vehicle line was not created!") end else outputDebugString("Error: File could not be opened!") return false end else return nil end end A final note: This code is being called by another resource, my commands part. Although I don't think there should be any problem in there, I post it just to be sure: call(getResourceFromName("total-war-XMLdb"),"saveVehicleLocation",thePlayer) And the reason for the strange resource name? That's just so not the ENTIRE gamemode has to start over by 1 change, but only the section XMLdb for example.
  20. @ v0nz: Have you read to the Wiki VERY well? Otherwise do it now, then we don't have to help you. People are lazy from nature you know. If you have read through it well, give us an example of what you want and proof it, by making a small start and post it. We can't give you scripts for free! We can help you to fix yours and to let you GET them free.
  21. If you've ever used.. well, any of the most used languages, you're used to being able to call a function "earlier" (line-wise) in the script than you defined it. In LUA it seems like functions aren't registered until the compiler/interpreter reaches the line in which it's declared. Don't reference or call functions until after you've declared them, and you'll be fine. exactly what I was thinking, but it hadn't been mentioned anywhere. I'm sure I've used a language with a similar problem in the past, but I've not come across that problem lately Ehm... I can remember it was somewhere in the wiki... Either server manual or introduction to scripting. So it IS mentioned somewhere.
  22. Gamesnert

    Cant damage players

    It is... Isn't there a way to program a few things into a .map file and that the AI will follow one at random and at the end goes to another path? Also, only making the server to create peds when they're in the drawrange of a player would be alot better for the traffic, wouldn't it?
  23. 1. Does // even work? 2. In line 2, you even forgot to do -- or //. (if the last one even works ofcourse)
  24. When joining or hosting a server? When joining you might want to use a keybinder, when hosting you might want to change bindKey command to change it.
×
×
  • Create New...