SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 08/05/2007, 06:58 AM   #51
Simon
Gangsta
 
Join Date: Jan 2006
Location: New Zealand
Posts: 530
Reputation: 54
Default Re: Useful Snippets

Jail.

/jail ID (TIME REASON)

If the time you input is 0 (or less), it will put them in jail until they leave the server.

Jails on respawn. In this example it puts you in the blocked off part in Ammunation .

http://usefulsnippets.pastebin.co.uk/14166
Simon is offline   Reply With Quote
Old 10/05/2007, 09:44 PM   #52
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 662
Reputation: 0
Default Re: Useful Snippets - 2 loops in 1

2 loops in 1
This lets you do the same thing 2 loops would do, except in only 1 loop, and both the loops have a different number of loops to do.

MAX_PLAYERS = 100.
MAX_BLAH = 50.

pawn Code:
new i;
while((i < MAX_BLAH) || (i < MAX_PLAYERS)) // smaller the MAX_BLAH or MAX_PLAYERS
{
  if(i < MAX_BLAH) Something[i] = 0; // if i is smaller then MAX_BLAH only
  if(i < MAX_PLAYERS) Other[i] = false; // if i is smaller then MAX_PLAYERS only
  i++; // increase i to do next loop(s)
}
So that will only use 1 loop but can change arrays of different lengths.

Its more effecient then:
pawn Code:
for(new i; i < MAX_PLAYERS; i++) Other[i] = false;
for(new i; i < MAX_BLAH; i++) Something[i] = 0;

You can also do it for any amount of loops you want.
pawn Code:
while((i < MAX_BLAH) || (i < MAX_PLAYERS) || (i < MAX_PIE))
{
  if(i < MAX_BLAH) Something[i] = 0;
  if(i < MAX_PLAYERS) Other[i] = false;
  if(i < MAX_PIE) pies -= 90;
  i++;
}
boylett is offline   Reply With Quote
Old 11/05/2007, 06:11 AM   #53
boylett
Gangsta
 
Join Date: Jul 2006
Posts: 662
Reputation: 0
Default Re: Useful Snippets

Its the idea that you dont have to loop twice.
With 2 loops you go 1, 2, 3,... 1, 2, 3... but with one you just go 1, 2, 3... once so it takes less time.
boylett is offline   Reply With Quote
Old 18/05/2007, 06:26 AM   #54
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 79
Reputation: 0
Default Re: Useful Snippets

A taste of modifying Pawn to be more like VB, for the VB programmers out there who find it hard to adjust:

Using defines we can change the way if() works

pawn Code:
#define If if(
#define Then ){
#define EndIf }
#define Else }else{

So now we can do stuff like this:

pawn Code:
new bool:t = true;
If t == true Then
    //Do somethng
Else
  // Do Something else
EndIf

Big question: Does anyone know how to make defines work for 2 words at once, for instance if i wanted to use something like this:

Dim %1 As Integer

If that can be read by a define then it could become

new %1;

But lets say we wanted to do a float, then thats:

Dim %1 As Float

would become:

new Float:%1;

and i don't know how to accodomate that?
Sacky is offline   Reply With Quote
Old 18/05/2007, 07:09 AM   #55
Simon
Gangsta
 
Join Date: Jan 2006
Location: New Zealand
Posts: 530
Reputation: 54
Default Re: Useful Snippets

I hope this is what you want, this seems to work (read notes below though).

pawn Code:
#define Dim%1As%2Integer  new %1;

#include <a_samp>

main() {
    Dim ja As Integer
   
    ja = 3;
   
    printf("%d", ja);
}

The only problem is that if I wanted to make a As Float version, it complains about re-definition .. .

You may find this of interest, but I was unable to find out how it works or if it's doing what I'd like it to do..

Quote:
Originally Posted by Page 95, pawn-lang.pdf
There may be no space characters in the pattern. If you must match a space,
you need to use the "\32;" escape sequence. The substitution text, on the
other hand, may contain space characters. Due to the matching rules of
the macro pattern (explained below), matching a space character is rarely
needed.
Simon is offline   Reply With Quote
Old 18/05/2007, 07:33 AM   #56
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 79
Reputation: 0
Default Re: Useful Snippets

Using that throws a ton of errors my way

pawn Code:
new bool:t = true;
    If t == true Then
        Dim Test As Integer
        Test = 3;
    Else
      // Do Something else
    End If

Using your Dim define

Also no matter how hard i try i cannot get the \32 escape character to work in defines
Sacky is offline   Reply With Quote
Old 18/05/2007, 07:50 AM   #57
Simon
Gangsta
 
Join Date: Jan 2006
Location: New Zealand
Posts: 530
Reputation: 54
Default Re: Useful Snippets

Quote:
Originally Posted by Sacky
Using that throws a ton of errors my way

pawn Code:
new bool:t = true;
    If t == true Then
        Dim Test As Integer
        Test = 3;
    Else
      // Do Something else
    End If

Using your Dim define

Also no matter how hard i try i cannot get the \32 escape character to work in defines
It's crashing because you have a space in your "EndIf" ("End If"). Making your last line.. "} if(", your code with the macro definitions above compile fine on my compiler except for a warning: warning 204: symbol is assigned a value that is never used: "Test"
Simon is offline   Reply With Quote
Old 18/05/2007, 08:07 AM   #58
Sacky
Big Clucker
 
Join Date: Aug 2006
Posts: 79
Reputation: 0
Default Re: Useful Snippets

Your absolutely right! I'm sorry i was so blind about that, well thats one hurdle crossed thanks to Simon
Sacky is offline   Reply With Quote
Old 18/05/2007, 04:48 PM   #59
yo_silent2006
Little Clucker
 
Join Date: Dec 2006
Posts: 3
Reputation: 0
Default Re: Useful Snippets

sorry but now i corrected script and i post where is need

Earn By Score

Put this at script start:
pawn Code:
forward ScoreEarn(playerid);

pawn Code:
public ScoreEarn(playerid) {
if(GetPlayerScore(playerid) > 9) {
  GivePlayerMoney(playerid, 2500);
GameTextForPlayer(playerid, "~g~+2500$ ~w~for reach 10 points", 3000, 1); }
if(GetPlayerScore(playerid) > 14) {
  GivePlayerMoney(playerid, 2500);
GameTextForPlayer(playerid, "~g~+5000$ ~w~for reach 15 points", 3000, 1); }
if(GetPlayerScore(playerid) > 19) {
  GivePlayerMoney(playerid, 2500);
GameTextForPlayer(playerid, "~g~+7500$ ~w~for reach 20 points", 3000, 1); }
if(GetPlayerScore(playerid) > 29) {
  GivePlayerMoney(playerid, 2500);
GameTextForPlayer(playerid, "~g~+10000$ ~w~for reach 30 points", 3000, 1); }
if(GetPlayerScore(playerid) > 39) {
  GivePlayerMoney(playerid, 3000);
GameTextForPlayer(playerid, "~g~+13000$ ~w~for reach 40 points", 3000, 1); }
if(GetPlayerScore(playerid) > 59) {
  GivePlayerMoney(playerid, 3000);
GameTextForPlayer(playerid, "~g~+16000$ ~w~for reach 60 points", 3000, 1); }
if(GetPlayerScore(playerid) < -2) {
  GivePlayerMoney(playerid, -300);
GameTextForPlayer(playerid, "~r~-300$ ~w~for reach -2 points", 3000, 1); }
if(GetPlayerScore(playerid) < 9) {
  GivePlayerMoney(playerid, 800);
  GameTextForPlayer(playerid, "~w~No more money for n00b", 3000, 1); }
if(GetPlayerScore(playerid) > 99) {
ResetPlayerMoney(playerid);
GivePlayerWeapon(playerid, 38, 500);
GameTextForPlayer(playerid, "~g~Minigun with more ammo ~w~for reach 100 points", 3000, 1); }


 }

and now can use command:
pawn Code:
ScoreEarn(playerid)

... i use it on OnPlayerSpawn , for this is most good
yo_silent2006 is offline   Reply With Quote
Old 18/05/2007, 08:46 PM   #60
mdog
Little Clucker
 
Join Date: Nov 2006
Posts: 1
Reputation: 0
Default Re: Useful Snippets

OK, I fixed everything and had it working, but now I get this when trying red alert
Code:
K:\ROCKST~1\GTASAN~1\SAMP01~1\GAMEMO~1\src\kitchen.pwn(120) : error 017: undefined symbol "cmdtext"
K:\ROCKST~1\GTASAN~1\SAMP01~1\GAMEMO~1\src\kitchen.pwn(142) : error 017: undefined symbol "cmdtext"
mdog is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
READ Usefull Links to snippets and other -Sneaky- Help Archive 5 02/05/2009 11:22 AM


All times are GMT. The time now is 07:09 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.