SA-MP Forums Archive
How can I make this so that it can only be used once after each respawn? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How can I make this so that it can only be used once after each respawn? (/showthread.php?tid=263938)



How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 24.06.2011

if (strcmp("/gearme", cmdtext, true, 10) == 0)
{
GameTextForPlayer(playerid, "Cheat found! Multiple weapons and full armour given.", 5000, 4);
GivePlayerWeapon(playerid, 24, 700);
GivePlayerWeapon(playerid, 31, 1400);
SetPlayerArmour(playerid, 100);
return 1;
}

For instance, after a player types /gearme, he/she can't use this command again unless they respawn/die.
(It's to keep people from entering /gearme over and over and over again.)


Re: How can I make this so that it can only be used once after each respawn? - DaRealz - 24.06.2011

Quote:
Originally Posted by omgkillerzambies
Посмотреть сообщение
if (strcmp("/gearme", cmdtext, true, 10) == 0)
{
GameTextForPlayer(playerid, "Cheat found! Multiple weapons and full armour given.", 5000, 4);
GivePlayerWeapon(playerid, 24, 700);
GivePlayerWeapon(playerid, 31, 1400);
SetPlayerArmour(playerid, 100);
return 1;
}

For instance, after a player types /gearme, he/she can't use this command again unless they respawn/die.
(It's to keep people from entering /gearme over and over and over again.)
WEll... im new to this kinda, but i might be able to help.
This might be wasting space in the script to do this, but this is how i do it:
put this at the top of the script
pawn Код:
new gearme; //or some other name
Then after, for your command, do this:
pawn Код:
if (strcmp("/gearme", cmdtext, true, 10) == 0)
{
     if(gearme = 1)
     {
          SendClientMessage(playerid,0xFFFFFFFF,"You already geared youself !");
     }
     else if(gearme = 0)
     {
     GameTextForPlayer(playerid, "Cheat found! Multiple weapons and full armour given.", 5000, 4);
     GivePlayerWeapon(playerid, 24, 700);
     GivePlayerWeapon(playerid, 31, 1400);
     SetPlayerArmour(playerid, 100);
     gearme = 1; //This should make it so now, if u do it again, it will do the first thing where it says you already geared yourself
     }
     return 1;
}
then under OnPlayerDeath
pawn Код:
gearme = 0; //if you want to beable to /gearup again after you die
And on OnPlayerConnect
pawn Код:
gearme = 0;
NOT TESTED | NOT SURE IF IT WORKS


Re: How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 24.06.2011

Thanks a lot! I'll give it a go tomorrow, but I have to catch a few zzz's before work.

Thanks again, I really appreciate it.
(I'm new to this also.)


Re: How can I make this so that it can only be used once after each respawn? - linuxthefish - 24.06.2011

Quote:
Originally Posted by DaRealz
Посмотреть сообщение
WEll... im new to this kinda, but i might be able to help.
This might be wasting space in the script to do this, but this is how i do it:
put this at the top of the script
pawn Код:
new gearme; //or some other name
Then after, for your command, do this:
pawn Код:
if (strcmp("/gearme", cmdtext, true, 10) == 0)
{
     if(gearme = 1)
     {
          SendClientMessage(playerid,0xFFFFFFFF,"You already geared youself !");
     }
     else if(gearme = 0)
     {
     GameTextForPlayer(playerid, "Cheat found! Multiple weapons and full armour given.", 5000, 4);
     GivePlayerWeapon(playerid, 24, 700);
     GivePlayerWeapon(playerid, 31, 1400);
     SetPlayerArmour(playerid, 100);
     gearme = 1; //This should make it so now, if u do it again, it will do the first thing where it says you already geared yourself
     }
     return 1;
}
then under OnPlayerDeath
pawn Код:
gearme = 0; //if you want to beable to /gearup again after you die
And on OnPlayerConnect
pawn Код:
gearme = 0;
NOT TESTED | NOT SURE IF IT WORKS
Код:
new gearme;
should be
Код:
new gearme[MAX_PLAYERS];



Re: How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 24.06.2011

Ah, yeah, thanks for that Linux.
As I said, I'll give it a go tomorrow.

I appreciate it very much so.


Re: How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 24.06.2011

C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(133) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(150) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(207) : warning 211: possibly unintended assignment
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(207) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(211) : warning 211: possibly unintended assignment
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(211) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(217) : error 033: array must be indexed (variable "gearme")

Couldn't help myself, but going to bed now.


Re: How can I make this so that it can only be used once after each respawn? - linuxthefish - 24.06.2011

Quote:
Originally Posted by linuxthefish
Посмотреть сообщение
Код:
new gearme;
should be
Код:
new gearme[MAX_PLAYERS];
Quote:
Originally Posted by omgkillerzambies
Посмотреть сообщение
Ah, yeah, thanks for that Linux.
As I said, I'll give it a go tomorrow.

I appreciate it very much so.
Quote:
Originally Posted by omgkillerzambies
Посмотреть сообщение
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(133) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(150) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(207) : warning 211: possibly unintended assignment
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(207) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(211) : warning 211: possibly unintended assignment
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(211) : error 033: array must be indexed (variable "gearme")
C:\Users\Nanna\Desktop\SAMP\gamemodes\ni.pwn(217) : error 033: array must be indexed (variable "gearme")

Couldn't help myself, but going to bed now.
You should have a variable array thingy for each player, having a global variable will just allow the cmd to be used once by someone, and not everyone else.

EDIT: Colossus_'s post may be more helpful.


Re: How can I make this so that it can only be used once after each respawn? - LZLo - 24.06.2011

PHP код:
new gearme[MAX_PLAYERS]; 
PHP код:
if (strcmp("/gearme"cmdtexttrue10) == 0)
{
     if(
gearme[playerid] == 1)
     {
          
SendClientMessage(playerid,0xFFFFFFFF,"You already geared youself !");
     }
     else
     if(
gearme[playerid] == 0)
     {
     
GameTextForPlayer(playerid"Cheat found! Multiple weapons and full armour given."50004);
     
GivePlayerWeapon(playerid24700);
     
GivePlayerWeapon(playerid311400);
     
SetPlayerArmour(playerid100);
     
gearme[playerid] = 1;
     }
     return 
1;

after onplayerspawn - there is no matter why it's good to use onplayerdisconnect, because after the connection the player spawns down
PHP код:
gearme[playerid] = 0
check this out


Re: How can I make this so that it can only be used once after each respawn? - iPLEOMAX - 25.06.2011

In your CMD:
pawn Код:
if(GetPVarInt(playerid, "gearme") != 1) // 1 means its already used.
{
     SetPVarInt(playerid, "gearme", 1); //Setting to 1, which lets the cmd to detect it on next use. See Above^
     GameTextForPlayer(playerid, "Cheat found! Multiple weapons and full armour given.", 5000, 4);
     GivePlayerWeapon(playerid, 24, 700);
     GivePlayerWeapon(playerid, 31, 1400);
     SetPlayerArmour(playerid, 100);
} else SendClientMessage(playerid, 0xFFFFFFFF, "You can only use it again after death.");
In OnPlayerDeath:
pawn Код:
SetPVarInt(playerid, "gearme", 0); // Setting it to normal.
In OnPlayerDisconnect:
pawn Код:
SetPVarInt(playerid, "gearme", 0); // Setting it to normal.
Hope this helps.


Re: How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 26.06.2011

Looks like it worked, man. Thanks a lot.


Re: How can I make this so that it can only be used once after each respawn? - omgkillerzambies - 26.06.2011

@iPLEOMAX

Code worked, however when I enter /gearme it says unknown command.
It's weird though, because it still works. Like I get the guns and everything.


Re: How can I make this so that it can only be used once after each respawn? - iPLEOMAX - 26.06.2011

Quote:
Originally Posted by omgkillerzambies
View Post
@iPLEOMAX

Code worked, however when I enter /gearme it says unknown command.
It's weird though, because it still works. Like I get the guns and everything.
Add this in your cmd at the end:
pawn Code:
return 1;
I think you forgot this..