xTravax Posted April 24, 2015 Share Posted April 24, 2015 Hello! I would like to create something similiar to group conversations. You invite a person over command, if he accepts you two merge into 1 conversation(unless if you are already with someone in conversation, then he gets in it as well) However i am not really sure how to store the conversation's data. I could use tables, but how do i do it without making conflicts? Any example how you would do it? Thank you in advance. Link to comment
MTA Team botder Posted April 24, 2015 MTA Team Share Posted April 24, 2015 I don't know if you are going to accept this answer, but you could take a look into my resource: https://community.multitheftauto.com/in ... ls&id=7424 Link to comment
xTravax Posted April 25, 2015 Author Share Posted April 25, 2015 Thanks. I like the way how you called it, 'Party Chat'. I have finished my 'party' resource (at least i thought so) I've ran into incredibly retarded bug(seriously) This is driving me nuts. -- (one part of client script) addEvent("onPlayerInvite",true) local theInviter = {} function onPartyInvite(inviter) if source == localPlayer then bindKey("k","down",triggerAccept) bindKey("l","down",triggerDecline) table.insert(theInviter,inviter) -- lets keep the inviter in table guiSetVisible(partyWindow,true) guiSetText(label,getPlayerNick(inviter).." has invited you for a party\n\nPress 'K' to accept, or 'L' to decline") guiLabelSetHorizontalAlign(label,"center") guiLabelSetVerticalAlign(label,"center") end end addEventHandler("onPlayerInvite",root,onPartyInvite) function triggerAccept() local inviter = unpack(theInviter) outputDebugString("inviter: "..getPlayerNick(inviter)) -- outputs different name than the localPlayer triggerServerEvent("onPartyAccept",inviter,localPlayer) guiSetVisible(partyWindow,false) unbindKey("k","down",triggerAccept) unbindKey("l","down",triggerDecline) theInviter = {} end -- one part of server script function onPartyAccept(player) if client == player then return error("WTF!?") end -- client is same as player, and it gives error outputChatBox(getPlayerNick(player).." has accepted your party invitation.",client,0,255,0) local id = getPlayerSerial(client) if not isPlayerInParty(client) then party[id] = {} party[id].players = {client,player} setElementData(client,"party.name",id) setElementData(client,"party.leader",true) setElementData(player,"party.name",id) setElementData(player,"party.leader",false) else table.insert(party[id].players,player) setElementData(player,"party.name",id) setElementData(player,"party.leader",false) end outputChatBox(getPlayerNick(player).." has accepted your party invitation!",client,0,255,0) end addEventHandler("onPartyAccept",root,onPartyAccept) Shortly said: I make sure that the party inviter and localPlayer are two different elements/players then i trigger a server event, and in server event they're both the person who invited another player(they're both the same player element) Please help me anyone if anyone knows why the f*** is this happening... Link to comment
MTA Team botder Posted April 26, 2015 MTA Team Share Posted April 26, 2015 triggerServerEvent("onPartyAccept",inviter,localPlayer) function onPartyAccept(player) if client == player then player will be always 'localPlayer'. Link to comment
xTravax Posted April 26, 2015 Author Share Posted April 26, 2015 yes player is an argument in server function and that player is localPlayer from clientside but client on the server is same as the player, and that is impossible inviter and localPlayer are two different players, and on server side they are same 1 player... why?how?help? Link to comment
MTA Team botder Posted April 26, 2015 MTA Team Share Posted April 26, 2015 triggerServerEvent("onPartyAccept",inviter,localPlayer) In your event handler onPartyAccept (serverside) you will have those values: source = inviter client = localPlayer player = localPlayer The parameter player is wrong in the triggerServerEvent call (clientside). Link to comment
xTravax Posted April 26, 2015 Author Share Posted April 26, 2015 alright, thanks it works now but i got a question: isn't client always the element in 2nd argument when triggeringEvents? what about the warning of source faking on wiki for these custom events? Link to comment
MTA Team botder Posted April 26, 2015 MTA Team Share Posted April 26, 2015 The hidden variable client is an automatically filled variable with the player-element, which triggered the event. Manipulated clients could trigger serverside events for other players. For example in the race resource a player can request to get killed by triggering a serverside event. The manipulated client could trigger that event for everyone and make everyone get killed. To avoid this, the race resource has a function to catch those false triggered events (source == client) called checkClient. 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