Jump to content

triggerServerEvent(SOLVED)


undefined

Recommended Posts

Posted (edited)

Hi guys.

Im work on the this project. But;

When the player click on the weap.image or weap.label, client say's Test 1 but the server is not say Test 2 or Test 3. So triggerServerEvent is not work. It's not give error or warning on debug.

Here is my code:

---------------------------------------- 
-- Client-Side 
---------------------------------------- 
local onMouseTable = {{personality, "personality", "Personality"}, {pistol, "pistol", "Pistol"}, {deagle, "deagle", "Deagle"}, {uzi, "uzi", "UZI"}, {shotgun, "shotgun", "Shotgun"}, {ak47, "ak47", "AK-47"}, {m4, "m4", "M4"}} 
function onClickSkill(btn, state, aX, aY) 
    for k=1,#onMouseTable do 
        local weap = onMouseTable[k][1] 
        for i=1,#weap.image do 
            if source == weap.image[i] or source == weap.label[i] then 
                if lockedSkills(onMouseTable[k][2], onMouseTable[k][3], i) then 
                    triggerServerEvent("giveSkill", gMe, gMe, skillCosts, onMouseTable[k][2], i, weap.image[i]) 
                    outputChatBox("Test 1", 255, 168, 0) 
                end 
                break 
            end 
        end 
    end 
end 

---------------------------------------- 
-- Server-Side 
---------------------------------------- 
addEvent("giveSkill", true) 
addEventHandler("giveSkill", getRootElement(), function(player, skillCosts, skillName, skillLevel, image) 
    local amount = skillCosts[skillName][skillLevel][1] 
    local skillMoney = skillCosts[skillName][skillLevel][2] 
    local skillStat = skillCosts[skillName][skillLevel][3] 
    outputChatBox("Test 2", player, 255, 168, 0) 
    if skillName == "personality" then 
        outputChatBox("Test 3", player, 255, 168, 0) 
        local spawnArmor = skillCosts[skillName][skillLevel][4] 
        takePlayerMoney(player, skillMoney) 
        setElementData(player, skillName, skillLevel) 
        setPedStat(player, 24, skillStat) 
        callClientFunction(player, "boughtSkill", image) 
    end 
end) 

Where is the problem?

Edited by Guest
Posted

Where is "gMe" defined?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
triggerServerEvent("giveSkill", localPlayer, gMe, otherArguments) 

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted
  
triggerServerEvent("giveSkill",  resourceRoot,localPlayer, skillCosts, onMouseTable[k][2], i, weap.image[i]) 
  

local player as source uses more memory. If client and server files are within same resource then using resourceRoot is more efficient.

Posted
  
triggerServerEvent("giveSkill",  resourceRoot,localPlayer, skillCosts, onMouseTable[k][2], i, weap.image[i]) 
  

local player as source uses more memory. If client and server files are within same resource then using resourceRoot is more efficient.

Not work!

When the im removed the arguements on triggerServerEvent;

Like this:

local onMouseTable = {{personality, "personality", "Personality"}, {pistol, "pistol", "Pistol"}, {deagle, "deagle", "Deagle"}, {uzi, "uzi", "UZI"}, {shotgun, "shotgun", "Shotgun"}, {ak47, "ak47", "AK-47"}, {m4, "m4", "M4"}} 
function onClickSkill(btn, state, aX, aY) 
    for k=1,#onMouseTable do 
        local weap = onMouseTable[k][1] 
        for i=1,#weap.image do 
            if source == weap.image[i] or source == weap.label[i] then 
                if lockedSkills(onMouseTable[k][2], onMouseTable[k][3], i) then 
                    triggerServerEvent("giveSkill",  gMe) 
                    outputChatBox("Test 1", 255, 168, 0) 
                end 
                break 
            end 
        end 
    end 
end 

Server-Side is give this error:

ERROR: test\test_s.lua:3: attempt to index local 'skillCosts' (a nil value) 

addEvent("giveSkill", true) 
addEventHandler("giveSkill", getRootElement(), function(player, skillCosts, skillName, skillLevel, image) 
    local amount = skillCosts[skillName][skillLevel][1] -- Line 3 
    local skillMoney = skillCosts[skillName][skillLevel][2] 
    local skillStat = skillCosts[skillName][skillLevel][3] 
    outputChatBox("Test 2", player, 255, 168, 0) 
    if skillName == "personality" then 
        outputChatBox("Test 3", player, 255, 168, 0) 
        local spawnArmor = skillCosts[skillName][skillLevel][4] 
        takePlayerMoney(player, skillMoney) 
        setElementData(player, skillName, skillLevel) 
        setPedStat(player, 24, skillStat) 
        callClientFunction(player, "boughtSkill", image) 
    end 
end) 

So triggerServerEvent is work. But i dont understand this problem. Pff :cry:

Where is the problem?

Posted
  
triggerServerEvent("giveSkill",  resourceRoot,localPlayer, skillCosts, onMouseTable[k][2], i, weap.image[i]) 
  

local player as source uses more memory. If client and server files are within same resource then using resourceRoot is more efficient.

Not work!

When the im removed the arguements on triggerServerEvent;

Like this:

local onMouseTable = {{personality, "personality", "Personality"}, {pistol, "pistol", "Pistol"}, {deagle, "deagle", "Deagle"}, {uzi, "uzi", "UZI"}, {shotgun, "shotgun", "Shotgun"}, {ak47, "ak47", "AK-47"}, {m4, "m4", "M4"}} 
function onClickSkill(btn, state, aX, aY) 
    for k=1,#onMouseTable do 
        local weap = onMouseTable[k][1] 
        for i=1,#weap.image do 
            if source == weap.image[i] or source == weap.label[i] then 
                if lockedSkills(onMouseTable[k][2], onMouseTable[k][3], i) then 
                    triggerServerEvent("giveSkill",  gMe) 
                    outputChatBox("Test 1", 255, 168, 0) 
                end 
                break 
            end 
        end 
    end 
end 

Server-Side is give this error:

ERROR: test\test_s.lua:3: attempt to index local 'skillCosts' (a nil value) 

addEvent("giveSkill", true) 
addEventHandler("giveSkill", getRootElement(), function(player, skillCosts, skillName, skillLevel, image) 
    local amount = skillCosts[skillName][skillLevel][1] -- Line 3 
    local skillMoney = skillCosts[skillName][skillLevel][2] 
    local skillStat = skillCosts[skillName][skillLevel][3] 
    outputChatBox("Test 2", player, 255, 168, 0) 
    if skillName == "personality" then 
        outputChatBox("Test 3", player, 255, 168, 0) 
        local spawnArmor = skillCosts[skillName][skillLevel][4] 
        takePlayerMoney(player, skillMoney) 
        setElementData(player, skillName, skillLevel) 
        setPedStat(player, 24, skillStat) 
        callClientFunction(player, "boughtSkill", image) 
    end 
end) 

So triggerServerEvent is work. But i dont understand this problem. Pff :cry:

Where is the problem?

Just like I told you already use resourceRoot. Where is skillCosts defined?

Posted (edited)

It's here:

Removed 

Give this error when the im removed the other arguements. For example: skillCosts, i, onMouseTable. So the error is not due to skillcosts.

ERROR: test\test_s.lua:3: attempt to index local 'skillCosts' (a nil value) 

Edited by Guest
  • Moderators
Posted

if it is not in the same file/ not higher in the code, put the table as a global.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

did you changed the variable somewhere?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

is your table on top of your code?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Im found the mistake.

Mistake is in the weap.image.

local personality = { 
    label = {}, 
    image = {} 
} 
createSkillLevelButton(personality, 162, 53) 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() 
    skillWindow = guiCreateWindow(396, 129, 734, 451, "Skill System [F7]", false) 
    guiWindowSetSizable(skillWindow, false) 
    guiSetVisible(skillWindow, false) 
    createSkillLevelButton(personality, 162, 53) 
end) 
  
function createSkillLevelButton(weap, x, y) 
    for i=1, 6 do 
        weap.image[i] = guiCreateStaticImage(x, y, 82, 20, "wep_sel.png", false, skillWindow) 
        guiSetAlpha(weap.image[i], 1.0) 
        weap.label[i] = guiCreateLabel(20, 3, 42, 14, "Level "..i, false, weap.image[i]) 
        guiLabelSetColor(weap.label[i], 255, 255, 255) 
        guiSetFont(weap.label[i], "default-bold-small") 
        guiLabelSetHorizontalAlign(weap.label[i], "center", false) 
         
        addEventHandler("onClientMouseEnter", weap.image[i], onMouseEnterSkill) 
        addEventHandler("onClientMouseLeave", weap.image[i], onMouseLeaveSkill) 
        addEventHandler("onClientMouseEnter", weap.label[i], onMouseEnterSkill) 
        addEventHandler("onClientMouseLeave", weap.label[i], onMouseLeaveSkill) 
        addEventHandler("onClientGUIClick", weap.image[i], onClickSkill) 
         
        if i == 6 then return end 
        x = x + 92 
    end 
end 

When the im add the weap.image arguement, it's not work. Here is my create image code.

Help!

  • Moderators
Posted

be more specific and check your debug.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
be more specific and check your debug.

Not give error or warning on debug...

if so then what doesn't work of the code?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted

what was the problem?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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