SA-MP Forums Archive
How to use a command on another player? - 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: How to use a command on another player? (/showthread.php?tid=364828)



How to use a command on another player? - gnoomen2 - 31.07.2012

Ok, so I guess this is a very very nooby question, but I am new to scripting.
How do i make this script here a command to use on someone? I think i got a start, but it ain't working.


pawn Код:
COMMAND:torture(playerid, params[])
{
    new giveplayerid;
    if(IsPlayerAdmin(playerid))
    {
    if(sscanf(params, "is[24]", giveplayerid)) return SendClientMessage(playerid,COLOR_YELLOW,"Usage: /torture [PlayerID]");
    else
    {
        SetPlayerPos(playerid, 300.0837,-129.4271,1004.0625);
        SetPlayerInterior(playerid, 7);
        SetPlayerVirtualWorld(playerid, 0);
        TogglePlayerControllable(playerid, 0);
        SetPlayerFacingAngle( playerid, 95.22 );
        wep1 = CreateDynamicObject(339, 270.5772,-129.6093,1005.6752, 0.0, 0.0, 0.0, -1, -1, -1, 100.0);
        MoveDynamicObject(wep1, 300.5394,-129.4422,1004.0625, 1);
        SetTimer("torture", 1500, 1);
      }
    }
    return 1;
}
And if you can please explain everything you add or edit.


Re: How to use a command on another player? - Ranama - 01.08.2012

This is how you'll do it,

Код:
COMMAND:torture(playerid, params[])
{
    new giveplayerid;
    if(IsPlayerAdmin(playerid))
    {
    new targetid;//You'll have to make a new variable witch will hold the id of the player you want to torture
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,COLOR_YELLOW,"Usage: /torture [PlayerID]");
    else
    {
        SetPlayerPos(targetid, 300.0837,-129.4271,1004.0625);
        SetPlayerInterior(targetid, 7);//Change all of these to targetid becuse you want the targeted id to get tortured
        SetPlayerVirtualWorld(targetid, 0);
        TogglePlayerControllable(targetid, 0);
        SetPlayerFacingAngle(targetid, 95.22 );
        wep1 = CreateDynamicObject(339, 270.5772,-129.6093,1005.6752, 0.0, 0.0, 0.0, -1, -1, -1, 100.0);
        MoveDynamicObject(wep1, 300.5394,-129.4422,1004.0625, 1);
        SetTimer("torture", 1500, 1);//and SetTimer will start a function after the desired time, i fon't think you want thisbecuse i think you want to torure the player in 15 secounds and then it will stop? if that's true I can help you more, but try the first part first :)
      }
    }
    return 1;
}
Hope i helped


Re: How to use a command on another player? - Devilxz97 - 01.08.2012

Код:
Specifier(s)			Name				Example values
	i, d			Integer				1, 42, -10
	c			Character			a, o, *
	l			Logical				true, false
	b			Binary				01001, 0b1100
	h, x			Hex				1A, 0x23
	o			Octal				045 12
	n			Number				42, 0b010, 0xAC, 045
	f			Float				0.7, -99.5
	g			IEEE Float			0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
	u			User name/id (bots and players)	******, 0
	q			Bot name/id			ShopBot, 27
	r			Player name/id			******, 42



Re: How to use a command on another player? - gnoomen2 - 01.08.2012

Quote:
Originally Posted by Ranama
Посмотреть сообщение
This is how you'll do it,

Код:
COMMAND:torture(playerid, params[])
{
    new giveplayerid;
    if(IsPlayerAdmin(playerid))
    {
    new targetid;//You'll have to make a new variable witch will hold the id of the player you want to torture
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,COLOR_YELLOW,"Usage: /torture [PlayerID]");
    else
    {
        SetPlayerPos(targetid, 300.0837,-129.4271,1004.0625);
        SetPlayerInterior(targetid, 7);//Change all of these to targetid becuse you want the targeted id to get tortured
        SetPlayerVirtualWorld(targetid, 0);
        TogglePlayerControllable(targetid, 0);
        SetPlayerFacingAngle(targetid, 95.22 );
        wep1 = CreateDynamicObject(339, 270.5772,-129.6093,1005.6752, 0.0, 0.0, 0.0, -1, -1, -1, 100.0);
        MoveDynamicObject(wep1, 300.5394,-129.4422,1004.0625, 1);
        SetTimer("torture", 1500, 1);//and SetTimer will start a function after the desired time, i fon't think you want thisbecuse i think you want to torure the player in 15 secounds and then it will stop? if that's true I can help you more, but try the first part first :)
      }
    }
    return 1;
}
Hope i helped
Thank you! You fixed it!

I have the timer because i don't know how to make the player get killed when the object gets too him, I would be very glad if you can edit the code to do that. The time in the timer isnt even at the correct time xD


Re: How to use a command on another player? - Ranama - 01.08.2012

Change the timer to

Код:
SetTimerEx("SetPlayerHealth", 1500, false , "if", targetid, 0.0);
I think that will kill the player after the timer have finished


Re: How to use a command on another player? - gnoomen2 - 01.08.2012

Quote:
Originally Posted by Ranama
Посмотреть сообщение
Change the timer to

Код:
SetTimerEx("SetPlayerHealth", 1500, false , "if", targetid, 0.0);
I think that will kill the player after the timer have finished
That compiled without errors, havent tested it but i think it will work, and i can do the same with this?

[/PAWN]SetTimerEx("DestroyDynamicObject(wep1);", 1500, false , "if", targetid, 0.0);[PAWN]

That also compiled without errors. Do you know how i can make the player die and the object get destroyed "DestroyDynamicObject(wep1);" when the object reaches the players position?


Re: How to use a command on another player? - Ranama - 01.08.2012

well, what you could do is create the object in the local scope(not in any function to be able to destroy it in another function)
So you'll have to do this:

Код:
new wep1;//set this at the start of your gamemode before OnGameModeInit();
//and then you could do that timer, but not exactly like you whrite it, do it like this.
SetTimerEx("DestroyDynamicObject", 1500, false , "i", wep1);
That would work since first you name the function you want to call, then the time, then if you want it to loop, then the type of the data you want to put into the function, then what data you want to put in there, more info here:

https://sampwiki.blast.hk/wiki/SetTimerEx