PDA

View Full Version : [Help] Minigame's


mickos
14/06/2012, 04:28 PM
Hey there,
I wanna make some minigames. I know how I can make that..
But how can I disable commands for players, when they are in a minigame?
If they try to make a command in a minigame, they will see this message: Sorry you are currectly in a minigame, /kill to leave!

And when a player leaved it they can use commands.


Thanks

BEER-Samp

Littlehelper
14/06/2012, 04:41 PM
Use a variable or boolean to detect that.
EX:

new IsInMinigame[MAX_PLAYERS] = 0;

// Under OnPlayerConnect
IsInMinigame[playerid] = 0;

// On Your Commands
if(IsInMinigame[playerid] == 1) return SendClientMessage(playerid,-1,"Type /Kill To Leave");

// /Kill ;p
CMD:kill(playerid,params[])
{
SetPlayerHealth(playerid,0);
IsInMinigame[playerid] = 0;
return 1;
}

Kindred
14/06/2012, 04:41 PM
You can easily create a variable that sets to 1 when the player is in a minigame, and you can make a stock to check if the player is in a minigame. If he is, you can return a SendClientMessage with the message.

EDIT: Looks like someone already did something similar, post above. Much better to see it then read what I wrote.

mickos
14/06/2012, 05:01 PM
You can easily create a variable that sets to 1 when the player is in a minigame, and you can make a stock to check if the player is in a minigame. If he is, you can return a SendClientMessage with the message.

EDIT: Looks like someone already did something similar, post above. Much better to see it then read what I wrote.

Can u show a example of that? And I didnt use ZCMD

mickos
15/06/2012, 06:22 PM
I didnt use ZCMD, and I didnt know exactly what u mean. Can u send an example of that what u mean? or better info

mehdi-jumper
15/06/2012, 06:33 PM
Just put your command in your minigame and remove commands in one other gamemode

mickos
15/06/2012, 06:46 PM
But when I that do, will it again work?

Elysian`
15/06/2012, 07:59 PM
http://t0.gstatic.com/images?q=tbn:ANd9GcRTuwvP2xDJkQE0CkDBc0t3Vx17W4_Oy w2nz7rAWpmUiImEJ2aXeg

Try it.

mickos
17/06/2012, 06:33 PM
Anyone they can help me?

Black Wolf
30/08/2012, 04:17 PM
Hey i used this method also put IsInMinigame[playerid] = 0; on player death but after death player is still not able to use commands its again saying use /kill

Black Wolf
30/08/2012, 04:51 PM
I have put this code



public OnPlayerCommandText(playerid, cmdtext[])
{
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
new giveplayer[MAX_PLAYER_NAME];
new playername[MAX_PLAYER_NAME];
new cmd[256];
new giveplayerid, moneys, idx, weaponid;

new tmp[256];

cmd = strtok(cmdtext, idx);

// On Your Commands
if(IsInMinigame[playerid] == 1) return SendClientMessage(playerid,-1,"Type /Kill To Leave");
/////////OTHER COMMANDS
if(strcmp(cmdtextm "/kill", true) == 0)
{
shit just a example
return 1;
}

Maybe something wrong is here

Lordzy
30/08/2012, 05:07 PM
//Create variables to detect that player is in a minigame or not.
new minigame[MAX_PLAYERS];//Created minigame variable.

CMD:kill(playerid,params[])
{
if(minigame[playerid]==1) //Detecting that if player is in a minigame or not.
{
minigame[playerid]=0; //Here minigame stats becomes to 0.
SendClientMessage(playerid, 0xFF0000, "You've quit from minigame");
SetPlayerHealth(playerid,100.00);
}
else
{
SetPlayerHealth(playerid,100.00);
return 1;
}

CMD:minigame(playerid,params[])
{
minigame[playerid]=1;
//Other functions here.
return 1;
}

Black Wolf
30/08/2012, 05:08 PM
Strcmp please

Black Wolf
30/08/2012, 05:12 PM
Is there something like this

// On Your Commands
if(IsInMinigame[playerid] == 1) return SendClientMessage(playerid,-1,"Type /Kill To Leave");
/////////OTHER COMMANDS

Its wrong but can anyone correct it so that i can just place it under onplayercommandtext and i dont need to put that
Thingy in every command i hoope you understand.

Kwarde
30/08/2012, 05:18 PM
It's posted a several times before, but since I've been asked for help, I will try to explain it.

As they said before, you should use a variable. You can either use the 0/1 integer variable, or make a boolean (true/false), since you won't need other values for the variable.

Step 1: Create the variable
Just put it somewhere on the top of the script (but it musn't be above the A_SAMP include, unless if you have defined your own MAX_PLAYERS before the A_SAMP).
Just like this:

#include <a_samp>

#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_RED 0xFF0000AA //Just some colors, it's just an example

new bool:isInMinigame[MAX_PLAYERS];

//And here is the rest of the script


Step 2: Enabling/disabling this "isInMinigame"
This is very easy. To "turn it on", set the variable to true. Otherwise put it on false.

if (!strcmp(cmdtext, "/minigundm", false)) //Example command for a minigun DM match (minigame)
{
isInMinigame[playerid] = true; //Now the server can detect that the player is in the minigame
//Set position, health and give weapons and such things. However, this can also be placed before the 'isInMinigame[playerid] = true;' part. It doesn't matter
return 1;
}

To turn it off, you could use this:

if (!strcmp(cmdtext, "/exitminigame", false)) //Example to quit the minigame
{
isInMinigame[playerid] = false; //Out of it.
SetPlayerHealth(playerid, -1); //Example to kill the player, so he'll respawn
return 1;
}


Step 3: Use this variable
You'll simply need an IF statement for this.
if (isInMinigame[playerid]) - This will return TRUE when the boolean is TRUE, otherwise it'll return FALSE.
Right now, I'll show you the commands I just created, but now with this IF statement

if (!strcmp(cmdtext, "/minigundm", false)) //Example command for a minigun DM match (minigame)
{
if (isInMinigame[playerid]) //If the 'isInMinigame[playerid]' is true
return SendClientMessage(playerid, 0xFF0000AA, "* You are in a minigame already!"); //Display this message and don't run the command futher.
isInMinigame[playerid] = true;
return 1;
}

if (!strcmp(cmdtext, "/exitminigame", false))
{
if (!isInMinigame[playerid]) //If the 'isInMinigame[playerid]' is NOT true (so if it's false)
return SendClientMessage(playerid, 0xFF0000AA, "* You aren't in a minigame at the moment!"); //Don't run the command futher and display this message
isInMinigame[playerid] = false;
SetPlayerHealth(playerid, -1);
return 1;
}


So, if you want restrictions of commands when people are in a minigame, you could simply add the next text into the command, right after the first barrack and BEFORE all the stuff, like SetPlayerPos:
if (isInMinigame[playerid]) return SendClientMessage(playerid, 0xFF0000AA, "* You must exit the minigame first before using this command!");

I seriously hope you get it now, since it took some time to create this small tutorial.

Kind regards,
Kwarde

p.s.
Please don't use the BBCodes when using a PAWN code. Use the PAWN BBcode instead, please.
So, it's not this:
//PAWN code
//PAWN code
But this:
[pawn]//PAWN code[/code]
//PAWN code
Why this is - Because it reads the code easier because of the highlighting. Thanks in advance.

Black Wolf
31/08/2012, 03:39 AM
Thanks kwarde its working but exitminigame command is also not working maybe becoz i put this

[pawn]
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[128];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
new giveplayer[MAX_PLAYER_NAME];
new playername[MAX_PLAYER_NAME];
new cmd[256];
new giveplayerid, moneys, idx, weaponid;

new tmp[256];

cmd = strtok(cmdtext, idx);

if (isInMinigame[playerid]) return SendClientMessage(playerid, 0xFF0000AA, "* You must exit the minigame first before using this command!");

other commands goes on[/code]

Becoz putting this in every command will suck too much time as i have got too many commands in Gamemode.

Kwarde
31/08/2012, 02:35 PM
About the CODE and PAWN; you must close the PAWN code not with [/code] but with [/pawn].
You did:


That code
[/code]

Instead of

[pawn]
That code


;)

And I see the problem:
if (isInMinigame[playerid]) return SendClientMessage(playerid, 0xFF0000AA, "* You must exit the minigame first before using this command!");
It's in the OnPlayerCommandText before any command; Now every command can't be used then 'isInMinigame[playerid]' is 'true'. Please remove it (it's under the "cmd = strtok(cmdtext, idx);") and put it in every command you want to be unavaible when in a minigame. Command that may be used in a minigame, musn't have it off course. Do you get what I mean?

Black Wolf
31/08/2012, 02:47 PM
Yes i get but there i too many commands is their any other way so that i dont need to put it in every command

Kwarde
31/08/2012, 02:54 PM
Well, you could try this (within OnPlayerCommandText, without using it in other commands):


new allowedCommands[][] = { //You can add more off course
"/help", "/kill", "/exitminigame"
};

new index = -1;
while (index <= sizeof(allowedCommands))
{
index++;
if (!strcmp(cmdtext, allowedCommands[index]) && isInMinigame[playerid]) //Performed command is not in the 'allowedCommands' list, and the player is in a minigame, then:
return SendClientMessage(playerid, 0xFF0000AA, "* You aren't allowed to use this command while being in a minigame!");
}

I'm using something similar so it should work. You should try this. If it doesn't work, please send me the source of your gamemode (either the .pwn file, or paste it in pastebin) over PM and I'll add it for you (and test it if I have all the includes and/or plugins you use) and then I'll send it back. But only if you don't seem to get it to work.

Black Wolf
31/08/2012, 03:14 PM
Well i got these errors


C:\Users\Bhupesh\Desktop\mygm.pwn(1902) : error 033: array must be indexed (variable "allowedCommands")
C:\Users\Bhupesh\Desktop\mygm.pwn(1905) : error 048: array dimensions do not match


On the lines

while (index <= allowedCommands) ///Its line NO 1902
{
index++;
if (!strcmp(cmdtext, allowedCommands) && isInMinigame[playerid]) //Its line no 1905 //Performed command is not in the 'allowedCommands' list, and the player is in a minigame, then:

Kwarde
31/08/2012, 03:19 PM
I already fixed that; check my previous post. Btw, I am now running some tests.

EDIT: Wait a bit please, all the commands are returning 0 now. (SERVER: Unknown command)

Black Wolf
31/08/2012, 03:27 PM
Yea i see the commands are not working .

Kwarde
31/08/2012, 03:40 PM
I don't get it to work properly yet. You should just use the method with posting the check in all the commands you don't want to be avaible when someone is in a minigame. Either do that, or wait while I try to fix this problem I just created (WARNING! I'm not sure if I'm gonna be able to fix it, since I tried many ways already. However, I won't give up yet -but if it's taking too much time, I will-)

Black Wolf
31/08/2012, 03:42 PM
I willl be waiting till you fix it :)

Kwarde
31/08/2012, 03:44 PM
.elihw gnoool a ekat annog s'ti spahreP - ); dmin ni taht peek tsum ouy ,ti xif ot elba eb annog m'I fi erus ton m'I tuB

(But I'm not sure if I'm gonna be able to fix it, you must keep that in mind ;) - Perhaps it's gonna take a looong while.)

Black Wolf
31/08/2012, 03:48 PM
Ok i will wait xd because putting that in all the commands will also take a long time xD :P i will keep checking this thread.

Kwarde
31/08/2012, 03:49 PM
You don't need to do that; If I fix this bug (or if I don't) I'll immediately send you a visitor message ;)

Black Wolf
31/08/2012, 03:52 PM
Thnx :D Rep+ :)

Kwarde
31/08/2012, 04:25 PM
So far, no luck.
This is the gamemode I am using;

#include <a_samp>

new bool:isInTestMode[MAX_PLAYERS];

new forbiddenCommands[][] = {
"/entertest",
"/test3",
"/test4"
};

main() return 1;

public OnGameModeInit()
{
AddPlayerClass(281,1759.0189,-1898.1260,13.5622,266.4503,-1,-1,-1,-1,-1,-1);
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
printf("[DEBUG] CMDTEXT(1.A); %s", cmdtext);
if (!mayUseCommand(playerid, cmdtext))
{
printf("[DEBUG] CMDTEXT(1.B); %s", cmdtext);
SendClientMessage(playerid, 0xFF0000AA, "You aren't allowed to use this command while being in the test modus!");
return 1;
}
printf("[DEBUG] CMDTEXT(2.A); %s", cmdtext);

if (!strcmp(cmdtext, "/entertest", false))
{
isInTestMode[playerid] = true;
SendClientMessage(playerid, 0x00FF00AA, "Test mode entered");
return 1;
}
if (!strcmp(cmdtext, "/leavetest", false))
{
isInTestMode[playerid] = false;
SendClientMessage(playerid, 0x00FF00AA, "Test mode left");
return 1;
}
if (!strcmp(cmdtext, "/test1", false))
{
SendClientMessage(playerid, 0xFFFFFFAA, "Test 1");
return 1;
}
if (!strcmp(cmdtext, "/test2", false))
{
SendClientMessage(playerid, 0xFFFFFFAA, "Test 2");
return 1;
}
if (!strcmp(cmdtext, "/test3", false))
{
SendClientMessage(playerid, 0xFFFFFFAA, "Test 3");
return 1;
}
if (!strcmp(cmdtext, "/test4", false))
{
SendClientMessage(playerid, 0xFFFFFFAA, "Test 4");
return 1;
}
return SendClientMessage(playerid, 0xAFAFAFAA, "This command doesn't exist!");
}

stock mayUseCommand(playerid, cmdtext[])
{
printf("[DEBUG] MUC(1); playerid=%d,cmdtext=%s", playerid, cmdtext);
static index = -1, bool:allowed = true;

while (index <= sizeof(forbiddenCommands))
{
printf("[DEBUG] MUC(2); index=%d", index);
index++;
if (isInTestMode[playerid])
{
printf("[DEBUG] MUC(3); IITM[%d]=TRUE", playerid);
if (!strcmp(cmdtext, forbiddenCommands[index]))
{
printf("[DEBUG] MUC(4); cmdtext=%s,fC[%d]=%s (SET allowed=false)", cmdtext, index, forbiddenCommands[index]);
allowed = false;
}
else printf("[DEBUG] MUC(3); IITM[%d]=FALSE", playerid);
}
else printf("[DEBUG] MUC(4); cmdtext=%s", cmdtext);
}
printf("[DEBUG] MUC(5); ALLOWED=%d", allowed);
return allowed;
}

And this is the debug output:

[16:35:18] [DEBUG] CMDTEXT(1.A); /test1
[16:35:18] [DEBUG] MUC(1); playerid=0,cmdtext=/test1
[16:35:18] [DEBUG] MUC(2); index=-1
[16:35:18] [DEBUG] MUC(4); cmdtext=/test1
[16:35:18] [DEBUG] MUC(2); index=0
[16:35:18] [DEBUG] MUC(4); cmdtext=/test1
[16:35:18] [DEBUG] MUC(2); index=1
[16:35:18] [DEBUG] MUC(4); cmdtext=/test1
[16:35:18] [DEBUG] MUC(2); index=2
[16:35:18] [DEBUG] MUC(4); cmdtext=/test1
[16:35:18] [DEBUG] MUC(2); index=3
[16:35:18] [DEBUG] MUC(4); cmdtext=/test1
[16:35:18] [DEBUG] MUC(5); ALLOWED=1
[16:35:18] [DEBUG] CMDTEXT(2.A); /test1
[16:35:19] [DEBUG] CMDTEXT(1.A); /test2
[16:35:19] [DEBUG] MUC(1); playerid=0,cmdtext=/test2
[16:35:19] [DEBUG] MUC(5); ALLOWED=1
[16:35:19] [DEBUG] CMDTEXT(2.A); /test2
[16:35:20] [DEBUG] CMDTEXT(1.A); /test3
[16:35:20] [DEBUG] MUC(1); playerid=0,cmdtext=/test3
[16:35:20] [DEBUG] MUC(5); ALLOWED=1
[16:35:20] [DEBUG] CMDTEXT(2.A); /test3
[16:35:20] [DEBUG] CMDTEXT(1.A); /test4
[16:35:20] [DEBUG] MUC(1); playerid=0,cmdtext=/test4
[16:35:20] [DEBUG] MUC(5); ALLOWED=1
[16:35:20] [DEBUG] CMDTEXT(2.A); /test4
[16:35:22] [DEBUG] CMDTEXT(1.A); /entertest
[16:35:22] [DEBUG] MUC(1); playerid=0,cmdtext=/entertest
[16:35:22] [DEBUG] MUC(5); ALLOWED=1
[16:35:22] [DEBUG] CMDTEXT(2.A); /entertest
[16:35:22] [DEBUG] CMDTEXT(1.A); /entertest
[16:35:22] [DEBUG] MUC(1); playerid=0,cmdtext=/entertest
[16:35:22] [DEBUG] MUC(5); ALLOWED=1
[16:35:22] [DEBUG] CMDTEXT(2.A); /entertest
[16:35:23] [DEBUG] CMDTEXT(1.A); /test1
[16:35:23] [DEBUG] MUC(1); playerid=0,cmdtext=/test1
[16:35:23] [DEBUG] MUC(5); ALLOWED=1
[16:35:24] [DEBUG] CMDTEXT(2.A); /test1
[16:35:24] [DEBUG] CMDTEXT(1.A); /test2
[16:35:24] [DEBUG] MUC(1); playerid=0,cmdtext=/test2
[16:35:24] [DEBUG] MUC(5); ALLOWED=1
[16:35:24] [DEBUG] CMDTEXT(2.A); /test2
[16:35:25] [DEBUG] CMDTEXT(1.A); /test3
[16:35:25] [DEBUG] MUC(1); playerid=0,cmdtext=/test3
[16:35:25] [DEBUG] MUC(5); ALLOWED=1
[16:35:25] [DEBUG] CMDTEXT(2.A); /test3
[16:35:26] [DEBUG] CMDTEXT(1.A); /test4
[16:35:26] [DEBUG] MUC(1); playerid=0,cmdtext=/test4
[16:35:26] [DEBUG] MUC(5); ALLOWED=1
[16:35:26] [DEBUG] CMDTEXT(2.A); /test4
[16:35:28] [DEBUG] CMDTEXT(1.A); /leavetest
[16:35:28] [DEBUG] MUC(1); playerid=0,cmdtext=/leavetest
[16:35:28] [DEBUG] MUC(5); ALLOWED=1
[16:35:28] [DEBUG] CMDTEXT(2.A); /leavetest
[16:35:28] [DEBUG] CMDTEXT(1.A); /leavetest
[16:35:28] [DEBUG] MUC(1); playerid=0,cmdtext=/leavetest
[16:35:28] [DEBUG] MUC(5); ALLOWED=1
[16:35:28] [DEBUG] CMDTEXT(2.A); /leavetest
[16:35:30] [DEBUG] CMDTEXT(1.A); /test1
[16:35:30] [DEBUG] MUC(1); playerid=0,cmdtext=/test1
[16:35:30] [DEBUG] MUC(5); ALLOWED=1
[16:35:30] [DEBUG] CMDTEXT(2.A); /test1
[16:35:31] [DEBUG] CMDTEXT(1.A); /test2
[16:35:31] [DEBUG] MUC(1); playerid=0,cmdtext=/test2
[16:35:31] [DEBUG] MUC(5); ALLOWED=1
[16:35:31] [DEBUG] CMDTEXT(2.A); /test2
[16:35:31] [DEBUG] CMDTEXT(1.A); /test3
[16:35:31] [DEBUG] MUC(1); playerid=0,cmdtext=/test3
[16:35:31] [DEBUG] MUC(5); ALLOWED=1
[16:35:31] [DEBUG] CMDTEXT(2.A); /test3
[16:35:32] [DEBUG] CMDTEXT(1.A); /test4
[16:35:32] [DEBUG] MUC(1); playerid=0,cmdtext=/test4
[16:35:32] [DEBUG] MUC(5); ALLOWED=1
[16:35:32] [DEBUG] CMDTEXT(2.A); /test4

At 16:35:22, I entered this test mode. At 16:35:25 I used the command and it returned ALLOWED=1, while it's in the forbidden commands, and while I had the test modus ON. I'm now adding more debug lines, and I may see what could be wrong.

Kwarde
31/08/2012, 08:48 PM
UPDATE:
I am now trying to use strfind instead of strcmp. So far, the commands that may not work while in the test modus (or in your case, when someone's in the minigame), only work when you're out of that modus. Otherwise you'll get a message. The only thing not working right now, is that the commands that SHOULD work while in that modus, will return a "SERVER: Unknown command" (even though I've defined another "Unknown command" message), so something is doing weird. But it's almost done I hope, it's going much better atm! :)

Black Wolf
01/09/2012, 07:07 AM
Keep going gud! :D

Kwarde
29/09/2012, 10:10 PM
Sorry, I couldn't seem to get this fixed. I gave up. :(

Black Wolf
30/09/2012, 03:19 AM
Sorry, I couldn't seem to get this fixed. I gave up. :(

Np brother :)

M3mPHi$_S3
30/09/2012, 05:11 AM
new Isplayerinminigame[MAX_PLAYERS]

Now you can use this like when rthey are in mini game like

CMD:ls(playerid, params][)
{
if(isplayerinminigame[playerid] == 1) return SendClientMessage(playerid,-1,"Cant use any commands while playing mini-game :");
CMD:kill(playerid,params[])
{
SetPlayerHealth (playerid,0);
isplayerinminigame[playerid] == 0;
return 1;
}



}
[/PAWN]

Black Wolf
30/09/2012, 05:16 AM
You did not read the topic clearly.

and i have already fixed by some different method.