How to use a command on another player?
#1

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.
Reply
#2

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
Reply
#3

Код:
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
Reply
#4

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
Reply
#5

Change the timer to

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

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?
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)