SA-MP Forums Archive
Little coding questions - For general minor queries 5 - 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)
+--- Thread: Little coding questions - For general minor queries 5 (/showthread.php?tid=30938)



Re: Little coding questions - For general minor queries 5 - Cedimedi - 15.11.2009

How can i make when (for example) i type /cardm that the commands /fix are disabled?



Re: Little coding questions - For general minor queries 5 - dice7 - 15.11.2009

pawn Код:
new CarFix = 0;
public OnPlayerCommandText(playerid, cmdtext[])
{
 
    if (strcmp("/cardm", cmdtext, true, 10) == 0)
    {
      CarFix = 1;
        return 1;
    }
    if (strcmp("/fix", cmdtext, true, 10) == 0)
    {
      if (CarFix == 1) return SendClientMessage(playerid, color, "can't use that here");
      //other code
    }
    return 0;
}



Re: Little coding questions - For general minor queries 5 - David22 - 16.11.2009

Is it possible to use regular expressions (regexes) with SA-MP?


Re: Little coding questions - For general minor queries 5 - Cedimedi - 16.11.2009

Quote:
Originally Posted by dice7
pawn Код:
new CarFix = 0;
public OnPlayerCommandText(playerid, cmdtext[])
{
 
    if (strcmp("/cardm", cmdtext, true, 10) == 0)
    {
      CarFix = 1;
        return 1;
    }
    if (strcmp("/fix", cmdtext, true, 10) == 0)
    {
      if (CarFix == 1) return SendClientMessage(playerid, color, "can't use that here");
      //other code
    }
    return 0;
}
Thank you very mutch!

Just another question... when the player die, how to check if he was in "/cardm" and that it respawn him there and if he wasn't there just spawn normal?

greetz


Re: Little coding questions - For general minor queries 5 - dice7 - 16.11.2009

You then use a slightly modified version

pawn Код:
new IsInCarDM[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[])
{
 
    if (strcmp("/cardm", cmdtext, true, 10) == 0)
    {
      IsInCarDM[playerid] = 1;
        return 1;
    }
    if (strcmp("/fix", cmdtext, true, 10) == 0)
    {
      if (IsInCarDM[playerid] == 1) return SendClientMessage(playerid, color, "can't use that here");
      //other code
    }
    return 0;
}

public OnPlayerDeath(playerid, killerid, reason)
{
  if(IsInCarDM[playerid] == 1) SendClientMessage(playerid, color, "player was in car dm");
  return 1;
}



Re: Little coding questions - For general minor queries 5 - [WS]Hyper - 16.11.2009

Isn't it better to replace the new IsInCarDM[MAX_PLAYERS]; for a bool? Or will it not make much difference..? It's just that you only have 1 and 0 so..


Re: Little coding questions - For general minor queries 5 - [HLF]Southclaw - 16.05.2010

yes, it's called, not surprisingly, 'OnPlayerText'

params:
playerid - player who typed text
text[] - text they entered


Re: Little coding questions - For general minor queries 5 - dice7 - 16.05.2010

Every public function can be called script wise, since they're only functions and nothing else
Examples:

pawn Code:
public OnPlayerConnect(playerid)
{
    OnPlayerCommandText(playerid, "/commands"); //will simulate that the player typed /commands
    OnPlayerText(playerid, "hello"); //will simulate that the player typed hello (im not sure if the text is displayed in chat)
    OnPlayerPickUpPickup(playerid, 3); //will tell the script that the player pickup a pickup with the id 3 (of course the player didn't)
    return 1;



Re: Little coding questions - For general minor queries 5 - Apply - 16.05.2010

Whenever someone types in the clan chat it says the thing he wrote both on the public chat & on the clan chat, tried to fix it but couldnt do it, here is the onplayertext of the clan system-
Code:
public OnPlayerText(playerid, text[])
{
  new Name[24];
	GetPlayerName(playerid,Name,24);
	format(file,256,userfiles,Name);
	ClanName = dini_Get(file,"Clan");

  if(text[0] == '!')
	{
		if(InMuteC[playerid] == 1){ SendClientMessage(playerid,COLOR_RED," אתה לא יכול לכתוב בקלאן צ'אט כשאתה במיוט ");return 0;}
		format(file,256,clansfiles,ClanName);
		if(dini_Int(file,"ChatLock") == 1)
		{
		  format(file,256,userfiles,Name);
		  if(dini_Int(file,"ClanLevel") < 3)
		  {
		    SendClientMessage(playerid,COLOR_RED," אתה לא יכול לכתוב בקלאן צ'אט כשהצ'אט נעול ");
				return 0;
			}
		}
 		GetPlayerName(playerid,name,24);
		format(file,256,userfiles,name);
	  	if(dini_Isset(file,"Clan"))
		{
   		format(str3,sizeof(str3)," [ClanChat] [%s] %s: %s (ID: %d | Level: %d) ",dini_Get(file,"Clan"),name,text[1],playerid,dini_Int(file,"ClanLevel"));
      SendClanMessage();
      SendClanMessageToRadmin();
      return 0;
    }
  }
	return 1;
}
Thanks!



Re: Little coding questions - For general minor queries 5 - russo666 - 16.05.2010

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
yes, it's called, not surprisingly, 'OnPlayerText'

params:
playerid - player who typed text
text[] - text they entered
Lol i know that, i was asking for that:

Quote:
Originally Posted by dice7
Every public function can be called script wise, since they're only functions and nothing else
Examples:

pawn Code:
public OnPlayerConnect(playerid)
{
    OnPlayerCommandText(playerid, "/commands"); //will simulate that the player typed /commands
    OnPlayerText(playerid, "hello"); //will simulate that the player typed hello (im not sure if the text is displayed in chat)
    OnPlayerPickUpPickup(playerid, 3); //will tell the script that the player pickup a pickup with the id 3 (of course the player didn't)
    return 1;
Anyway, thanks to both!


Re: Little coding questions - For general minor queries 5 - winson0228 - 17.05.2010

All my dialogs have no effect... can somebody help me? It did this on a filterscript

http://pastebin.com/ueiJew1L


Re: Little coding questions - For general minor queries 5 - [HLF]Southclaw - 17.05.2010

Quote:
Originally Posted by russooooo
Quote:
Originally Posted by dice7
Every public function can be called script wise, since they're only functions and nothing else
Anyway, thanks to both!
Sorry about that :P misread :]


Re: Little coding questions - For general minor queries 5 - DevilRP - 19.05.2010

Code:
if GetPlayerScore(playerid <100) return SetPlayerScore(playerid, 750);
error-
Code:
error 001: expected token: "*then", but found "return"



Re: Little coding questions - For general minor queries 5 - russo666 - 20.05.2010

Quote:
Originally Posted by DevilRP
Code:
if GetPlayerScore(playerid <100) return SetPlayerScore(playerid, 750);
error-
Code:
error 001: expected token: "*then", but found "return"
if(GetPlayerScore(playerid < 100)) return SetPlayerScore(playerid, 750);

This should work.

Edit:

I have 2 questions.

1st I can't remember how exactly i can do that.

Read a line from a file and use SendClientMessage. I tried to use a string, etc, but i'm totaly bored and i can't get it to work.


2nd This one fucked up my head.

I don't know what is happening to me, but day by day i'm getin worst and i can't code anything.

I tried to save the positions of every single player in every single way that i remember and this shit didn't work.

I mean, when a player goes to an Event (eg: /dm) and then the event finishes he is automaticly teleported to his previous pos.


Edit: 1st solved. 2nd still in the same problem.



Re: Little coding questions - For general minor queries 5 - sansko - 20.05.2010

Hey all,

I want to have an aircraftcarrier in front of santa maria beach
the onley thing that i need is the carrier with doors etc.
And if it could an move object cmd for the 2 plane lifts (entrance door isnt neccery)

Thanks in advance

Sansko



Re: Little coding questions - For general minor queries 5 - Calgon - 20.05.2010

Quote:
Originally Posted by sansko
Hey all,

I want to have an aircraftcarrier in front of santa maria beach
the onley thing that i need is the carrier with doors etc.
And if it could an move object cmd for the 2 plane lifts (entrance door isnt neccery)

Thanks in advance

Sansko
This isn't for requests, this is for questions, there's a thread for what you're looking for.


Re: Little coding questions - For general minor queries 5 - [XST]O_x - 22.06.2010

Quote:
Originally Posted by [ĦŁ₣
ЉǾǖŦĦЗŁΛẄ ]
",nameoflol,cmdtext[4]); I think that is only inserting the fifth character, rather than all the text that's after the fifth character.

256 is too big, use 128 then minus whatever text you put in with the message: "** Car Chat ** %s: %s" I count 42 characters, so should be:
new str[(128-42)];

I never use this method of parameter commands, I would advise using DCMD and sscanf, that is the easiest. :P
Thanks,but actually I tested it after I made it while I was in a vehicle,and it inserted everything I wrote,but I wanted to know if it will send the message to ALL the players that are in the vehicle.

And,yeah,I know 256 is too big,I just like being sure that it will send the whole message,but I'll fix it,thanks.

But,besides that part,will the rest work?



Re: Little coding questions - For general minor queries 5 - mamorunl - 22.06.2010

Quote:
Originally Posted by O_x
Quote:
Originally Posted by mamoru
No, it will give you errors. If not: The compiler is stupid. Even I can see that that if-else in the beginning doesn't even work
Actually it doesn't give me any errors.

Well at least I've tried.. D:
Oh wait, it DOES work. I read the if-else wrong. It was because of the second if-statement that confused me.

While reading through it all: It does work, it will also send to the others in the car but, as mentioned, it can be more efficient on your memory and/or server load.


Re: Little coding questions - For general minor queries 5 - [XST]O_x - 22.06.2010

Quote:
Originally Posted by mamoru
Quote:
Originally Posted by O_x
Quote:
Originally Posted by mamoru
No, it will give you errors. If not: The compiler is stupid. Even I can see that that if-else in the beginning doesn't even work
Actually it doesn't give me any errors.

Well at least I've tried.. D:
Oh wait, it DOES work. I read the if-else wrong. It was because of the second if-statement that confused me.

While reading through it all: It does work, it will also send to the others in the car but, as mentioned, it can be more efficient on your memory and/or server load.
Oh,thanks for the validation mamoru

I'll try improving it a little bit though :P


Re: Little coding questions - For general minor queries 5 - zeli - 24.06.2010

Hello!

if i type a command which makes something with a player, how can i make that, to type the part of the name of the player.
so, eg.: a player who called "bunny", and i type /kill bun, it kills the player called bunny.