SA-MP Forums Archive
Teleporting Weapons - 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: Teleporting Weapons (/showthread.php?tid=652141)



Teleporting Weapons - PizzaMag - 03.04.2018

I wish to make a pretty basic command that when you shoot a specific weapon, it does a special action. I tried first with shotgun that when you shot in a location, it TPs you there:
PHP код:
CMD:magicweaps(playerid,params[])
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            
plInfo[playerid][tpw] = false;
            
SendClientMessage(playerid,COLOR_GREEN,"You turned on magic weapons!");
        }
        else
        {
            
plInfo[playerid][tpw] = true;
            
SendClientMessage(playerid,COLOR_RED,"You turned off magic weapons!");
        }
    }
    return 
1;
}
public 
OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            if(
hittype == BULLET_HIT_TYPE_NONE)
            {
                if(
weaponid == 25SetPlayerPos(playerid,fX,fY,fZ);
            }
        }
    }
    return 
1;

And then nothing happens, just casual shooting.


Re: Teleporting Weapons - ForCop - 04.04.2018

Quote:
Originally Posted by PizzaMag
Посмотреть сообщение
I wish to make a pretty basic command that when you shoot a specific weapon, it does a special action. I tried first with shotgun that when you shot in a location, it TPs you there:
PHP код:
CMD:magicweaps(playerid,params[])
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            
plInfo[playerid][tpw] = false;
            
SendClientMessage(playerid,COLOR_GREEN,"You turned on magic weapons!");
        }
        else
        {
            
plInfo[playerid][tpw] = true;
            
SendClientMessage(playerid,COLOR_RED,"You turned off magic weapons!");
        }
    }
    return 
1;
}
public 
OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            if(
hittype == BULLET_HIT_TYPE_NONE)
            {
                if(
weaponid == 25SetPlayerPos(playerid,fX,fY,fZ);
            }
        }
    }
    return 
1;

And then nothing happens, just casual shooting.
Код:
CMD:magicweaps(playerid,params[])
{
    new path[256];
	format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(plInfo[playerid][tpw] == true)
        {
            plInfo[playerid][tpw] = false;
            SendClientMessage(playerid,COLOR_GREEN,"You turned on magic weapons!");
		}
		else
		{
		    plInfo[playerid][tpw] = true;
		    SendClientMessage(playerid,COLOR_RED,"You turned off magic weapons!");
		}
    }
    return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    new path[256];
	format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(plInfo[playerid][tpw] == true)
        {
            if(hittype == BULLET_HIT_TYPE_NONE)
            {
                if(weaponid == 25)
                {  
                new Float:fOriginX, Float:fOriginY, Float:fOriginZ,Float:fHitPosX, Float:fHitPosY, Float:fHitPosZ;
                GetPlayerLastShotVectors(playerid, fOriginX, fOriginY, fOriginZ, fHitPosX, fHitPosY, fHitPosZ);
                SetPlayerPos(playerid, fHitPosX, fHitPosY, fHitPosZ + 3);
               }
	   }
         }
	}
	return 1;
}



Re: Teleporting Weapons - PizzaMag - 04.04.2018

Thank you so much. It worked perfectly.
But how can I check if the player hits the ground or not? By so, the player wouldn't be TPed to the world's middle if he shot at the sky.

I tried:
PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            if(
hittype == BULLET_HIT_TYPE_NONE)
            {
                if(
weaponid == 25)
                {
                    new 
Float:fOriginXFloat:fOriginYFloat:fOriginZ,Float:fHitPosXFloat:fHitPosYFloat:fHitPosZ;
                    
GetPlayerLastShotVectors(playeridfOriginXfOriginYfOriginZfHitPosXfHitPosYfHitPosZ);
                    
SetPlayerPos(playeridfHitPosXfHitPosYfHitPosZ 3);
                }
            }
            else return 
0;
        }
    }
    return 
1;

But I am aware that it won't work because:
Quote:

Return Values:
0 - Prevent the bullet from causing damage.
1 - Allow the bullet to cause damage.
It is always called first in filterscripts so returning 0 there also blocks other scripts from seeing it.




Re: Teleporting Weapons - ForCop - 04.04.2018

Quote:
Originally Posted by PizzaMag
Посмотреть сообщение
Thank you so much. It worked perfectly.
But how can I check if the player hits the ground or not? By so, the player wouldn't be TPed to the world's middle if he shot at the sky.

I tried:
PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    new 
path[256];
    
format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    if(
IsPlayerAdmin(playerid) || dini_Int(path,"Admin Level") >= 3)
    {
        if(
plInfo[playerid][tpw] == true)
        {
            if(
hittype == BULLET_HIT_TYPE_NONE)
            {
                if(
weaponid == 25)
                {
                    new 
Float:fOriginXFloat:fOriginYFloat:fOriginZ,Float:fHitPosXFloat:fHitPosYFloat:fHitPosZ;
                    
GetPlayerLastShotVectors(playeridfOriginXfOriginYfOriginZfHitPosXfHitPosYfHitPosZ);
                    
SetPlayerPos(playeridfHitPosXfHitPosYfHitPosZ 3);
                }
            }
            else return 
0;
        }
    }
    return 
1;

But I am aware that it won't work because:
Код:
new AdminPayer[MAX_PLAYERS];


public OnPlayerConnect(playerid)
{
    new path[256];
    format(path,sizeof(path),"users/%s.ini",PlayerName(playerid));
    AdminPayer[playerid] = dini_Int(path,"Admin Level");
    return true;
}

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(IsPlayerAdmin(playerid) || AdminPayer[playerid] >= 3)
    {
        if(plInfo[playerid][tpw] == true && weaponid == 25) 
	{
        new Float:fOriginX, Float:fOriginY, Float:fOriginZ,Float:fHitPosX, Float:fHitPosY, Float:fHitPosZ;
        GetPlayerLastShotVectors(playerid, fOriginX, fOriginY, fOriginZ, fHitPosX, fHitPosY, fHitPosZ);
        SetPlayerPos(playerid, fHitPosX, fHitPosY, fHitPosZ + 3);
        }
    }
    return true;
}
you can use it when a player, car, object, etc... https://sampwiki.blast.hk/wiki/BulletHitTypes