Jump to content

Question About Scripting


rublisk19

Recommended Posts

That data will save the current function you are creating:

function housePrice (thePlayer) 
-----Complete your code 
setElementData(thePlayer, "price.data") 
end 

I recomendete to you, use database, is stored on the db, more effective, try to start learn if you don't know.

Link to comment
That data will save the current function you are creating:
function housePrice (thePlayer) 
-----Complete your code 
setElementData(thePlayer, "price.data") 
end 

I recomendete to you, use database, is stored on the db, more effective, try to start learn if you don't know.

Hmmm , as far i know scripting , that will not save an data + it saves for the element.

As far , you must make for all the houses\cars , and another function

I think you want to make it trought an command so it will be like

  
--House script here 
  
function buyTheHouse() 
  local account = getPlayerAccount ( thePlayer ) 
  if isGuestAccount ( account ) then 
   outputChatBox ( " You need to register in order to buy the house" , getRootElement() ) 
  else 
    setAccountData ( account , "ownHouse1" , playerHouse ) 
    takePlayerMoney ( source , 2000 ) -- Here you can set your own price 
  end 
end  
addCommandHandler ( "buyHouse1", buyTheHouse ) 
  

Maybe im wrong . Btw , you must do for all the house this way..

So what you have to do

What you need to do!

1.Make Markers , and you should script : when the player hits the marker , it gets the data, remember , different data for every house!

2.When the player hits the marker , and the house belongs him , then he enters in a int.

Link to comment
Hi i have question . Is there any way to make command like example setAccountData so i wan't make setHouseData and setCarData thanks for replies. So setAccountData saves accounts setHouseData would save house data and setCarData would save car data

Like that ?

function setHouseData(element, data, value) 
    if element and value then 
        setElementData(element, "house-data-"..data, value) 
    else 
        return false 
    end 
end 
  
function setCarData(element, data, value) 
    if element and value then 
        setElementData(element, "car-data-"..data, value) 
    else 
        return false 
    end 
end 

Link to comment

something but not this . here my dream :D

function playerExit() 
setAccountData (account, "money", getElementData(source, "MONEY")) 
setHouseData (house, "id", getElementData(source, "houseid")) 
setCarData (car, "id", getElementData(source, "carid")) 

something like i posted :D

Link to comment

so you'd expect to use a house element for setting? I don't think you can store that in sql so I guess you should just give each house a name or so as a correspondence because the following code works like this setHouseData(string HouseName, string Data)

Note: There is no getHouseData. Make it yourself

Note2: Might be some errors since I made it on the spot

executeSQLCreateTable('houseData', 'dataName TEXT, value TEXT') 
function setHouseData(houseName, save) 
    if not houseName or not save then return end 
    local sql = executeSQLQuery("SELECT dataName, value FROM houseData WHERE dataName = '"..houseName.."'") 
    if #sql == 0 then 
        executeSQLInsert("houseData", "'"..houseName.."', '"..save.."'") 
    else  --data was already set, I'm overriding it, but maybe you'll need some checks here  
        executeSQLUpdate("houseData", "dataName = '"..houseName.."'", "value = '"..save.."'") 
    end 
end 

Link to comment

A small heads up -script for you.

Things you need to do yourself:

- Find the account from the XML file and save it to the same child. Do not let it always make a new child.

- Give you information on player connect and fetch your money and houses/vehicles.

Tested and working. Only thing you need to do is the above thing.

local xml_file = "data.xml" 
  
function findPlayer(name, player) 
    local matches = {} 
    for i, v in ipairs(getElementsByType("player")) do 
        if getPlayerName(v) == name then 
            return v 
        end 
        local playerName = getPlayerName(v):gsub("#%x%x%x%x%x%x", "") 
        playerName = playerName:lower() 
        if playerName:find(name:lower(), 0) then 
            table.insert(matches, v) 
        end 
    end 
    if #matches == 1 then 
        return matches[1] 
    else 
        outputChatBox("Found " .. #matches .. " players with that partial name.", player, 220, 220, 0, true) 
    end 
    return false 
end 
  
addCommandHandler("issuehouse", 
    function(player, cmd, name, id) 
        if hasObjectPermissionTo(player, "function.banPlayer") then 
            if tostring(name) then 
                if tonumber(id) then 
                    local target = findPlayer(name, player) 
                    if tostring(target) then 
                        setElementData(target, "temp.houseid", tonumber(id)) 
                        outputChatBox("House with ID " .. tonumber(id) .. " successfully issued to " .. tostring(target) .. ".", player, 0, 255, 0, false) 
                        outputChatBox(getPlayerName(player) .. " issued a house to you with ID " .. tonumber(id) .. ".", target, 0, 255, 0, false) 
                    else 
                        outputChatBox("No players found with name " .. tostring(name) .. ".", player, 255, 0, 0, false) 
                    end 
                else 
                    outputChatBox("Syntax: /issuehouse [string: player] [number: id]", player, 220, 220, 0, false) 
                end 
            else 
                outputChatBox("Syntax: /issuehouse [string: player] [number: id]", player, 220, 220, 0, false) 
            end 
        else 
            outputChatBox("No sufficent privileges to execute this command.", player, 255, 0, 0, false) 
        end 
    end 
) 
  
addCommandHandler("issuevehicle", 
    function(player, cmd, name, id) 
        if hasObjectPermissionTo(player, "function.banPlayer") then 
            if tostring(name) then 
                if tonumber(id) then 
                    local target = findPlayer(name, player) 
                    if tostring(target) then 
                        local vehicle = getPedOccupiedVehicle(target) 
                        if vehicle then 
                            setElementData(target, "temp.vehicleid", tonumber(id)) 
                            outputChatBox("Vehicle '" .. getVehicleName(vehicle) .. "' successfully issued to " .. tostring(getPlayerName(target)) .. " with ID " .. tonumber(id) .. ".", player, 0, 255, 0, false) 
                            outputChatBox(getPlayerName(player) .. " issued a vehicle '" .. getVehicleName(vehicle) .. "' to you with ID " .. tonumber(id) .. ".", target, 0, 255, 0, false) 
                        else 
                            outputChatBox(getPlayerName(target) .. " is not in a vehicle at the moment.", player, 255, 0, 0, false) 
                        end 
                    else 
                        outputChatBox("No players found with name " .. tostring(name) .. ".", player, 255, 0, 0, false) 
                    end 
                else 
                    outputChatBox("Syntax: /issuevehicle [string: player] [number: id]", player, 220, 220, 0, false) 
                end 
            else 
                outputChatBox("Syntax: /issuevehicle [string: player] [number: id]", player, 220, 220, 0, false) 
            end 
        else 
            outputChatBox("No sufficent privileges to execute this command.", player, 255, 0, 0, false) 
        end 
    end 
) 
  
addCommandHandler("saveme", 
    function(player, cmd) 
        local xml = xmlLoadFile(tostring(xml_file)) 
        if xml then 
            if getAccountName(getPlayerAccount(player)) then 
                if getElementData(player, "temp.houseid") and getElementData(player, "temp.vehicleid") then 
                    local new = xmlCreateChild(xml, "data") 
                    xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                    xmlNodeSetAttribute(new, "houseid", getElementData(player, "temp.houseid")) 
                    xmlNodeSetAttribute(new, "vehicleid", getElementData(player, "temp.vehicleid")) 
                    xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                elseif not getElementData(player, "temp.vehicleid") and getElementData(player, "temp.houseid") then 
                    local new = xmlCreateChild(xml, "data") 
                    xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                    xmlNodeSetAttribute(new, "houseid", getElementData(player, "temp.houseid")) 
                    xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                elseif not getElementData(player, "temp.houseid") and getElementData(player, "temp.vehicleid") then 
                    local new = xmlCreateChild(xml, "data") 
                    xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                    xmlNodeSetAttribute(new, "vehicleid", getElementData(player, "temp.vehicleid")) 
                    xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                else 
                    local new = xmlCreateChild(xml, "data") 
                    xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                    xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                    xmlSaveFile(xml) 
                    xmlUnloadFile(xml) 
                end 
                outputChatBox("Your data was successfully saved.", player, 0, 255, 0, false) 
                outputDebugString(getPlayerName(player) .. " saved his data to " .. tostring(xml_file) .. ".") 
            else 
                outputChatBox("Please log in first.", player, 255, 0, 0, false) 
            end 
        else 
            outputChatBox("XML error happened, report to the administration.", player, 255, 0, 0, false) 
            outputDebugString("Unable to read file " .. tostring(xml_file) .. ". " .. getPlayerName(player) .. "'s data was not saved. Make sure you have created the XML file.") 
        end 
    end 
) 
  
addEventHandler("onPlayerQuit", root, 
    function() 
        local xml = xmlLoadFile(tostring(xml_file)) 
        if xml then 
            if getElementData(player, "temp.houseid") and getElementData(player, "temp.vehicleid") then 
                local new = xmlCreateChild(xml, "data") 
                xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                xmlNodeSetAttribute(new, "houseid", getElementData(player, "temp.houseid")) 
                xmlNodeSetAttribute(new, "vehicleid", getElementData(player, "temp.vehicleid")) 
                xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                xmlSaveFile(xml) 
                xmlUnloadFile(xml) 
            elseif not getElementData(player, "temp.vehicleid") and getElementData(player, "temp.houseid") then 
                local new = xmlCreateChild(xml, "data") 
                xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                xmlNodeSetAttribute(new, "houseid", getElementData(player, "temp.houseid")) 
                xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                xmlSaveFile(xml) 
                xmlUnloadFile(xml) 
            elseif not getElementData(player, "temp.houseid") and getElementData(player, "temp.vehicleid") then 
                local new = xmlCreateChild(xml, "data") 
                xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                xmlNodeSetAttribute(new, "vehicleid", getElementData(player, "temp.vehicleid")) 
                xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                xmlSaveFile(xml) 
                xmlUnloadFile(xml) 
            else 
                local new = xmlCreateChild(xml, "data") 
                xmlNodeSetAttribute(new, "account", getAccountName(getPlayerAccount(player))) 
                xmlNodeSetAttribute(new, "money", getPlayerMoney(player)) 
                xmlSaveFile(xml) 
                xmlUnloadFile(xml) 
            end 
            outputDebugString(getPlayerName(source) .. " saved his data to " .. tostring(xml_file) .. ".") 
        else 
            outputDebugString("Unable to read file " .. tostring(xml_file) .. ". " .. getPlayerName(source) .. "'s data was not saved. Make sure you have created the XML file.") 
        end 
    end 
) 

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...