Sign in to follow this  
MeChill

request and response issue via commands [node]

Recommended Posts

Hey, Node issue

I'm trying to make it so if playerA is (1. in Faction and 2. is Faction leader), he then is able to /invite playerB ( who is NOT in a faction )

I'm having no issues at all with this but then, I try to send a request from playerA to playerB in order to ask playerB if he wants to join and if he does, he then can use /accept and then playerB will get into the faction.

down below you can see my current code:

mp.events.addCommand('invite', (player, target) => {
    if(target === undefined){
        player.outputChatBox('SERVER: /invite [Name]')
    } else {
        whatFaction(player).then(results => { //whatFaction gets player's faction and factionRank and (faction 0 means Civilian or no faction )
            let theTarget = mp.players.at(target)
            if(results[0].faction === 1 && results[0].factionRank > 5) {
                isInFaction(theTarget).then(results => {
                    if(results[0].faction !== 0) {
                        player.outputChatBox('SERVER: Invited player is already in a faction.')
                    } else {
                        theTarget.outputChatBox('SERVER: You have been invited to a faction, in order to join use /accept')
                      // code??
                    }
                })
            }
        })
    }
}) // by the way, usernames ( ingame names ) are unique

At this point I'm really out of clue on how to:

1- 'get the entered information from ONLY theTarget' ( since he's the only one who's getting invited )

2- 'use that specific information'

Thanks for reading and I really appreciate any response.

Share this post


Link to post
Share on other sites
12 hours ago, MeChill said:

Hey, Node issue

 

Nope, not a node issue. Basic programming and logic issue? Maybe. You've been told two times on discord how to do that but you ignored the answers. Just set a variable on the target data with which faction he was invited to, and when he runs command "accept invite"(for example) then check if variable is there and if it is then get it's value(which would be the faction) and put him there.

Share this post


Link to post
Share on other sites
Posted (edited)

I'd like to add that you should check whether entity exists in pool before going any further. Also I'm wondering how do you expect to get the target player's object here

let theTarget = mp.players.at(target)
            

since you're referring to players by their names and not ids (https://wiki.rage.mp/index.php?title=Pool::at)

If you insist on using unique names then make a function that loops the player pool, match names and return player.

 

Edited by Doom

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.