Admin's SetWorld command by using zcmd and sscanf
#1

hey guys as im noob in scripting, ihave another question ^^
i tried to make /setworld playerid worldid command but it didn't worked... is there any tut to teach me how to make it?
Reply
#2

Simple and easy..

https://sampforum.blast.hk/showthread.php?tid=361798


pawn Код:
#include <a_samp>
#include <sscanf>
#include <zcmd>

CMD:vw(playerid,params[])
{
    new virtualworld;
    if(sscanf(params,"i",virtualworld)) return SendClientMessage(playerid,-1,"USAGE: /vw [id]");
    else
   {
       new str[256];
       SetPlayerVirtualWorld(playerid,virtualworld);
       format(str,sizeof(str),"You are now in virtual world %d",virtualworld);
       SendClientMessage(playerid,-1,str);
   }
    return 1;
}
Reply
#3

@kbalor why did you use 256 when 64 MAX. is needed. If you want only the admin to access to that command just add
pawn Код:
[if(IsPlayerAdmin(playerid)) { //code }
above the string variable.
Reply
#4

this one let's the player to change his own virtual world... im trying to create a command which let's admin to change a player's virtual world
Reply
#5

pawn Код:
#include <a_samp>
#include <sscanf>
#include <zcmd>

CMD:vw(playerid,params[])
{
    new virtualworld;
    if(sscanf(params,"i",virtualworld)) return SendClientMessage(playerid,-1,"USAGE: /vw [id]");
    {
        if(IsPlayerAdmin(playerid)) {
            new str[64];
            SetPlayerVirtualWorld(playerid,virtualworld);
            format(str,sizeof(str),"You are now in virtual world %d",virtualworld);
            SendClientMessage(playerid,-1,str);
        } else {
            SendClientMessage(playerid,-1,"Only RCON users can access to this command");
        }
    }
    return 1;
}
Here's an example.
Reply
#6

The above example will output errors.

pawn Код:
#include <a_samp>
#include <sscanf>
#include <zcmd>

COMMAND:setvw(playerid, params[])
{
    #pragma unused params
    if (IsPlayerAdmin(playerid))
    {
        new
            targetid,
            vw;
        if (sscanf(params, "dd", targetid, vw))
        {
            SendClientMessage(playerid, -1, "Syntax: /setvw [playerid] [virtual world]");
            return 1;
        }
        if (vw < 0)
        {
            SendClientMessage(playerid, -1, "Invalid virtual world specified.");
            return 1;
        }
        if (!IsPlayerConnected(targetid))
        {
            SendClientMessage(playerid, -1, "Invalid player ID.");
            return 1;
        }
        SetPlayerVirtualWorld(targetid, vw);
        SendClientMessage(targetid, -1, "Your virtual world has been changed by an Admin.");
    }
    return 1;
}
Note that -1 in SendClientMessage is white color, so change that if you want your colors.
Reply
#7

I forgot to add a bracket and the code is not wrong. Also mine was a basic example.
Reply
#8

Quote:
Originally Posted by Universal
Посмотреть сообщение
The above example will output errors.

pawn Код:
#include <a_samp>
#include <sscanf>
#include <zcmd>

COMMAND:setvw(playerid, params[])
{
    #pragma unused params
    if (IsPlayerAdmin(playerid))
    {
        new
            targetid,
            vw;
        if (sscanf(params, "dd", targetid, vw))
        {
            SendClientMessage(playerid, -1, "Syntax: /setvw [playerid] [virtual world]");
            return 1;
        }
        if (vw < 0)
        {
            SendClientMessage(playerid, -1, "Invalid virtual world specified.");
            return 1;
        }
        if (!IsPlayerConnected(targetid))
        {
            SendClientMessage(playerid, -1, "Invalid player ID.");
            return 1;
        }
        SetPlayerVirtualWorld(targetid, vw);
        SendClientMessage(targetid, -1, "Your virtual world has been changed by an Admin.");
    }
    return 1;
}
Note that -1 in SendClientMessage is white color, so change that if you want your colors.
thx mate repped
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)