samp.directory
← Scripts et bibliothèques

hreesang/samp-pp-dialogs

An open.mp/SA:MP library that provides functions to display dialogs with asynchronous responses

Bibliothèque★ 8mis à jour mars 2023Pas de licencePawnsampctl
Ouvrir sur GitHub

Ce dépôt n’a pas de fichier de licence. Il est public en lecture, mais cela ne donne pas à lui seul le droit de le réutiliser.

Installer avec sampctl

sampctl package install hreesang/samp-pp-dialogs

Lance ceci dans le dossier de ton projet. sampctl télécharge le paquet et ce dont il dépend.

L’essayer dans le compilateur Pawn →

Ajoute ses fichiers include, avec les bibliothèques dont il dépend, au compilateur Pawn de ton navigateur, prêts à être inclus dans un script.

README.md

samp-pp-dialogs

Installation

Simply install to your project:

sampctl install Hreesang/samp-pp-dialogs

Include in your code and begin using the library:

#include <pp_dialogs>

It is recommended that you set a PawnPlus version explicitely on your pawn.json (preferibly the latest) to avoid always downloading the latest one.

If you don't use sampctl, just download the pp_dialogs.inc include and drop it to your includes/ folder, and then download the PawnPlus plugin and include from here.

While you're on it and if you don't use PawnPlus yet, you should check it out!

Usage

This include provides one single function

Task:ShowPlayerAsyncDialog(playerid, DIALOG_STYLE:style, const caption[], const info[], const button1[], const button2[] = "");

This will show the dialog and await for the response, which will pause the current script's execution and return the yielded value to the last public function (or 0 if it wasn't set). When it's responded to, the response details will be inside the responses[E_ASYNC_DIALOG] array. If another dialog gets shown while awaiting, the Task will be discarded with any following code that was to be resumed.

For comfortability, it also provides support for PawnPlus strings:

ShowPlayerDialogStr(playerid, dialogid, DIALOG_STYLE:style, ConstString:caption, ConstString:info, ConstString:button1, ConstString:button2 = ConstString:STRING_NULL);
Task:ShowPlayerAsyncDialogStr(playerid, DIALOG_STYLE:style, ConstString:caption, ConstString:info, ConstString:button1, ConstString:button2 = ConstString:STRING_NULL);

Example

static TestAsyncDialog(playerid)
{
	yield 1;
	new Task:t = ShowPlayerAsyncDialog(
		playerid,
		DIALOG_STYLE_MSGBOX,
		"Hello World | Async Dialog",
		"Through TestAsyncDialog, the World says \"Hello World.\"",
		"Hi!",
		"Ok!"
	);
	new responses[E_ASYNC_DIALOG];
	await_arr(responses) t;

	new string[144];
	format(
		string,
		sizeof(string),
		"Script: TestAsyncDialog - Response: %s",
		responses[E_ASYNC_DIALOG_RESPONSE] ? "true" : "false"
	);
	SendClientMessage(playerid, -1, string);
}

static TestAsyncDialogStr(playerid)
{
	yield 1;
	new Task:t = ShowPlayerAsyncDialogStr(
		playerid,
		DIALOG_STYLE_MSGBOX,
		str_new_static("Hello World | Async Dialog Str"),
		str_new_static("Through TestAsyncDialogStr, the World says \"Hello World.\""),
		str_new_static("Hi!"),
		str_new_static("Ok!")
	);
	new responses[E_ASYNC_DIALOG];
	await_arr(responses) t;

	new string[144];
	format(
		string,
		sizeof(string),
		"Script: TestAsyncDialogStr - Response: %s",
		responses[E_ASYNC_DIALOG_RESPONSE] ? "true" : "false"
	);
	SendClientMessage(playerid, -1, string);
}

What's the Difference?

You might be wondering that because this library is quite similar with async-dialogs. Well, I have this library privately in my script because of some preference reasons. I don't find comfortable with the async-dialogs enumerator naming convention, and also there's a bug in there that messes up my script dialog IDs. I suspected that the bug happens because I have some libraries which hook the dialog functions and callback in my script, and the async-dialogs doesn't trigger the hooks because it directly calls the native.

Thanks

  • IS4Code for PawnPlus, which allows this and even more awesome stuff
  • AGraber for async-dialogs, most of the concept is from there, even the README.md is from there
  • Y-Less for Pre-Hooks snippets

dialogopenmppawnplussamp

Cette page est construite à partir de ce que GitHub publie sur le dépôt. samp.directory n’héberge pas le code. Signaler un problème avec cette fiche

hreesang/samp-pp-dialogs : Bibliothèque SA-MP | samp.directory