SA-MP Forums Archive
Useful Functions - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: Useful Functions (/showthread.php?tid=38965)



Re: Useful Functions - SlashPT - 21.09.2010

using garsinos other person code :P

pawn Код:
//==============================================================================
new
    gp,
    string[65],
    name[MAX_PLAYER_NAME]
;
//==============================================================================
cmd(crash, playerid, params[])
{
    if(IsAdmin(playerid))
    {
        if(sscanf(params, "i", gp)) return SendClientMessage(playerid, 0xF60000AA, "Usage: /crash [PlayerID]");
        CrashPlayer(gp);
        GetPlayerName(gp, name, sizeof MAX_PLAYER_NAME);
        format(string, sizeof(string), "Player %s[%d] crashed sucefully", name, gp);
        SendClientMessage(playerid, 0xF60000AA, string);
    }
    else
        return SendClientMessage(playerid, 0xF60000AA, "You aren't Rcon...");
    return 1;
}
//==============================================================================
stock CrashPlayer(playerid)
    return ApplyAnimation(playerid, "GANG", "DRUGS_BUY", 10, 0, 0, 0, 0, 5*1000);
thx garsino


Re: Useful Functions - RyDeR` - 21.09.2010

Check the CrashPlayer params and the ApplyAnimation params please..


Re: Useful Functions - SlashPT - 21.09.2010

fixed i didnt saw it i thought garsino posted it correctly :P anyways thx for you two


Re: Useful Functions - [03]Garsino - 21.09.2010

You should use "u" in the sscanf part btw (its for both [part]names and player IDs)


Re: Useful Functions - [03]Garsino - 21.09.2010

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Check the CrashPlayer params and the ApplyAnimation params please..
Whoops, didn't notice (I took it out from my /crash command wich uses id as the variable for the other player). Thanks for pointing out :P


Re: Useful Functions - SlashPT - 21.09.2010

well in my gm i always use playerid and also if i use "u" i need to put a string variable... if i do /crash Bruno_Bandidez without a string...


Re: Useful Functions - [03]Garsino - 21.09.2010

no you dont


Re: Useful Functions - SlashPT - 21.09.2010

really thought about it and yea your right just if the string is higher than 30 ... :P


Re: Useful Functions - Luka P. - 22.09.2010

Okay, this is not a function, but I think it is useful. Well, I was experiencing a bug with textdraw, namely the first textdraw didn't wanted to show everytime I try doing something with TDs, so here is a hotfix if you experience the same problem. Put this before creating any textdraw inside OnGameModeInit callback.

Код:
TextDrawCreate(0.0, 0.0, "_");



Re: Useful Functions - CJ101 - 22.09.2010

Код:
stock FindPlayerIDForIP(ip[])
{
	new ip2[16];
 	for(new i = 0; i < MAX_PLAYERS; i++)
	{
 		if(IsPlayerConnected(i))
   		{
     		  GetPlayerIp(i,ip2,sizeof ip2);
	    	  if(strcmp(ip,ip2, true)==0)
		  {
		     return i;
		  }
		}
	}
	return -1;
}
i blame copy and paste for the bad indentation.


Re: Useful Functions - Luka P. - 22.09.2010

Nice function, but I suggest using a foreach include by ****** when you need to loop through all the players and compare some things like IP.


Re: Useful Functions - Prozack - 22.09.2010

Searched thread for SetPlayerCameraPos and it looks like this topic hasn't been covered yet. This function is really handy for setting up the view for OnPlayerRequestClass and can be used for spectating also.

Notes:
camera angle is relative to the map not the player facing angle - this is being addressed for next edit.
mode=true when used in OnPlayerRequestClass - set the appropriate interiorid if not "0"

Код:
stock AdjustCameraAngle(playerid,mode)
{
	new Float:c[3], Float:angle;
	new Float:degrad=0.01745329251994;
	new Float:p[]={2033.1309,1543.0475,10.8203,90.00}; // playerrequestclass data
	new Float:distance = 10.0;			   // camera distance to player
	new Float:offset = 0.00;                           // camera facing angle
	new Float:pitch = 10.00;			   // camera pitch
	if(mode){
		SetPlayerPos(playerid,p[0],p[1],p[2]);
		SetPlayerFacingAngle(playerid,p[3]);
		SetPlayerInterior(playerid,0);		   // see notes
	}
	else{
		GetPlayerPos(playerid,p[0],p[1],p[2]);
	}
	angle=offset-180.00*degrad;
	c[0]=p[0]+floatsin(angle)*distance;
	c[1]=p[1]+floatcos(angle)*distance;
	c[2]=p[2]+pitch;                            		
	SetPlayerCameraPos(playerid,c[0],c[1],c[2]);
	SetPlayerCameraLookAt(playerid,p[0],p[1],p[2]);
}



Re: Useful Functions - Luka P. - 22.09.2010

Nice, but my opinion is that it is still easier to set it in a regular way (at least for me).


Re: Useful Functions - Prozack - 22.09.2010

Hit and miss works too..

I will compliment you however on your ability to calculate angles without using math.
Some people aren't that bright.

Saw quite a few posts where people were having trouble getting this right. Some of these may never get it right..
But if it actually helps them get it.. it's worth the effort I suppose.


Re: Useful Functions - Prozack - 22.09.2010

This function will locate the position that is directly in front of a player at a given distance.
It works well with /bring or /goto commands and keeps people from spawning on other players heads.

Test s[0]!=9999.99 on return to ensure the player is not spectating. If so, don't go there.

It's not nice to /bring a person in front of your vehicle

Код:
new Float:s[4];
new Bool:IsSpectactor[MAX_PLAYERS];

stock PlayerVacinityLocation(playerid,Float:distance)
{
	new reset[]={9999.99,0.00,0.00,0.00};
	new Float:degrad=0.01745329251994;
	new Float:angle;
	new Float:p[4];
	s=reset;
	if(!IsSpectator[playerid]){
		
		GetPlayerPos(playerid,p[0],p[1],p[2]);
		GetPlayerFacingAngle(playerid,p[3]);							
		if(IsPlayerInAnyVehicle(playerid)){
			new vehicleid=GetPlayerVehicleID(playerid);
			GetVehicleZAngle(playerid,p[3]);
		}
		angle=p[3]*degrad;
		s[0]=p[0]-floatsin(angle)*distance;
		s[1]=p[1]+floatcos(angle)*distance;
		s[2]=p[2]+0.0001;
		s[3]=p[3]+180.0;
	}
}



Re: Useful Functions - Grim_ - 22.09.2010

Not bad, but ****** created this:
pawn Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{   // Created by ******

    new Float:a;

    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);

    if (GetPlayerVehicleID(playerid)) {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}



Re: Useful Functions - willsuckformoney - 23.09.2010

Is that to get the X & Y positions for a player?


Re: Useful Functions - Grim_ - 23.09.2010

The XY coordinates in front of the player, as the function name suggests.


Re: Useful Functions - Prozack - 23.09.2010

Thanks Grim_. There is clearly redundance in my statements. It's nice to see how accomplished people code similar tasks. Returning the values via the pointer to an argument is really good, but I'm not that familiar with the process. LoL -- passing global variables is sloppy work.

and thank you ******!!


Re: Useful Functions - Luka P. - 23.09.2010

WeaponSlotOf(w)
@w = weapon id

Well, this is my one-line function that will determinite which slot specific weapon will be stored in (simple - the slot of the weapon). It will return 0xFFFF (-1) if slot has not been found. http://pastebin.com/GZJz5bBU