SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/02/2020, 01:33 PM   #1
None1337
Big Clucker
 
Join Date: Aug 2017
Posts: 193
Reputation: 12
Default Cancel selection

I am using this command:

PHP Code:
CMD:selectobjs(playerid)
{

      
SetPVarInt(playerid"in_selecting"1);
      
SelectObject(playerid);

      return 
1;
}


public 
OnPlayerSelectObject(playeridtypeobjectidmodelidFloat:fXFloat:fYFloat:fZ)
{
      if(
GetPVarInt(playerid"in_selecting") == 1)
      {
            
DeletPVar(playerid"in_selecting");
      }
      return 
1;

The problem is that, when he press ESC, he cancel the selection, but the PVar ("in_selecting") is not deleted because the callback is not called.
How can I now if a player is canceled selection (via pressing ESC or other buttons) in order to delete his Pvar?

Last edited by None1337; 16/02/2020 at 04:36 PM.
None1337 is offline   Reply With Quote
Old 16/02/2020, 03:51 PM   #2
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 811
Reputation: 79
Default Re: Cancel selection

Have you tried debugging? I think the callback is called but there is something wrong with your if statement.
PHP Code:

public OnPlayerSelectObject(playeridtypeobjectidmodelidFloat:fXFloat:fYFloat:fZ)
{
printf("OnplayerSelectObject callback works fine");
if(
GetPVarInt(playerid"in_selecting") == 1)
{
printf("Your if statement works fine");
DeletPVar(playerid"in_selecting");

}
return 
1;

Try above.
__________________
Coming soon (5-21-2020):

Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Official Live Beta Release Date: 21th of May, 2020
Discord
jasperschellekens is offline   Reply With Quote
Old 16/02/2020, 04:04 PM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 822
Reputation: 68
Default Re: Cancel selection

Have you tried to set the pvar inside the SelectObject function instead of command? Also try debugging like jasperschellekens said.
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is online now   Reply With Quote
Old 16/02/2020, 04:35 PM   #4
None1337
Big Clucker
 
Join Date: Aug 2017
Posts: 193
Reputation: 12
Default Re: Cancel selection

Quote:
Originally Posted by Symon View Post
Have you tried to set the pvar inside the SelectObject function instead of command? Also try debugging like jasperschellekens said.
yes

Quote:
Originally Posted by jasperschellekens View Post
Have you tried debugging? I think the callback is called but there is something wrong with your if statement.
PHP Code:

public OnPlayerSelectObject(playeridtypeobjectidmodelidFloat:fXFloat:fYFloat:fZ)
{
printf("OnplayerSelectObject callback works fine");
if(
GetPVarInt(playerid"in_selecting") == 1)
{
printf("Your if statement works fine");
DeletPVar(playerid"in_selecting");

}
return 
1;

Try above.
I tried and when he press ESC (when he cancel the selection) the callback OnPlayerSelectObject is not called. So the Pvar is still active.
None1337 is offline   Reply With Quote
Old 16/02/2020, 04:42 PM   #5
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 822
Reputation: 68
Default Re: Cancel selection

https://wiki.sa-mp.com/wroot/index.p...ct&redirect=no

The default callback returns 0, you're returning 1. Perhaps is that?
__________________


"A server owner shouldn't be embarrassed or have fear to request help, because we're humans and we never stop learning."
Symon is online now   Reply With Quote
Old 16/02/2020, 04:58 PM   #6
None1337
Big Clucker
 
Join Date: Aug 2017
Posts: 193
Reputation: 12
Default Re: Cancel selection

Quote:
Originally Posted by Symon View Post
https://wiki.sa-mp.com/wroot/index.p...ct&redirect=no

The default callback returns 0, you're returning 1. Perhaps is that?
I changed to return 0; nothing happend.
None1337 is offline   Reply With Quote
Old 16/02/2020, 05:15 PM   #7
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 811
Reputation: 79
Default Re: Cancel selection

Quote:
Originally Posted by None1337 View Post
I changed to return 0; nothing happend.
Have you debugged it like I said to confirm the callback is not called? It is highly unlikely that it isn't being called.
Just because the pvar doesn't change doesn't mean that the callback even is getting called so, confirm it with debugging first.
__________________
Coming soon (5-21-2020):

Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Official Live Beta Release Date: 21th of May, 2020
Discord
jasperschellekens is offline   Reply With Quote
Old 16/02/2020, 05:32 PM   #8
None1337
Big Clucker
 
Join Date: Aug 2017
Posts: 193
Reputation: 12
Default Re: Cancel selection

Quote:
Originally Posted by jasperschellekens View Post
Have you debugged it like I said to confirm the callback is not called? It is highly unlikely that it isn't being called.
Just because the pvar doesn't change doesn't mean that the callback even is getting called so, confirm it with debugging first.
Yes, i did. And the callback is not called when the player is pressing ESC, only if the player select an object, then the callback is called.
None1337 is offline   Reply With Quote
Old 16/02/2020, 06:24 PM   #9
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 811
Reputation: 79
Default Re: Cancel selection

I know you can detect the esc button in ONplayerEditObject with the response
Code:
 if(response == EDIT_RESPONSE_CANCEL)
Allthough Im starting to think it's impossible with selecting an object. Not sure tho.
__________________
Coming soon (5-21-2020):

Undead Wasteland Roleplay - The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
Official Live Beta Release Date: 21th of May, 2020
Discord
jasperschellekens is offline   Reply With Quote
Old 18/02/2020, 02:38 PM   #10
None1337
Big Clucker
 
Join Date: Aug 2017
Posts: 193
Reputation: 12
Default Re: Cancel selection

Quote:
Originally Posted by jasperschellekens View Post
I know you can detect the esc button in ONplayerEditObject with the response
Code:
 if(response == EDIT_RESPONSE_CANCEL)
Allthough Im starting to think it's impossible with selecting an object. Not sure tho.
I've tried. Not called.
None1337 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching ESCAPE key on Selection Cancel Riwerry Scripting Help 1 27/02/2017 02:41 PM
Dialog help, the "cancel" kick is being called even if you dont cancel Don_Cage Scripting Help 11 23/03/2013 04:24 AM
Cancel CMD in a Situation shark Help Archive 4 09/02/2009 03:54 PM


All times are GMT. The time now is 11:59 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.