Raised This Month: $32 Target: $400
 8% 

experimenting with menus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pr0mers
Junior Member
Join Date: May 2020
Old 07-28-2021 , 15:04   experimenting with menus
Reply With Quote #1

i have some questions:
i displayed menu to 2 players and when they both choose dont they trigger menuaction_end?
is it very very important to delete menu? do they automatically delete it if its open twice or using
very memory.

because this isn't xy question i am saying what i try to accomplish right away (i am trying to make rock paper scissors game)

What i am saying is i spent tooooo much trying to get menu end (its very pain in the ...... ) when player disconnects or cancels menu with sth like !store, !map or pressing number 9 which is exit

plugin is WORKING but i did printtochatall when menu ends etc but it doesn't seem to be ending. and i am very afraid of plugin using too much memory or sth which affects server's performance badly.

(edit:i wrote what that line mines in //)

code is here:
Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "pr0mers"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>
#include <sdktools>
int kisiler[MAXPLAYERS + 1]; // wanttoplay wtih player
int secim[MAXPLAYERS + 1]; //choose of Rocl, paper, scissors


public Plugin myinfo = 
{
	author = "pr0mers",
	description = "tas kagit makas plugini",
	version = PLUGIN_VERSION
};

public void OnPluginStart()
{
	RegConsoleCmd("sm_tkm", taskagitmakas); // tkm = rps = rock paper scissors
	RegConsoleCmd("sm_tkmdebug", tkmdebugla);
}
public Action tkmdebugla(int client,int args){
	for (int i = 1; i < MaxClients; i++)
	{
		if(IsClientInGame(i)==true)
		{
			PrintToChat(client, "player: %d , wanttoplaywith: %d , choose : %d", i, kisiler[i], secim[i]);
		}
	}
}
public Action taskagitmakas(int client,int args){
	int baslatankisi = client;
	char text1[512];
    char text0[512];
    GetCmdArg(1, text1, sizeof(text1));
	int playersConnected = GetMaxClients();
    int bulduk = 0;
	for (int i = 1; i < playersConnected; i++)
	    {
	        if(IsClientInGame(i)==true)
	        {
	            GetClientName(i, text0, sizeof(text0));
	            if (StrContains(text0, text1, false)!=-1){
	            	if(bulduk!=0){
	            		return;
	            	}
	           		bulduk = i;
	           	}
	        }
	}
	if(bulduk == 0){
		return;
	}
	int asilhedef = bulduk;
	for (int i = 1; i < MaxClients; i++)
	{
	    if(IsClientInGame(i)==true)
		{
		    if(kisiler[i]==bulduk){
	        	PrintToChat(client, "Zaten baska biriyle oynuyor sonra tekrar dene"); // already playing with omsone
	        	return;
          	}
          	if(kisiler[i]==client){
	        	PrintToChat(client, "Zaten baska biriyle oynuyorsun!"); // you are already playing with someone
	        	return;
          	}
          	
	    }
	}
	if(kisiler[bulduk]!=0){
		PrintToChat(client, "Zaten baska biriyle oynuyor sonra tekrar dene");//already playing withsomone
		return;
	}
	PrintToChat(asilhedef, "%N adlı kişi sana taş kağıt makasda meydan okudu kabul edicekmisin?", baslatankisi); // someone challanged you
	PrintToChat(baslatankisi, "%N adlı kişiye meydan okundu.", asilhedef);//you challanged him
	kisiler[baslatankisi] = asilhedef;

	evethayirmenu(baslatankisi,asilhedef);//do you accept or dont menu
}
public evethayirmenu(int baslatan,int hedef){
	Menu menu = new Menu(Menu_Callback);
	menu.SetTitle("%N adlı kişi sana taş kağıt makasda meydan okudu kabul edecekmisin?",baslatan);//title do you accept
	menu.AddItem("evet", "Evet");//yes
	menu.AddItem("hayır", "Hayır");//no
	menu.Display(hedef, 60);
	return;
}
public int Menu_Callback(Menu menu, MenuAction action,int param1,int param2){
	switch (action){
		case MenuAction_Select:
		{
			int kisi2 = 0;
			for (int i = 1; i < MaxClients; i++)
			{
				if(IsClientInGame(i)==true)
				{
				    if(kisiler[i]==param1){
				    	kisi2 = i;
				    	break;
				    }
				           	
				}
			}
			if(IsClientInGame(kisi2)==false){
                               /* it didn't have gotten in this function ever might be something wrong*/
				PrintToChat(param1, "Karşıdaki oyuncu oyundan çıktı!");//he left the game 
				kisiler[kisi2] = 0;
				kisiler[param1] = 0;	
				delete menu;				
				return;
			}	    
			if(IsClientInGame(param1)==false){
                                 /* it didn't have gotten in this function ever might be something wrong*/
				PrintToChat(kisi2, "Karşıdaki oyuncu oyundan çıktı!");
				kisiler[kisi2] = 0;
				kisiler[param1] = 0;
				delete menu;				
				return;
			}	    
			char item[64];
			menu.GetItem(param2, item, sizeof(item));
			if(StrEqual(item,"evet")){
				kisiler[param1] = kisi2;
				taskagitmakasmenusu(param1,kisiler[param1]);
			}
			else{
			    kisiler[kisi2] = 0;
				PrintToChatAll("%N taş kağıt makası kabul etmedi! Korkak tavuk!", param1); // scaredy cat didn't accept the challange
				
			}
		}
		case MenuAction_End:
		{			
                        //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
			delete menu;
		}
		case MenuAction_Cancel:
		{
			int kisi2 = 0;
			for (int i = 1; i < MaxClients; i++)
			{
				if(IsClientInGame(i)==true)
				{
				    if(kisiler[i]==param1){
				    	kisi2 = i;
				    	break;
				    }
				           	
				}
			}
			kisiler[kisi2] = 0;			 
		}
		
	}
}
public void taskagitmakasmenusu(int hedef,int yapan){
	Menu menus = new Menu(Menu_Callback2);
	menus.SetTitle("Taş Kağıt Makas Menüsü");
	menus.AddItem("tas", "Taş");
	menus.AddItem("kagit", "Kağıt");
	menus.AddItem("makas", "Makas");
	menus.Display(hedef, 60);
	menus.Display(yapan, 60);
	
}
public int Menu_Callback2(Menu menu, MenuAction action,int param1,int param2){
	switch (action){
		case MenuAction_Select:
		{
			int kisi2 = kisiler[param1];
			if(IsClientInGame(kisi2)==false){
                                //same with everything something should be wrong it have never came this function
				PrintToChat(param1, "Karşıdaki oyuncu oyundan çıktı!");
				secim[param1] = 0;
				secim[kisiler[param1]] = 0;
				kisiler[kisiler[param1]] = 0;
				kisiler[param1] = 0;
				delete menu;				
				return;
			}	    
			if(IsClientInGame(param1)==false){
                                //saaaame
				PrintToChat(kisi2, "Karşıdaki oyuncu oyundan çıktı!");
				secim[param1] = 0;
				secim[kisiler[param1]] = 0;
				kisiler[kisiler[param1]] = 0;
				kisiler[param1] = 0;
				delete menu;				
				return;
			}	   
			char item[64];
			menu.GetItem(param2, item, sizeof(item));
			//PrintToChatAll("%d", param1);
			
			if(StrEqual(item,"tas")){
				
				secim[param1] = 1;
			}
			if(StrEqual(item,"kagit")){
				
				secim[param1] = 2;
			}
			if(StrEqual(item,"makas")){
			
				secim[param1] = 3;
			}	
			
			secimyapildi(param1);
		}
		case MenuAction_End:
		{
                        //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
			if(secim[param1]!= 0 && secim[kisiler[param1]]!=0){

				delete menu;					
			}
			if(param1 != MenuEnd_Selected){
				secim[param1] = 0;
				secim[kisiler[param1]] = 0;
				kisiler[kisiler[param1]] = 0;
				kisiler[param1] = 0;
				delete menu;
			}
		}
		case MenuAction_Cancel:
		{
			secim[param1] = 0;
			secim[kisiler[param1]] = 0;
			kisiler[kisiler[param1]] = 0;
			kisiler[param1] = 0;
			 
		}
		
	}
}
public void secimyapildi(int client){
	int baslatansecim = secim[client];
	int hedefsecim = secim[kisiler[client]];
	char text1[256];
   	char text0[256];
	GetClientName(client, text1, sizeof(text1));
	GetClientName(kisiler[client], text0, sizeof(text0));
	if(baslatansecim != 0 && hedefsecim!=0){
		char bassec[10];
		char hedsec[10];
		if(baslatansecim == 1){
			bassec = "Taş";
		}
		if(baslatansecim== 2){
			bassec = "Kağıt";
		}
		if(baslatansecim == 3){
			bassec = "Makas";
		}
		if(hedefsecim == 1){
			hedsec = "Taş";
		}
		if(hedefsecim== 2){
			hedsec = "Kağıt";
		}
		if(hedefsecim == 3){
			hedsec = "Makas";
		}
                //below is this chose this, this chose this this is the winner blah blah blah
		if(hedefsecim==baslatansecim){
			PrintToChatAll("Berabere! 2 Oyuncununda seçimi %s idi", hedsec);
			
		}
		if(hedefsecim==1 && baslatansecim==2){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text1, text1, bassec, text0, hedsec);
		}
		if(hedefsecim==1 && baslatansecim==3){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text0, text0, hedsec, text1, bassec);
		}
		if(hedefsecim==2 && baslatansecim==1){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text0, text0, hedsec, text1, bassec);
		}
		if(hedefsecim==2 && baslatansecim==3){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text1, text1, bassec, text0, hedsec);
		}
		if(hedefsecim==3 && baslatansecim==1){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text1, text1, bassec, text0, hedsec);
		}
		if(hedefsecim==3 && baslatansecim==2){
			PrintToChatAll("Kazanan :%s-%s in seçimi %s, %s in seçimi %s idi", text0, text0, hedsec, text1, bassec);
		}
		secim[client] = 0;
		secim[kisiler[client]] = 0;
		kisiler[kisiler[client]] = 0;
		kisiler[client] = 0;
		
	}
	else{
		//PrintToChatAll("herkes secmedi");//not both palyer selected
	}
}
public OnClientDisconnect(int client){
		secim[client] = 0;
		secim[kisiler[client]] = 0;
		kisiler[kisiler[client]] = 0;
		kisiler[client] = 0;
}
i am too tilted, i am sorry but i spent waay much time in this
__________________
My Steam
My Youtube Channel
My Github
My Discord : pr0mers#0369
-I always write unnecessary plugins-
(you can tell me better ways to do something, thank you)

Last edited by pr0mers; 07-28-2021 at 15:18. Reason: // everything
pr0mers is offline
jugule
AlliedModders Donor
Join Date: Apr 2020
Old 07-29-2021 , 07:42   Re: experimenting with menus
Reply With Quote #2

case MenuAction_End: CloseHandle(menu)

if(IsClientInGame(kisi2)==false) -> if(IsClientInGame(kisi2))

delete menu; -> CloseHandle(menu)

if(IsClientInGame(i)==true) -> if(IsClientInGame(i))
jugule is offline
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

Forum Jump


All times are GMT -4. The time now is 08:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode