Jump to content

Exporting functions


Negriukas

Recommended Posts

Hello, I'm adding some exported functions to my xp system which is based on element datas "EXP" and "Level", Anyway when i tried to export them I get those errors,

1407251205-mta-screen-2014-08-05-14-12-53.png

1407251230-mta-screen-2014-08-05-14-12-44.png

This is the meta file.

<export function="addPlayerXP" type="server"/> 
    <export function="addPlayerXP" type="client"/> 
    <export function="setPlayerXP" type="server"/> 
    <export function="setPlayerXP" type="client"/> 
    <export function="takePlayerXP" type="server"/> 
    <export function="takePlayerXP" type="client"/> 
    <export function="getPlayerXP" type="server"/> 
    <export function="getPlayerXP" type="client"/> 

And the server side code.

function setPlayerXP(thePlayer, _, who, XP) 
    local thePlayer = getPlayerName(who) 
    setElementData(thePlayer, "EXP", XP) 
end 
  
function addPlayerXP(thePlayer, _, who, much) 
    local thePlayer = getPlayerName(who) 
    local H = getElementData(thePlayer, "EXP") or 0 
    local number = much 
    setElementData(thePlayer, "EXP", tonumber(H) + number) 
end 
  
function getPlayerXP(thePlayer, _, who, XP) 
    local thePlayer = getPlayerName(who) 
    getElementData(thePlayer, "EXP", XP) 
end 
  
function takePlayerXP(thePlayer, _, who, much) 
    local thePlayer = getPlayerName(who) 
    local H = getElementData(thePlayer, "EXP") or 0 
    local number = much 
    setElementData(thePlayer, "EXP", tonumber(H) - number) 
end 

And server side of my bots script.

addEvent( "onAlphaBotWasted" , true) 
addEventHandler( "onAlphaBotWasted", getRootElement(), 
function( killer ) 
    local money = 5000 
    local xp = 5 
    local points = getElementData(killer, "Points") or 0 
        exports.Experience:addPlayerXP(killer, xp) 
        givePlayerMoney( killer, tonumber(money)) 
        setElementData(killer, "Points", tonumber(H)+math.random(1,5)) 
        triggerClientEvent(killer, "onClientAlphaBotWasted", killer, money) 
end) 

Edited by Guest
Link to comment

1. Make sure the file that contains the functions is shared by both server and client. Meta.xml

2. Fix the arguments when you're calling the exported functions. The parameters are different to the arguments from line 7 (client-side script sample).

Tip: Don't give player money in client-side script because it will not sync with the server. Players will still have the same amount of money when you call getPlayerMoney in a server script.

Link to comment
1. Make sure the file that contains the functions is shared by both server and client. Meta.xml

2. Fix the arguments when you're calling the exported functions. The parameters are different to the arguments from line 7 (client-side script sample).

Tip: Don't give player money in client-side script because it will not sync with the server. Players will still have the same amount of money when you call getPlayerMoney in a server script.

I did:

Here is a part from meta

<script src="server.lua" type="server" /> 
    <script src="client.lua" type="client" /> 

Or do you mean this?

<export function="exampleExport3" type="shared" /> 

And i dont understand the second tip

2. Fix the arguments when you're calling the exported functions. The parameters are different to the ....

And the third tip i made just a typo while writting the topic and i fixed it

Edited by Guest
Link to comment
function addPlayerXP(thePlayer, _, who, much) -- func definition 
------------------------------------ 
exports.Experience:addPlayerXP(killer, xp) -- calling the function:  thePlayer = killer, _ = xp 

Link to comment
function addPlayerXP(thePlayer, _, who, much) -- func definition 
------------------------------------ 
exports.Experience:addPlayerXP(killer, xp) -- calling the function:  thePlayer = killer, _ = xp 

Alright thanks, I based mine on this thePlayer = me, _ = command, who = target, much = how much xp, So no need for "who" and "much" right?

I'm just a beginner trying to learn thats why i made a lot of mistakes in this code, And i couldnt find any example of exporting functions in a random topic or sometihng alike..

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