Jump to content

triggerServerEvent(SOLVED)


undefined

Recommended Posts

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
Link to comment
  
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?

Link to comment
  
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?

Link to comment

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!

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