Jump to content

Help - trigger


The Killer

Recommended Posts

hello everyone

i have a little problem that when i do the trigger

in this code:

guiGridListSetItemText (mgrid, row, money, triggerServerEvent("money", getLocalPlayer(), player), false, false ) 

it is not happend

server :

addEvent("money", true) 
addEventHandler("money", root, 
function (player) 
getPlayerMoney(player) 
end 
) 

Edit:

and this code too

function PlayerList ( ) 
if ( Players ) then 
for id, player in ipairs ( getElementsByType ( "player" ) ) do 
local row = guiGridListAddRow ( gridd ) 
guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) 
guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) 
end 
end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) 
  
addEventHandler("onClientGUIClick", root, 
function () 
if (source == row) then 
local row2 = guiGridListAddRow ( mgrid ) 
local select2 = guiGridListGetItemText(mgrid, row2, money) 
if selectt and selectt ~= "" then 
local player = getPlayerFromName(select2) 
if player then 
guiGridListSetItemText (mgrid, row2, money, getPlayerMoney(player), false, false ) 
end 
end 
end 
end 
) 

i want when someone select the row one in 'gridd' then the other grid 'mgrid' show his money

Link to comment

You should store your variable first and then trigger it. It's a nicer way and easier to see what's wrong;

local money = getPlayerMoney ( getLocalPlayer() ) -- can be triggered client sided, just don't change it! 
guiGridListSetItemText (mgrid, row, money, money, false, false ); 

Also, the second error is because you created a local row. Which can't be seen out of his own function, remove the local and it will work. You might want to add the 'local row = nil;' on top of your document.

Link to comment

little help in this code:

function PlayerList ( ) 
if ( Players ) then 
for id, player in ipairs ( getElementsByType ( "player" ) ) do 
local row = guiGridListAddRow ( gridd ) 
guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) 
guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) 
end 
end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) 
  
addEventHandler("onClientGUIClick", root, 
function () 
if (source == row) then 
local row2 = guiGridListAddRow ( mgrid ) 
local select2 = guiGridListGetItemText(mgrid, row2, money) 
if selectt and selectt ~= "" then 
local player = getPlayerFromName(select2) 
if player then 
guiGridListSetItemText (mgrid, row2, money, getPlayerMoney(player), false, false ) 
end 
end 
end 
end 
) 

i want when someone select the row one in 'gridd' then the other grid 'mgrid' show his money

Link to comment

Hmm... do you mean like this ?

function PlayerList ( ) 
if ( Players ) then 
for id, player in ipairs ( getElementsByType ( "player" ) ) do 
local row = guiGridListAddRow ( gridd ) 
guiGridListSetItemText ( gridd, row, Players, getPlayerName ( player ), false, false ) 
guiGridListSetItemColor ( gridd, row, Players, 255, 255, 30 ) 
end 
end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, PlayerList ) 
  
addEventHandler("onClientGUIClick", root, 
function () 
if (source == row) then 
local row2 = guiGridListAddRow ( mgrid ) 
local select2 = guiGridListGetItemText(mgrid, row2, money) 
if selectt and selectt ~= "" then 
local player = getPlayerFromName(select2) 
if player then 
local playerMoney = getPlayerMoney(player) 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) 
end 
end 
end 
end 
) 

Link to comment

what has changed?

--CLIENTSIDE 
local playerMoney = getPlayerMoney(player) -- WON'T WORK. It will return the money of your player, so everyone in the gridlist will have your amount of money shown 
local playerMoney = getPlayerMoney() -- THIS IS THE SAME AS THE PREVIOUS ONE. No differences, at all. 

Basically, you have to write your money serverside into the element data of each user. Add a function to "refreshCash" and write element data of a user with a value of his money amount. And use element data clientside, it will work.

Or you can trigger client from server with user data and then build the gridlist rows and stuff.

Link to comment

function createPlayerList( ) 
if ( Players ) then 
for id, player in ipairs ( getElementsByType ( "player" ) ) do 
row3 = guiGridListAddRow ( gridd ) 
guiGridListSetItemText ( gridd, row3, Players, getPlayerName ( player ), false, false ) 
guiGridListSetItemColor ( gridd, row3, Players, 255, 255, 30 ) 
end 
end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, createPlayerList) 
  
addEventHandler("onClientGUIClick", root, 
function () 
if (source == row3) then 
row2 = guiGridListAddRow ( mgrid ) 
selectt = guiGridListGetItemText(gridd, row3, Players) 
if selectt and selectt ~= "" then 
player = getPlayerFromName(selectt) 
if player then 
playerMoney = triggerServerEvent("money", getLocalPlayer(), player) 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) 
end 
end 
end 
end 
) 

it doesn't show the money when i select a player it should show his money in the other grid

so i try it by using 'triggerServerEvent' same problem.

if you want the server side:

addEvent("money", true) 
addEventHandler("money", root, 
function (player) 
getPlayerMoney(player) 
end 
) 
Link to comment

the logic should go like this:

1.

--SERVERSIDE 
setElementData(player,"money",getPlayerMoney(player)) -- Each time player money changes. Yes, each time you write your player money. 

2.

--CLIENTSIDE 
playerMoney = getElementData(player,"money") -- This is what we read. So it equals to your player's money if you set that correctly. 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) -- Add the value to the grid 

Edited by Guest
Link to comment

so i did what you say but nothing happend, the code:

function createPlayerList( ) 
if ( Players ) then 
for id, player in ipairs ( getElementsByType ( "player" ) ) do 
row3 = guiGridListAddRow ( gridd ) 
guiGridListSetItemText ( gridd, row3, Players, getPlayerName ( player ), false, false ) 
guiGridListSetItemColor ( gridd, row3, Players, 255, 255, 30 ) 
end 
end 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, createPlayerList) 
  
addEventHandler("onClientGUIClick", root, 
function () 
if (source == row3) then 
row2 = guiGridListAddRow ( mgrid ) 
selectt = guiGridListGetItemText(gridd, row3, Players) 
if selectt and selectt ~= "" then 
player = getPlayerFromName(selectt) 
if player then 
playerMoney = getElementData(player,"money") 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) 
end 
end 
end 
end 
) 
Link to comment

will i try so hard it work when i put "getPlayerMoney" in client side it work but when i do 'trigger' it doesn't work

the code after changes :

addEventHandler("onClientGUIClick",root, 
function () 
if source == gridd then 
row2 = guiGridListAddRow ( mgrid ) 
name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) 
if name and name ~= "" then 
playerMoney =  triggerServerEvent("PlayerMoney", getLocalPlayer ()) 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) 
guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) 
elseif name and name == "" then 
guiGridListClear(mgrid) 
end 
end 
end 
) 

it work if i put "getPlayerMoney" in client side else no

Link to comment

ok, i want when someone select a player in the grid list 'gridd' then his money show in the other grid 'mgrid'

this code it work only if i put 'getPlayerMoney' client side, if i put it in the server by using trigger it doesn't work

else if i select a player and repeat select, the money show again and againg and again

when i select a player and click the name that i selected before it show my money whenever i click,

i want it show the money one time and if i change the selected player i mean if i select another player

then the player that i selected before his money remove and show the new one.

the code :

addEventHandler("onClientGUIClick",root, 
function () 
if source == gridd then 
row2 = guiGridListAddRow ( mgrid ) 
name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) 
if name and name ~= "" then 
playerMoney =  triggerServerEvent("PlayerMoney", getLocalPlayer ()) 
guiGridListSetItemText (mgrid, row2, money, playerMoney, false, false ) 
guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) 
elseif name and name == "" then 
guiGridListClear(mgrid) 
end 
end 
end 
) 
Edited by Guest
Link to comment

is this code right ? :

addEventHandler("onClientGUIClick",root, 
function () 
if source == gridd then 
row2 = guiGridListAddRow ( mgrid ) 
name = guiGridListGetItemText ( gridd, guiGridListGetSelectedItem (gridd), 1 ) 
if name and name ~= "" then 
triggerServerEvent("PlayerMoney", localPlayer) 
elseif name and name == "" then 
guiGridListClear(mgrid) 
end 
end 
end 
) 
  
addEvent("AddRow", true) 
addEventHandler("AddRow", root, 
function () 
guiGridListSetItemText (mgrid, row2, money, false, false ) 
guiGridListSetItemColor (mgird,row2,money, 0, 255, 0 ) 
end 
) 

Server#

addEvent("PlayerMoney", true) 
addEventHandler("PlayerMoney", root, 
function (player) 
money = getPlayerMoney (client) 
if money then 
triggerClientEvent("AddRow", client) 
end 
end 
) 
Link to comment

Trigger when clicked then button :

triggerServerEvent('GetMoney',localPlayer) 

and tigger in server-side :

addEvent('GetMoney',true) 
addEventHandler('GetMoney',root,function() 
    triggerClientEvent(source,'_setPlayerMoney',source,getPlayerMoney(source)) 
    end 
) 

source = if you want send to source.

Now add trigger in client-side :

addEvent('_setPlayerMoney',true) 
addEventHandler('_setPlayerMoney',root,function(Money) 
    guiGridListSetItemText (mgrid, guiGridListAddRow(mgrid),1, Money, false, false ) 
        guiGridListSetItemColor (mgrid,guiGridListAddRow(mgrid),1, 0, 255, 0 ) 
    end 
) 

^ I think this you want.

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