[*S*] Left click for spawn, works all the time

Started by Sebastian, Mar 28, 2015, 09:34 PM

Previous topic - Next topic

.

Quote from: aXXo on Mar 30, 2015, 11:29 PMA much needed solution is to add several bool attributes to the current classes similar to object.TrackingBumps

Example:
player.TrackingKeys = true would enable monitoring OnPlayerKeyDown for that player. Any other player pressing a key would have no impact on the server performance. I mentioned the same in my post here, but I hope this is feasible in an update to the official Squirrel plugin.

That's the exact same thing I've been trying to feature on that module. The ability to avoid unnecessary event calls. I've almost done that. Now I just need to deal with a few flaws in my design and I'll start completing the module.
.

.

#31
A small (untested) C++ version of this can be found bellow:
#include <stdio.h>
#include <string.h>
#include <vcmp.h>

#if defined(_MSC_VER)
    #define SQMOD_API_EXPORT    extern "C" __declspec(dllexport)
#elif defined(__GNUC__)
    #define SQMOD_API_EXPORT    extern "C"
#endif

PluginFuncs * gFuncs;

int SPAWN_KEY_ID = -1;

void OnKeyBindDown(int nPlayerId, int nBindId)
{
    if (nBindId == SPAWN_KEY_ID && !gFuncs->IsPlayerSpawned(nPlayerId)) {
        gFuncs->ForcePlayerSpawn(nPlayerId);
    }
}

int OnInitServer()
{
    SPAWN_KEY_ID = gFuncs->RegisterKeyBind(gFuncs->GetKeyBindUnusedSlot(), 1, 0x01, 0, 0);

    if (SPAWN_KEY_ID < 0) {
        printf( "Left Click Spawn for VC:MP failed to register a key-bind" );

        return 0;
    }

    printf( "Left Click Spawn for VC:MP successfully loaded" );

    return 1;
}

SQMOD_API_EXPORT unsigned int VcmpPluginInit( PluginFuncs * functions, \
                                                PluginCallbacks * callbacks, \
                                                PluginInfo * info )
{
    info->uPluginVer = 0x1000; // 1.0.00
    strcpy( info->szName, "Left Click Spawn for VC:MP" );

    gFuncs = functions;

    callbacks->OnInitServer = OnInitServer;
    callbacks->OnKeyBindDown = OnKeyBindDown;

    return 1;
}

Code::Blocks project can be found here. If this works than let me know so that I can compile that on all platforms.
.

EK.IceFlake

#32
Knowing that isspawned is actually a function, I actually feel like using variables for checking if the player is spawned.

.

Quote from: NE.CrystalBlue on Mar 31, 2015, 07:13 AMKnowing that isspawned is actually a function, I actually feel like using variables for checking if the player is spawned.

Perhaps you quoted the wrong post because I don't know what you mean.
.

EK.IceFlake

Quote from: S.L.C on Mar 31, 2015, 07:22 AM
Quote from: NE.CrystalBlue on Mar 31, 2015, 07:13 AMKnowing that isspawned is actually a function, I actually feel like using variables for checking if the player is spawned.

Perhaps you quoted the wrong post because I don't know what you mean.
Sorry I forgot to remove the quote. Thats how I reply (quote and remove quote, its faster). I edited my post now.

Sebastian

#35
Quote from: S.L.CIf this works than let me know so that I can compile that on all platforms.

Nope, it doesn't work. I see the ""Left Click Spawn for VC:MP successfully loaded"" message in console, but when I press LMB, there is nothing happening.



Btw, didn't you say that calling a function is slower than comparing integers ?

Quote from: S.L.Cvoid OnKeyBindDown(int nPlayerId, int nBindId)
{
    if (gFuncs->IsPlayerSpawned(nPlayerId) && nBindId == SPAWN_KEY_ID) {
        gFuncs->ForcePlayerSpawn(nPlayerId);
    }
}

.

#36
I have some issues with my monitor right now but I'll verify that plugin as soon as I can get back on my PC.

EDIT: I think I forgot to negate the result from IsPlayerSpawned(). I'll be back with a fix.

EDIT: Updated the post with the code. Try that and let me know.
.

Sebastian

Quote from: S.L.C on Mar 31, 2015, 03:55 PMEDIT: Updated the post with the code. Try that and let me know.

It still doesn't work. Nothing happens, just like before.
Testing it by yourself will make you realize faster what's the problem. ;)

.

Quote from: sseebbyy on Apr 01, 2015, 11:57 AMTesting it by yourself will make you realize faster what's the problem. ;)

I'm having some issues with my monitor and I'm not at my PC right now. I will actually test this when I get a new one or at least get a provisory monitor.
.

Sebastian

Since this was fixed by developers, I will just lock this.