Dayokun Posted April 8, 2011 Posted April 8, 2011 Hey, I've just started up a server, and i'm a total noob in scripting. So I wanted to ask you guys if this is possible. The freeroam resource that comes along with MTA has a really nice create funtion for car / skins. Now I was wondering if there was an easy way to add a price to these items. The code in vehicles.xml as it is looks like this : </group> <group name="Planes, Jets and Airlines"> <vehicle id="592" name="Andromada" /> This is also the same layout as with the skins. Now I was wondering if this was possible in a similar way(This way won't work) </group> <group name="Planes, Jets and Airlines"> <vehicle id="592" name="Andromada" price="1000" /> Where in price = 1000 dollars I hope someone has an easy solution for this. Thanks!
proracer Posted April 8, 2011 Posted April 8, 2011 It doesn't work that way, you should make script with cash functions first: https://wiki.multitheftauto.com/wiki/SetAccountData or with XML or SQL system.
Chlorek Posted April 8, 2011 Posted April 8, 2011 You need edit freeroam script. Adding price="1000" isn't way bcuz scripts don't know what's value and how to use it! Easy example - if you want to add price to weapons you can use one thing without add prices to .xml file. Just open file fr_server.xml and look at 283 line. There is function: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else giveWeapon(source, weapon, amount, true) end end And change it to: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getPlayerMoney(source) if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then takePlayerMoney(source, 1000) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end This code (maybe I didn't test) add price for Uzi (ID is 28), price is 1000$. You can edit my code and add price for all weapons.
proracer Posted April 8, 2011 Posted April 8, 2011 I'm not so experienced in freeroam but I think that built-in money functions: takeMoney, setPlayerMoney is only temporarily.. That means it won't save the data when a player leaves or am I wrong?
Chlorek Posted April 8, 2011 Posted April 8, 2011 It won't save it but Dayokun don't want to save money to account data if I understand his post right. But if he wanna using account data money saving it's not much to do.... Just: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getAccountData(getPlayerAccount (source), "server-money") if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then newCash = playerMoney-1000 setAccountData (getPlayerAccount (source), "server-money", newCash) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end
Dayokun Posted April 8, 2011 Author Posted April 8, 2011 It won't save it but Dayokun don't want to save money to account data if I understand his post right. But if he wanna using account data money saving it's not much to do.... Just: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getAccountData(getPlayerAccount (source), "server-money") if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then newCash = playerMoney-1000 setAccountData (getPlayerAccount (source), "server-money", newCash) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end So if I understand correctly if I do this both the uzi and the pistol have a price? function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getAccountData(getPlayerAccount (source), "server-money") if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then newCash = playerMoney-1000 setAccountData (getPlayerAccount (source), "server-money", newCash) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end local playerMoney = getAccountData(getPlayerAccount (source), "server-money") if(tonumber(weapon) == 22) then if(tonumber(playerMoney) >= 200)then newCash = playerMoney-200 setAccountData (getPlayerAccount (source), "server-money", newCash) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end
Castillo Posted April 8, 2011 Posted April 8, 2011 It doesn't work that way, you should make script with cash functions first:https://wiki.multitheftauto.com/wiki/SetAccountData or with XML or SQL system. This makes totally no sense.. seriously, are you kidding him? He should use getPlayerMoney takePlayerMoney
proracer Posted April 8, 2011 Posted April 8, 2011 Read my next post, I said I'm not experienced in freeroaming and I don't use that way.
Chlorek Posted April 8, 2011 Posted April 8, 2011 First thing, do you wanna take player money from his "bank account" or from his hands? Secound thing, your thinking isn't right... how did you say "I'm a total noob" if you wanna make any scripts you should know anything about LUA but if you wanna know how to do this script I'll tell you. You did mistake... you must use: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getPlayerMoney(source) if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then takePlayerMoney(source, 1000) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end elseif(tonumber(weapon) == 22) then if(tonumber(playerMoney) >= 200)then takePlayerMoney(source, 200) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end When you wanna add any other weapon you need to add only: elseif(tonumber(weapon) == 22) then if(tonumber(playerMoney) >= 200)then takePlayerMoney(source, 200) giveWeapon(source, weapon, amount, true) be4 last word "else"! That's everything!
Castillo Posted April 8, 2011 Posted April 8, 2011 Read my next post, I said I'm not experienced in freeroaming and I don't use that way. Proracer, this has nothing to do with "freeroam", this is a normal script. By the way, why are you guys checking every weapon? why don't you create a table with the ID's/Prices?
Chlorek Posted April 8, 2011 Posted April 8, 2011 Read my next post, I said I'm not experienced in freeroaming and I don't use that way. Proracer, this has nothing to do with "freeroam", this is a normal script. Yea.... LUA is LUA! But it's not important... we should help and don't talk about shit!
Dayokun Posted April 8, 2011 Author Posted April 8, 2011 First thing, do you wanna take player money from his "bank account" or from his hands?Secound thing, your thinking isn't right... how did you say "I'm a total noob" if you wanna make any scripts you should know anything about LUA but if you wanna know how to do this script I'll tell you. You did mistake... you must use: function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getPlayerMoney(source) if(tonumber(weapon) == 28) then if(tonumber(playerMoney) >= 1000)then takePlayerMoney(source, 1000) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end elseif(tonumber(weapon) == 22) then if(tonumber(playerMoney) >= 200)then takePlayerMoney(source, 200) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money!", source, 255, 0, 0) end else giveWeapon(source, weapon, amount, true) end end end When you wanna add any other weapon you need to add only: elseif(tonumber(weapon) == 22) then if(tonumber(playerMoney) >= 200)then takePlayerMoney(source, 200) giveWeapon(source, weapon, amount, true) be4 last word "else"! That's everything! Thanks I'll try that
proracer Posted April 8, 2011 Posted April 8, 2011 Read my next post, I said I'm not experienced in freeroaming and I don't use that way. Proracer, this has nothing to do with "freeroam", this is a normal script. By the way, why are you guys checking every weapon? why don't you create a table with the ID's/Prices? Dude, I never worked with that functions so I don't know what they will do... They save money or not..?
Castillo Posted April 8, 2011 Posted April 8, 2011 The tables, proracer? if so, no, they are really good for this kind of stuff, so you can do. myWeaponsTable = {{22,500},{31,9000},{24,5000}} function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else local playerMoney = getPlayerMoney(source) for i,v in pairs(myWeaponsTable) do if(tonumber(weapon) == tonumber(v[1])) then if(tonumber(playerMoney) >= tonumber(v[2]))then takePlayerMoney(source, tonumber(v[2])) giveWeapon(source, weapon, amount, true) else outputChatBox("You haven't enough money, "..getWeaponNameFromID(tonumber(v[1])).." cost $"..tonumber(v[2]), source, 255, 0, 0) return end end end end end Then when you want to add a new weapon you just add it to myWeaponsTable following the way i did.
diegofkda Posted April 8, 2011 Posted April 8, 2011 Hey,I've just started up a server, and i'm a total noob in scripting. So I wanted to ask you guys if this is possible. The freeroam resource that comes along with MTA has a really nice create funtion for car / skins. Now I was wondering if there was an easy way to add a price to these items. The code in vehicles.xml as it is looks like this : </group> <group name="Planes, Jets and Airlines"> <vehicle id="592" name="Andromada" /> This is also the same layout as with the skins. Now I was wondering if this was possible in a similar way(This way won't work) </group> <group name="Planes, Jets and Airlines"> <vehicle id="592" name="Andromada" price="1000" /> Where in price = 1000 dollars I hope someone has an easy solution for this. Thanks! If you want to save your money in player account, you can use resource "Basic Save System" in community.
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