jkub Posted June 8, 2010 Share Posted June 8, 2010 Greetings I come to you this time in question why my server says that a client side event is not added client side even though I have checked more then 4 times and made sure that there was an event added. -server addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), function() triggerClientEvent ( getRootElement(), "resStart", getRootElement(), source ) end ) -client addEvent ( "resStart", true ) Link to comment
50p Posted June 9, 2010 Share Posted June 9, 2010 NEVER ever triggerClientEvent inside onResourceStart. This is because client has to download client-side files/script before he can use it, but because you try to trigger event before it's actually added then you will get this error. You should trigger server event inside onClientResourceStart event to tell server that client has downloaded all the files and the resource is running client-side too. This way, you can trigger client event after the download is done. Link to comment
jkub Posted June 9, 2010 Author Share Posted June 9, 2010 Oh. I cannot use onClientResourceStart alone. But are you trying to say it should be like: Client >>>> Server >>>> Client: Work Link to comment
jkub Posted June 9, 2010 Author Share Posted June 9, 2010 Oh. I cannot use onClientResourceStart alone. But are you trying to say it should be like:Client >>>> Server >>>> Client: Work Basicly What I am trying to do here is add every player in the server to a grid list in an admin panel I'm working on. I seemed to have it working for when a player quits and when he joins but in the middle of play when the resource starts is what I can't get here is my current code from doing client>server>client:work addEventHandler ( "clientResComplete", getRootElement(), function ( player, IP ) local id = 0 while ( id <= guiGridListGetRowCount( playerList ) ) do if ( guiGridListGetItemText ( playerList, id, playerColumn ) == getPlayerName ( player ) ) then -- if it makes it this far then from what I understand an insertion is not need due to their already being one that exists end--I can't turn this into an "else" id = id + 1 --Have to have this here in order to keep looking through the gridlist if I move it I get "Aborted: Infinite running script" end end ) Link to comment
50p Posted June 9, 2010 Share Posted June 9, 2010 Yes that's what you should do. Client->Server->Client But if you want to add players to grid list when resource starts, you can use getElementsByType to get all players connected to the server and add them to the grid list with a loop. Link to comment
jkub Posted June 9, 2010 Author Share Posted June 9, 2010 Works> Thanks:) Only Problem now is that If the player was to reconnect their would be a duplicate insertion in the gridlist. Here is the one for the resource start. addEventHandler ( "clientResComplete", getRootElement(), function ( player, IP ) for k, player in pairs ( getElementsByType ( "player" ) ) do local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, playerColumn, getPlayerName ( player ), false, false ) guiGridListSetItemText ( playerList, row, IPColumn, IP, false, false ) end end ) Here is the one for when a player joins the server function playerJoinHandler ( IP, name, serial ) local row = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, row, playerColumn, name, false, false ) guiGridListSetItemText ( playerList, row, IPColumn, IP, false, false ) end It just now hit me... If I make insertions both when a player joins and when the resource starts ( Triggered when a player joins anyway since it is "onClientResourceStart" ) then shouldn't I just remove one of these functions? Link to comment
jkub Posted June 9, 2010 Author Share Posted June 9, 2010 dammit... scratch that. I removed the one for when players join the server and wanted to use only the one that uses resource start and now it only adds players when the resource is started... The only way I could think of is use both of them, and check if each one of the row for the player it is trying to insert, already exists, however I have tried that several different ways and all that I have tried fail horribly. EDIT* This is getting to be alot bigger problem because now I discovered that since I looped that for every player that enters the server it will make an insertion for EVERYONE who it looped through. so if there was a total of 15 players in my server then I would have 15 insertions in the list of my self and 15 insertions of each and every other person. Damn this is a bigger problem then I thought. Please help me At the time of this picture I had just me and 1 other player in my server. It did this Here is what it also seems to be doing Link to comment
The_Ex Posted June 9, 2010 Share Posted June 9, 2010 Next time have a look at functions list... -> guiGridListClear You can also do loop through player list when you join(onClientResouceStart). Then add player onClientPlayerJoin and remove player from grid onClientPlayerQuit. This way grid will update even if adminpanel is opened. Link to comment
jkub Posted June 9, 2010 Author Share Posted June 9, 2010 Next time have a look at functions list...-> guiGridListClear I look through the function list quite often... Look again; according to the page, that function clears ALL the data from a gridlist. You can also do loop through player list when you join(onClientResouceStart). Then add player onClientPlayerJoin and remove player from grid onClientPlayerQuit. This way grid will update even if adminpanel is opened. Thanks. I will try this. I will get back ASAP Link to comment
The_Ex Posted June 9, 2010 Share Posted June 9, 2010 Yes, it cleans all the data but if you use 1st option by 50p and re-do the loop, players will be there, just clean it before you add them. Link to comment
jkub Posted June 10, 2010 Author Share Posted June 10, 2010 Tryed that. Failed. I got extremely fed up and cleaned out completely, all the functions that would either add change or delete insertions in the gridlist of my script and redid them. Here is what I have now. Players don't seem to be removed properly? --client function onClientResourceStart() initGUI() initReason() initSlapModifier() addEventHandler ( "onClientGUIClick", adminPanel, clickHandler ) addEventHandler ( "onClientGUIClick", reasonWindow, clickHandler2 ) addEventHandler ( "onClientGUIClick", slapModifierWindow, clickHandler3 ) -- triggerServerEvent ( "clientDownloadComplete", getLocalPlayer() ) -- end addEventHandler ( "clientServerInteractionComplete", getRootElement(), function ( IP, serial ) local tempRow = guiGridListAddRow ( playerList ) guiGridListSetItemText ( playerList, tempRow, playerColumn, getPlayerName ( source ), false, false ) guiGridListSetItemText ( playerList, tempRow, IPColumn, IP, false, false ) guiGridListSetItemText ( playerList, tempRow, serialColumn, serial, false, false ) end ) addEventHandler ( "onClientPlayerQuit", getRootElement(), function ( element ) local id = 0 while ( id <= guiGridListGetRowCount ( playerList ) ) do if ( guiGridListGetItemText ( playerList, id, playerColumn ) ) == getPlayerName ( source ) then guiGridListRemoveRow ( playerList, id ) end end id = id + 1 end ) addEventHandler ( "onClientPlayerChangeNick", getRootElement(), function ( oldNick, newNick ) local id = 0 while ( id <= guiGridListGetRowCount( playerList ) ) do if ( guiGridListGetItemText ( playerList, id, playerColumn ) == oldNick ) then guiGridListSetItemText ( playerList, id, playerColumn, newNick, false, false ) end id = id + 1 end end ) --server --Server addEvent ( "clientDownloadComplete", true ) addEventHandler ( "clientDownloadComplete", getRootElement(), function() triggerClientEvent ( getRootElement(), "clientServerInteractionComplete", client, getPlayerIP ( client ), getPlayerSerial ( client ) ) end ) Link to comment
50p Posted June 10, 2010 Share Posted June 10, 2010 It's not good idea to loop through the grid list and remove the row which has name of the player but instead I'd make a table of players and hold their row id in that table. Something like: plrIDs = { }; -- table of players and their row IDs -- when you add new row add the player to the table and set row id local tempRow = guiGridListAddRow( playerList ); plrsIDs[ source ] = tempRow; -- then, when player leaves the server it's easier and quicker to remove specific row: guiGridListRemoveRow( playerList, plrsIDs[ source ] ); plrsIDs[ source ] = nil; -- this is also easier to change text of cell when player changes his name: guiGridListSetItemText( playerList, plrsIDs[ source ], playerColumn, newNick, false, false ); Link to comment
jkub Posted June 12, 2010 Author Share Posted June 12, 2010 Thanks a million. That seemed to work. There is a section in my refined code where I get a "Clipboard" of information on whoever I am selecting in the playerlist. It works for the most part but there are players that when I have them selected it sometimes floods my chatbox returning nil values. This mainly happens with players who have just joined the server. Is that because that player is not done downloading the resources yet?. I know about the isTransferBoxActive function but I only know how to use that on the local client. If this actually is the case how would I use that function for that client I am selecting and return rather he is downloading or not. Link to comment
The_Ex Posted June 12, 2010 Share Posted June 12, 2010 Well, if you add them onClientResourceStart, then it's added when downloading is done, that wouldn't be problem anyways. Link to comment
jkub Posted June 13, 2010 Author Share Posted June 13, 2010 Yea, thats what I thought. When it passes me those errors I use the admin panel to spectate them and see if they are even spawned. Turns out they are fully spawned and playing the game free to get vehicles and what not. I don't see how this is happening. Sometimes pictures can help, if not then explain better then words Here is the panel before I open up the clipboard. Here is the clipboard open and displaying my information Here is the clipboard when I open it for someone else and try to get their information. If you notice it is blank and there is a debug returned in my debug window The debug says bad argument @ getWeaponNameFromID but somehow it still returns the correct value when I use it on other players. Now it just seems to work for some people and not for others... thats what I don't understand I have one long guiSetText line for filling out the clipboard and I have tried defining values before to shorten it up but when I define getWeponNameFromID it always says that in debug and returns a blank clipboard. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now