Jump to content
  • 0

pomoc Problém s if(IsPlayerAdmin(playerid))


Marks

Dotaz

Dobrý večer. Chtěl bych se zeptat, jestli někdo nemá podobnou zkušenost. Rozhodl jsem se udělat pro adminy možnost měnit čas. Když mám kód samostatný bez podmínky, jestli se jedná o admina, tak změna času v pohodě funguje, ale když přidám do kódu podmínku na admina, tak se mi náhle kód znefunkční. Nevím co dělám špatně, ale když dám kamkoliv do kódu tu podmínku, tak se to chová stejně..  Zde je kód:

 

if(!strcmp(cmdtext, "/cas", true, 4)){
new cas,text[256],admin[MAX_PLAYER_NAME];
if(!sscanf(cmdtext[5], "i",cas)){
if(cas < 25){
if(IsPlayerAdmin(playerid)){
GetPlayerName(playerid,admin,sizeof(admin));
format(text,sizeof(text),"|Sever| - Admin %s změnil čas na %d",admin,cas);
SendClientMessageToAll(0x00007777,text);
hodiny = cas;
}else{SendClientMessage(playerid,0x00007777,admintext);}
}
}
return 1;
}
Předem děkuji za odpověď. Doufám, že to není něco fatálně jednoduchého. Marks
Edited by Marks
Link to comment
Share on other sites

16 odpovědí na tuto otázku

Recommended Posts

  • 0

tá funkcia IsPlayerAdmin alebo ako to nazvať je len pre RCON

To vím, právě že se přihásím pomocí RCON a nic se neděje... to je divný

Link to comment
Share on other sites

  • 0

no hej, pretože premenné admintext je null takže SendClientMessage nič nevypíše

Proměnnou Admin text mám nadefinovanou nahoře a poté ji vypíši podle potřeby.

Link to comment
Share on other sites

  • 0

no nevidím nejak ju tam

if(!strcmp(cmdtext, "/cas", true, 4)){
new cas,text[256],admin[MAX_PLAYER_NAME];
if(!sscanf(cmdtext[5], "i",cas)){
if(cas < 25){
if(IsPlayerAdmin(playerid)){
GetPlayerName(playerid,admin,sizeof(admin));
format(text,sizeof(text),"|Sever| - Admin %s změnil čas na %d",admin,cas);
SendClientMessageToAll(0x00007777,text);
hodiny = cas;
}else{
  new admintext[256];
  format(admintext, sizeof(admintext), "Tento príkaz je len pre RCON");
  SendClientMessage(playerid,0x00007777,admintext);}
}
}
return 1;
}
Link to comment
Share on other sites

  • 0

vyskúšaj po kadiaľ ti to ide:
 

if(!strcmp(cmdtext, "/cas", true, 4)){
	print("ide 1");
	new cas,text[256],admin[MAX_PLAYER_NAME];
	if(!sscanf(cmdtext[5], "i",cas)){
		print("ide 2");
		if(cas < 25){
			print("ide 3");
			if(IsPlayerAdmin(playerid)){
				print("ide 4a");
				GetPlayerName(playerid,admin,sizeof(admin));
				format(text,sizeof(text),"|Sever| - Admin %s změnil čas na %d",admin,cas);
				SendClientMessageToAll(0x00007777,text);
				hodiny = cas;
			}else{
				print("ide 4b");
				SendClientMessage(playerid,0x00007777,admintext);
			}
		}
	}
	return 1;
}
Link to comment
Share on other sites

  • 0

Tak jsem zkusil to řešení s výpisem do konzole. V prvním případě, kdy jsem nebyl jako admin, tak mi to napsalo 1 2 3 4b, ale když jsem se přihlásil jako admin, tak mi to nevypsalo nic viz obrázek:

post-14643-0-74551000-1434221629_thumb.png

Link to comment
Share on other sites

  • 0

kurnik, nikto ma nikdy nepočúva... šak admintext je null boha tak čo má vypísať? teraz som to vyskúšal a funguje to, neviem čo tam treba riešiť :d furt o tom rozprávam a nikto ma nepočúva :d

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include "sscanf"

public OnPlayerCommandText(playerid, cmdtext[])
{
	if(!strcmp(cmdtext, "/cas", true, 4)){
		print("ide 1");
		new cas,text[256],admin[MAX_PLAYER_NAME];
		if(!sscanf(cmdtext[5], "i",cas)){
			print("ide 2");
			if(cas < 25){
				print("ide 3");
				if(IsPlayerAdmin(playerid)){
					print("ide 4a");
					GetPlayerName(playerid,admin,sizeof(admin));
					format(text,sizeof(text),"|Sever| - Admin %s změnil čas na %d",admin,cas);
					SendClientMessageToAll(0x00007777,text);
				} else {
					print("ide 4b");
					new admintext[256];
					strcat(admintext, "yolo");
					SendClientMessage(playerid,0x00007777,admintext);
				}
			}
		}
		return 1;
	}
	return 0;
}
Link to comment
Share on other sites

  • 0

 

kurnik, nikto ma nikdy nepočúva... šak admintext je null boha tak čo má vypísať? teraz som to vyskúšal a funguje to, neviem čo tam treba riešiť :d furt o tom rozprávam a nikto ma nepočúva :d

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include "sscanf"

public OnPlayerCommandText(playerid, cmdtext[])
{
	if(!strcmp(cmdtext, "/cas", true, 4)){
		print("ide 1");
		new cas,text[256],admin[MAX_PLAYER_NAME];
		if(!sscanf(cmdtext[5], "i",cas)){
			print("ide 2");
			if(cas < 25){
				print("ide 3");
				if(IsPlayerAdmin(playerid)){
					print("ide 4a");
					GetPlayerName(playerid,admin,sizeof(admin));
					format(text,sizeof(text),"|Sever| - Admin %s změnil čas na %d",admin,cas);
					SendClientMessageToAll(0x00007777,text);
				} else {
					print("ide 4b");
					new admintext[256];
					strcat(admintext, "yolo");
					SendClientMessage(playerid,0x00007777,admintext);
				}
			}
		}
		return 1;
	}
	return 0;
}

I když si okopíruji ten tvůj kód, tak mi to stále nejde, takže netuším, kde je chyba. Když nejsem adnim, tak mi to napíše nejsi admin a když se přihlásím tak to nic nedělá... :(

Link to comment
Share on other sites

  • 0

Ano, to asi bohužel už tak bude, nevíš, jak by ta chyba mohla vypadat? 

tak chyba bude len niekde v podmienke, najčastejšie to býva tak, že to vbehne do nejakého podobného príkazu ktorý ukončí public (return) a k tomuto to nedôjde, môžeš vyskúšať dať také printy aj medzi príkazy alebo časti kódu a zistíš kde sa ti to stráca

Link to comment
Share on other sites

  • 0
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0x00007777,"Tento príkaz je len pre RCON!");

Toto by mohlo šlapat

 

To je akortá jinak napsaná podmínka, mě ta podmínka funguje, akorát z nějakého důvodu se mi pak neprovede to, co je pod ní.

:facepalm: tak už jsem na to přišel, sory, že jsem nenapsal dříve, on není problém v mém kódu ale asi jsem se zase hrabal v cizím filterscriptu a kvůli tomu to nejde... Díky všem za rady 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...