AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Eventscript Code to Sourcemod Code (https://forums.alliedmods.net/showthread.php?t=323804)

BlackPanda 04-29-2020 07:04

Eventscript Code to Sourcemod Code
 
Hello everybody,

can someone maybe help me to write the script, which comes from eventscript, as SourceMod code?


Code:

event hegrenade_detonate
{
  es_playsound event_var(userid) bp_plugin/event/he.wav 1.0
}

event flashbang_detonate
{
  es_playsound event_var(userid) bp_plugin/event/flash.wav 1.0
}

event smokegrenade_detonate
{
  es_playsound event_var(userid) bp_plugin/event/smoke.wav 1.0
}



event player_team

if (event_var(team) = 2) do
        {
                es_msg Playername goes to T
                es_playsound event_var(userid) bp_plugin/event/tjt.mp3 1.0
        }

if (event_var(team) = 3) do
        {
                es_msg Playername goes to CT
                es_playsound event_var(userid) bp_plugin/event/tjct.mp3 1.0
        } 
}

Thx
BlackPanda

BlackPanda 04-30-2020 04:35

Re: Eventscript Code to Sourcemod Code
 
hello everybody,
is able to write plugins from eventscript in sourcemod plugins to?
I would be very grateful and willing to pay for it.

Gruß
BlackPanda

MAGNAT2645 04-30-2020 16:29

Re: Eventscript Code to Sourcemod Code
 
Something like this:
Code:

// these are just macros to simplify working with the code
#define GRENADE_DETONATE_SOUND                        "bp_plugin/event/he.wav"
#define FLASHBANG_DETONATE_SOUND                "bp_plugin/event/flash.wav"
#define SMOKE_GRENADE_DETONATE_SOUND        "bp_plugin/event/smoke.wav"
#define JOIN_T_SOUND                                        "bp_plugin/event/tjt.wav"
#define JOIN_CT_SOUND                                        "bp_plugin/event/tjct.wav"

// initialize event hooks and other stuff on plugin load (this calls only once)
public void OnPluginStart() {
        HookEvent( "hegrenade_detonate", OnGrenadeDetonate );
        HookEvent( "flashbang_detonate", OnFlashbangDetonate );
        HookEvent( "smokegrenade_detonate", OnSmokeGrenadeDetonate );
        HookEvent( "player_team", OnPlayerTeam );
}

// prepare (make our sounds public to any client) and precache our sounds (this call every map)
public void OnMapStart() {
        PrecacheSound( GRENADE_DETONATE_SOUND );
        AddFileToDownloadsTable( "sound/" ... GRENADE_DETONATE_SOUND );

        PrecacheSound( FLASHBANG_DETONATE_SOUND );
        AddFileToDownloadsTable( "sound/" ... FLASHBANG_DETONATE_SOUND );

        PrecacheSound( SMOKE_GRENADE_DETONATE_SOUND );
        AddFileToDownloadsTable( "sound/" ... SMOKE_GRENADE_DETONATE_SOUND );

        PrecacheSound( JOIN_T_SOUND );
        AddFileToDownloadsTable( "sound/" ... JOIN_T_SOUND );

        PrecacheSound( JOIN_CT_SOUND );
        AddFileToDownloadsTable( "sound/" ... JOIN_CT_SOUND );
}

// SNDVOL_NORMAL = 1.0 (you dont need actually to put this into function because it's a default value for EmitSoundToClient)
public void OnGrenadeDetonate(Event event, const char[] name, bool dontBroadcast) {
        int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
        if ( iClient )
                EmitSoundToClient( iClient, GRENADE_DETONATE_SOUND, .volume = SNDVOL_NORMAL );
}
public void OnFlashbangDetonate(Event event, const char[] name, bool dontBroadcast) {
        int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
        if ( iClient )
                EmitSoundToClient( iClient, FLASHBANG_DETONATE_SOUND, .volume = SNDVOL_NORMAL );
}
public void OnSmokeGrenadeDetonate(Event event, const char[] name, bool dontBroadcast) {
        int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
        if ( iClient )
                EmitSoundToClient( iClient, SMOKE_GRENADE_DETONATE_SOUND, .volume = SNDVOL_NORMAL );
}

public void OnPlayerTeam(Event event, const char[] name, bool dontBroadcast) {
        int iClient = GetClientOfUserId( event.GetInt( "userid" ) );
        if ( iClient == 0 )
                return; // break our code if client is not a player or is not in game

        switch ( event.GetInt( "team" ) ) {
                case 2: {
                        PrintToChatAll( "%N goes to T", iClient );
                        EmitSoundToClient( iClient, JOIN_T_SOUND, .volume = SNDVOL_NORMAL );
                }
                case 3: {
                        PrintToChatAll( "%N goes to CT", iClient );
                        EmitSoundToClient( iClient, JOIN_CT_SOUND, .volume = SNDVOL_NORMAL );
                }
        }
}


BlackPanda 05-01-2020 02:32

Re: Eventscript Code to Sourcemod Code
 
hi MAGNAT2645,
thanks for already bothering you that's really very nice of you! The way I see it, it seems to be exactly that :-) I tried compiling. However, there are a few errors.

Code:

Your plugin failed to compile! Read the errors below:
SourcePawn Compiler 1.10.0.6453
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC

/groups/sourcemod/upload_tmp/textg6uYiI.sp(19) : error 017: undefined symbol "AddFileToDownloadsTable"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(22) : error 017: undefined symbol "AddFileToDownloadsTable"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(25) : error 017: undefined symbol "AddFileToDownloadsTable"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(28) : error 017: undefined symbol "AddFileToDownloadsTable"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(31) : error 017: undefined symbol "AddFileToDownloadsTable"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(38) : error 017: undefined symbol "EmitSoundToClient"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(38) : warning 217: loose indentation
/groups/sourcemod/upload_tmp/textg6uYiI.sp(38) : error 017: undefined symbol "SNDVOL_NORMAL"
/groups/sourcemod/upload_tmp/textg6uYiI.sp(38) : error 029: invalid expression, assumed zero
/groups/sourcemod/upload_tmp/textg6uYiI.sp(38) : fatal error 190: too many error messages on one line

Compilation aborted.
9 Errors.


I'm already grateful to you
BlackPanda

MAGNAT2645 05-01-2020 05:17

Re: Eventscript Code to Sourcemod Code
 
Add #include sourcemod line to the top of your code.

Bacardi 05-01-2020 06:08

Re: Eventscript Code to Sourcemod Code
 
#include <sdktools>

BlackPanda 05-01-2020 06:45

Re: Eventscript Code to Sourcemod Code
 
Hi,
thank you very much!!! it is WORKING!!! :-)


now it would be nice if the player name and the t or ct are also written in the respective color. So either blue for ct or red for t. Doable for you?

Quote:

PrintToChatAll( "%N goes to T", iClient );
LG
BlackPanda

Bacardi 05-01-2020 07:21

Re: Eventscript Code to Sourcemod Code
 
I have never see this way to add strings :o
PHP Code:

#define GRENADE_DETONATE_SOUND            "bp_plugin/event/he.wav"
    
AddFileToDownloadsTable"sound/" ... GRENADE_DETONATE_SOUND ); 


MAGNAT2645 05-01-2020 10:35

Re: Eventscript Code to Sourcemod Code
 
Quote:

Originally Posted by Bacardi (Post 2697329)
I have never see this way to add strings :o
PHP Code:

#define GRENADE_DETONATE_SOUND            "bp_plugin/event/he.wav"
    
AddFileToDownloadsTable"sound/" ... GRENADE_DETONATE_SOUND ); 


It's just a preprocessor function like StrCat. Compiler joins multiple strings (between every three dots/ellipsis) into one.
I learned about this (and other useful things) from these Russian mini-lessons.

Bacardi 05-01-2020 10:42

Re: Eventscript Code to Sourcemod Code
 
hmmm... bummer. Need use translation


All times are GMT -4. The time now is 02:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.