Jump to content

A discussion on an existing resource - slrfuel?


churchill

Recommended Posts

https://community.multitheftauto.com/index.php?p= ... nts&id=190

Apologies to [uVA]bart for dissecting his work, but I thought it would be a good script upon which to further my education of LUA and MTA scripting.

Having looked at the description and scripts in this resource, I realised that there were a number of things in it that would probably cause problems for various server owners, mostly down to things being hardcoded into the script to handle such things as player data, and also additional functions to handle something unrelated to the fuel management system itself.

While I can understand the author's reasons for combining them, I wondered what problems it would cause for server owners, if, for example, it didn't have access to the xml files it was looking for.

Secondly, I am under the impression that the separate function that handle earning money through attacking players could/should really be a separate resource?

The reason I ask is that I wonder how easy it is to create resources that interop cleanly, rather than assuming that a server will have something already present on their machine or that data is stored in a particular way, and allow you to swap out resources that do a similar job for an improved one later down the line?

My understanding of the resource concept is that they are similar to classes, in that they perform a particular function, and uses calls to communicate data between them.

So, using this resource as an example, would it not be better to move the non-fuel related functions into it's own resource, perhaps even a third resource for the player management aspect, and a fourth resource for the bank account management, and then provide export functions in each so that they can communicate values between each other, but each performs their own functions?

For example, when you hit a marker (handled by the fuel resource), it checks to see if the user has the money to pay for it. The resource that handles this check and export function to call could be set in a config file somewhere (probably a server level one rather than resource, as the resources/function names for common tasks would be needed by multiple resources, so it's easier to maintain a list in one place than have to update the config file in multiple resources when you download a new resource to replace an old one).

In our example, this might be a resource called slrBank, with a function called "CheckPlayerBalance(thePlayer)". when called from the slrFuel resource, this function could return the balance of the player given back to the slrFuel resource, so that it can check whether a player can afford the fuel. How the slrBank resource stores this data would be up to this resource. All slrFuel needs to know is what resource and function to call in order to get the relevant value.

Similarly, our slrPlayer resource might be set up in a way that stores player data for players in an XML file, or in SQLLite. Again we won't know how it's storing the data, we don't care, all we need to know is that we could call a function called GetPlayerData(thePlayer, "attribute") in slrPlayer, and it would return the value of that attribute.

The idea being that there would be less problems with conflicting storage methods or resources that are all trying to perform the same function when server owners try to combine different resources?

Sorry, this is a bit long winded, but from a best practice point of view, I would love to know the thoughts of the experienced MTA/LUA scripters :) (or any experienced programmers of any other language for that matter, the concepts I'm getting at will still be familiar :))

Link to comment

Personally I prefer creating classes inside the resource and keep all functionality that is directly related to the script in one package instead of using many separate resources.

Regarding data storage, it is up to the developers to make sure their storage method does not interrupt with other resources. The aim is to create a script that does not bother end-users with the storage method or other complex tasks.

Link to comment

the reason behind the other functions included in my script are posted in my last comment on the resource and im sorry if i upset you churchill, but i do prefair to have it all in one resource with the scripts named to what they do, as you will see when i come to release the next version, which i am currently tideying up as the script i do agree is a bit sloppy.

Link to comment
the reason behind the other functions included in my script are posted in my last comment on the resource and im sorry if i upset you churchill, but i do prefair to have it all in one resource with the scripts named to what they do, as you will see when i come to release the next version, which i am currently tideying up as the script i do agree is a bit sloppy.

You didn't upset me at all! I'm new to scripting in this environment, and resources that have already been released are some of the only "working" examples of how to put MTA script packages together, e.g. they're useful learning material.

Your slrfuel resource interested me as there were two fuel scripts in the resources library, so I was just comparing them to see how they worked. If I remember correctly, your version requires money to get fuel whereas the other version didn't, so in that respect it's a more realistic resource. I'm well aware that the very nature of the scripts means you can tailor them for your own use on your own server, and why you've included the extra functionality in the resource so that it can function on it's own independently, but at the same I wondered if there is a "preferred" way to develop resources, e.g. add all the scripts it needs in order to perform as a solo resource, or, have them dependent on another resource. A good example of the later idealogy would be the "race" gamemode I downloaded a little while a go - at the point of downloading it prompted me to download further resources if I didn't have them already, as they are needed by the resource in order to function.

I can imagine your slrfuel resource working in a similar way, given the type of work it's doing to handle finances, and earning money for attacking people. :)

Link to comment

churchill do you have msn, i am a bit busy but i think i under stand what you mean about the functions and things, i can send you a edited version when i get a min to see if it is what you mean :)

do you mean like this

  
function addfunctiontrial(thePlayer, command ) 
    slrAddToPlayerCash ( getPlayerSerial ( thePlayer ), 50 ) 
    outputChatBox("player cash added via loop" ) 
end  
    addCommandHandler("addCash", addfunctiontrial) 
     
             
function slrAddToPlayerCash ( userSerial, ammount ) 
    local slrPlayer = xmlLoadFile ( "rpg_player.xml" )     
    local i = 0 
    local slrPlayerSubNode = xmlFindSubNode ( slrPlayer, "User", i ) 
        while ( slrPlayerSubNode ~= false ) do 
            if ( xmlNodeGetAttribute ( slrPlayerSubNode, "Serial" ) == userSerial) then 
                local readPlayerCurrentCash = tonumber(xmlNodeGetAttribute ( slrPlayerSubNode, "Cash" )) + tonumber(ammount) 
                    xmlNodeSetAttribute ( slrPlayerSubNode, "Cash", readPlayerCurrentCash)  
                        xmlSaveFile ( slrPlayer ) 
                    end 
                i = i + 1 
            slrPlayerSubNode = xmlFindSubNode ( slrPlayer, "User", i ) 
        end 
    return false 
end 
  

to add cash you use this

slrAddToPlayerCash ( userSerial, ammount )

Link to comment

Hi,

New here btw, um...dont really know what you guys are talking about but I know nothing about lua or any language for that matter but it took me all of 1 hour to find away to add money to player because when I ran the resource at server startup, joined the game... only to findout that player money was set to zero and upon restarting server money doesnt save. "breathes" Another thing churchill, when u get out a car and get back in the gas counter resets And no function when i pull to a gas fillup blip. Like I said im no programmer but i can mod off of your resources. Not copying or anything just changing some of the values in the code itself assuring you that all scripter info is still there like version, date created, Creator and all of that nice stuff. I also get a lot of jibberish in the server log about...

[04:34:45] JOIN: KillaB joined the game (IP: 127.0.0.1)

[04:34:46] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeFindSubNode' - Line: 296

[04:36:24] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeFindSubNode' - Line: 168

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeFindSubNode' - Line: 168

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeGetAttribute' - Line: 144

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlCreateSubNode' - Line: 153

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 154

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 155

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 156

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 157

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 158

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlNodeSetAttribute' - Line: 159

[04:36:54] WARNING: 1_ServerFuelGage.lua: Bad argument @ 'xmlSaveFile' - Line: 160

Just curious about how to get this to function right though it doesnt seem to be causing any problems (not knowing if the stated problems above stem from this) just curious.

Link to comment
xmlNodeFindSubNode is not a function. This should be xmlFindSubNode.

AFAIR, this is "misspelt". Probably MTA had xmlNodeFindSubNode in past and then it was changed to xmlFindSubNode, though the message wasn't changed and it shows the old message. I guess he uses xmlFindSubNode because you wouldn't get "Bad argument" warning message if the function you wanted to call doesn't not exist.

And Fatscrilla, if it doesn't cause you any problems, don't worry about it :) It could be fixed though, with simple if statement.

Link to comment

Dude! Seriously!? Dont worry about it huh, yea right. I'm here to help this guy church solve the bugs also for me to have a fully working script. Dont worry though, im reading up on some LUA now and doubt that i'll get around to understanding just the right 5+ or so cmds b4 im able to actually do something with the script. The language doesnt seem that hard but then again... Hell.!.!.! get used to hearing from me as im on on a mission and i'll be right here like white on rice and a papper plate in a snow storm. Funny how u say it could be fixed with just some if statments. I was thinking of changing the bad command to the good one.. shows how much I know! And with that im out Holla!!!

Link to comment
Dude! Seriously!? Dont worry about it huh, yea right. I'm here to help this guy church solve the bugs also for me to have a fully working script. Dont worry though, im reading up on some LUA now and doubt that i'll get around to understanding just the right 5+ or so cmds b4 im able to actually do something with the script. The language doesnt seem that hard but then again... Hell.!.!.! get used to hearing from me as im on on a mission and i'll be right here like white on rice and a papper plate in a snow storm. Funny how u say it could be fixed with just some if statments. I was thinking of changing the bad command to the good one.. shows how much I know! And with that im out Holla!!!

Um, can I just say that this isn't my script? :) it's [uVA]Barts! I've not actually attempted to run this script yet, so I wasn't aware that there were even any errors in it :)

A working Fuel management resource is on my to-do list - that handles just the fuel management aspect of it and nothing more, but whether that involves taking an existing resource and reworking it (with permission of course) or just writing my own, I've not decided yet.

I'm keen to do it in such a way that it let's the money and player data management get handled by a separate resource that you can define in the config of the fuel management resource. This is all in my head at the moment - whether what I'm talking about is actually a feasible solution is another matter. Needs more thought before I begin work on it, but I'm also working on some other little bits and bobs that hang together right now, so it might take a while before I do anything that I can release for public use.

Link to comment

churchill, i am working on that now making them in seperate scripts that can be enabled and disabled according to what a player wants to run in the server, also there was no errors of such when it was dp2.1, there must have been a change in the dp2.2 or dp2.3.

also churchill i have nearly re-wrote the fuel system in a different way by attaching a seperate id to the vehich :) so far i think its going ok but, i still dont get why those errors are suddenly arousing because they wasnt there, when i released it :S

Link to comment

sorry for ther double post but i just noticed something , the lines that are giving errors, have no errors on for instance on line 296 the "xmlNodeFindSubNode" error

here is the loop

  
 function FindSlrPlayerNode ( SlrPlayer, user ) 
    i = 0 
    local SlrPlayerSubNode = xmlFindSubNode ( SlrPlayer, "User", i ) 
    while ( SlrPlayerSubNode ~= false ) do 
    if ( xmlNodeGetAttribute ( SlrPlayerSubNode, "Serial" ) == user ) then 
    return SlrPlayerSubNode 
    end 
    i = i + 1 
    SlrPlayerSubNode = xmlFindSubNode ( SlrPlayer, "User", i ) 
    end 
    return false 
end 
  

as you can see there is no type error there, funnly tho when i looked in the origional script that i downloaded from the resource department there seems to be no errors in the script, but you are showing me errors in your post :S and the lines you gave me both seem to be in the loops :S which i cannot get my head around.

Link to comment

1st:

These are not errors! They are just warning messages telling you there is a bad argument passed to the function.

2nd:

From the function [uVA]Bart posted above this post I assume that SlrPlayer must be root xmlnode of the xml file that players are stored in and file format must be like this:

<file> 
    <User Serial="xxxx-xxxx-xxxx-xxxx" /> 
</file> 

If that's how the file looks, you should get that warning message if SlrPlayer was not xmlnode.

3rd:

I haven't seen code of that resource but I'm sure you should be able to get rid of that message with simple if statement.

Link to comment

one server had a big big problem with serials, well the way it changed. I don't follow so well what you the three of you are saying but it couldn't hurt to have a look at this:

MPORTANT NOTICE: IF YOU CAN PLAY MTA WITH DP2.1 DO NOT INSTALL DP2.2 OR DP2.3!

If you are a new player and have installed dp2.2 you will have the same serial as everyone else who has installed dp2.2...

The majority of our server coding is using serials - the wanted levels/jail/bank scripts all rely on each user having an individual serial. This, as you can imagine, will cause a few problems. Lots of people will have shared bank accounts and may also get jailed randomly as well as random wanted stars. Upon joining the server you may be jailed without actually being wanted.

If you get put in jail wrongfully bribe a cop (try a SAES member).

If you have been wrongfully banned because of this problem then you will be unbanned very soon.

http://forum.vces.net/index.php?showtopic=3078

Link to comment
You can always use getPlayerUserName and getClientIP istead and make your own banning system.

but that would be useless, mta already bans by ip and both those information are changeable.

but u already know that, hmm.

Well it wouldn't be a permenent ban like serial banning is, but it would hopefully provide enough of a deterrant to cheaters etc if they have to go to the trouble of getting a new IP and account before they can continue to cause problems on the server, so it's better than nothing.

Link to comment

Yeah, so getting usernames is quite useless ATM. What's quite usefull is DP2.1!! Because I still have a unique username and serial. ^^

Anyway: Can't you edit your username and serial in your registry? Ok, editing serial would be quite USELESS... But change of username would make scripts like these capable for a bit again.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...