Example #1
0
def OnPlayerCommandText(playerid, cmd):
    samp.printf("[%d]: %s" % (playerid, cmd))
    samp.SendClientMessage(playerid, COL_WHITE, cmd)

    if cmd == "/vehicle":
        samp.CreateVehicle(535, 5.0, 5.0, 5.0, 5.0, 0, 0, -1)
    elif cmd == "/anim":
        samp.ApplyAnimation(playerid, "PED", "KO_skid_front", 3.0, 0, 1, 1, 1,
                            0)
    elif cmd == "/banme":
        samp.Ban(playerid)
    elif cmd == "/banreason":
        samp.BanEx(playerid, "The reason")
    elif cmd == "/vehcol":
        samp.ChangeVehicleColor(1, 1, 1)
    elif cmd == "/vehjob":
        samp.ChangeVehiclePaintjob(1, 0)
    elif cmd == "/stopanim":
        samp.ClearAnimations(playerid)
    elif cmd == "/mypos":
        x = samp.GetPlayerPos(playerid)
        samp.SendClientMessage(playerid, COL_WHITE,
                               "Your position: %s" % str(x))
    elif cmd == "/curanim":
        x = samp.GetAnimationName(samp.GetPlayerAnimationIndex(playerid))
        samp.SendClientMessage(playerid, COL_WHITE,
                               "Current animation: %s" % str(x))
    return 1
Example #2
0
def OnVehicleStreamOut(vehicleid, forplayerid):
    samp.SendClientMessage(forplayerid, COL_WHITE, "StreamOut: %d" % vehicleid)
Example #3
0
def OnVehicleSpawn(vehicleid):
    samp.SendClientMessage(0, COL_WHITE, "Spawn: %d" % vehicleid)
Example #4
0
def OnVehicleRespray(playerid, vehicleid, color1, color2):
    samp.SendClientMessage(playerid, COL_WHITE,
                           "Respray: %d/%d/%d" % (vehicleid, color1, color2))
Example #5
0
def OnVehiclePaintjob(playerid, vehicleid, paintjobid):
    samp.SendClientMessage(playerid, COL_WHITE,
                           "Paintjob: %d/%d" % (vehicleid, paintjobid))
Example #6
0
def OnVehicleMod(playerid, vehicleid, componentid):
    samp.SendClientMessage(playerid, COL_WHITE,
                           "Mod: %d/%d" % (vehicleid, componentid))
Example #7
0
def OnEnterExitModShop(playerid, enterexit, interiorid):
    samp.SendClientMessage(playerid, COL_WHITE,
                           "EnterExit: %d/%d" % (enterexit, interiorid))
Example #8
0
def OnVehicleDeath(vehicleid, killerid):
    samp.SendClientMessage(0, COL_WHITE, "Vehicle died!")
Example #9
0
def OnVehicleDamageStatusUpdate(vehicleid, playerid):
    samp.SendClientMessage(0, COL_RED, "Damage updated")
Example #10
0
def OnPlayerExitVehicle(playerid, vehicleid):
    samp.SendClientMessage(playerid, COL_WHITE, "Exit")
    samp.CreateExplosion(5.0, 5.0, 3.0, 2, 10.0)
Example #11
0
def OnPlayerEnterVehicle(playerid, vehicleid, ispassenger):
    samp.SendClientMessage(playerid, COL_WHITE, "Enter")
Example #12
0
def handle_command(playerid, cmdtext):
    """This function handles a command sent by a player and has to be called in OnPlayerCommandText
	
	>>> @cmd
	... def test(pid, prm1, prm2):
	... 	print('called')
	>>> @cmd("t2", convert=dict(prm1=int))
	... def t2(pid, prm1):
	... 	print(type(prm1))
	>>> handle_command(0, "/test prm1 prm2")
	called
	True
	>>> handle_command(0, "/t2 5")
	<type 'int'>
	True
	>>> handle_command(1, "/nocmd")
	False
	"""
    # split cmdtext
    prt = cmdtext.split()
    cmdname = prt[0][1:]
    # find the cmd instance
    if not cmdname in _cmd_list:
        return False  # command does not exist
    cmd = _cmd_list[cmdname]
    if cmd.function == None:
        raise AttributeError(
            "command has no callable object assigned: [%d]: %s" %
            (playerid, cmdtext))

    # check if this user is authorized to use this command
    for req in cmd.requires:
        try:
            if not req(
                    playerid
            ):  # it's the user's fault if he doesn't pass callable objects
                samp.SendClientMessage(playerid, cmd.unauthd_color,
                                       cmd.unauthorized_text)
                return True
        except TypeError:
            pass

    if cmd.param_count != -1 and len(
            prt) - 1 > cmd.param_count:  # too many parameters passed -> cut out
        prt = prt[:-(len(prt) - cmd.param_count - 1)]

    # convert parameters
    for p in xrange(min(len(prt), len(cmd.args))):
        if cmd.args[p] in cmd.convert:  # check if this parameter exists
            try:  # call the converter
                prt[p] = cmd.convert[cmd.args[p]](prt[p])
            except:
                pass  # we don't know which exceptions are thrown if conversion fails, so always drop it

    # call the function object
    if not cmd.raw:
        cmd.function(playerid, *prt[1:])
    else:
        cmd.function(playerid, cmdtext)

    return True